M6809-Docs / m6809pm

MC6809-MC6809E 8-Bit Microprocessor Programming Manual [M6809PM/AD]
2 stars 0 forks source link

Error in DAA description in Appendix A #2

Open cmarrin opened 4 months ago

cmarrin commented 4 months ago

As stated in in section 1.10.1.1, The H (Half Carry) bit in the condition code register indicates that a carry was generated from bit 3 to bit 4 of a previous 8 bit addition. But in appendix A under the description of the DAA opcode it explains that an adjustment is needed in the lowest significant nibble (LSN) if the C (Carry) bit is set. It should say if the H (Half Carry) bit is set, since this indicates that a carry occurred in the LSN.

For instance, if you ADD 0x28 + 0x39 the result is 0x61. Since 0x8 + 0x9 is 0x11, there is a carry from bit 3 to bit 4 and the H bit is set during the ADD. So the DAA instruction sees that the H bit is set and adds 0x6 to the result, giving 0x67. Since the C bit is not set no adjustment is done to the Most Significant Nibble (MSN) the final adjustment is 0x67, which is what the result would be if the decimal numbers 28 and 39 were added.

cmarrin commented 4 months ago

I've gotten far enough in my emulator (https://github.com/cmarrin/6809/) to run the test09.asm file which contains tests for the DAA instruction. With the change described here these tests pass.