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
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:
Also, while DAA is intended to be run after an addition or subtraction, it can be run at any time.