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 noticed in the Zilog manual that it is for the purposes of adjusting the accumulator for binary coded decimal arithmetic. It says the instruction is intended to be run right after an addition or subtraction instruction.
My questions are:
- what happens if it is run after another instruction?
- how does it know what instruction preceeded it?
- I realise there is the N flag – but this surely wouldnt definitively indicate that the previous instruction was an addition or subtraction instruction?
- Does it just modify the accumulator anyway, based on the conditions set out in the DAA table, regardless of the previous instruction?
Yes. The documentation is only telling you what DAA is intended to be used for. Perhaps you are referring to the table at this link:
I must say, I’ve never seen a dafter instruction spec. If you examine the table carefully, you will see that the effect of the instruction depends only on the
CandHflags and the value in the accumulator — it doesn’t depend on the previous instruction at all. Also, it doesn’t divulge what happens if, for example,C=0,H=1, and the lower digit in the accumulator is 4 or 5. So you will have to execute aNOPin such cases, or generate an error message, or something.