Z80 DAA instruction

后端 未结 4 1129
无人共我
无人共我 2021-02-12 16:24

Apologies for this seemingly minor question, but I can\'t seem to find the answer anywhere - I\'m just coming up to implementing the DAA instruction in my Z80 emulator, and I no

4条回答
  •  情歌与酒
    2021-02-12 17:19

    I found this instruction rather confusing as well, but I found this description of its behavior from z80-heaven to be most helpful.

    When this instruction is executed, the A register is BCD corrected using the contents of the flags. The exact process is the following: if the least significant four bits of A contain a non-BCD digit (i. e. it is greater than 9) or the H flag is set, then $06 is added to the register. Then the four most significant bits are checked. If this more significant digit also happens to be greater than 9 or the C flag is set, then $60 is added.

    This provides a simple pattern for the instruction:

    • if the lower 4 bits form a number greater than 9 or H is set, add $06 to the accumulator
    • if the upper 4 bits form a number greater than 9 or C is set, add $60 to the accumulator

    Also, while DAA is intended to be run after an addition or subtraction, it can be run at any time.

提交回复
热议问题