LDIR
The Z80 CPU instruction LDIR is a loop instruction that loads the contents of the HL register pair into the memory location specified by the DE register pair, incrementing both HL and DE after each load. This instruction repeats until the BC register pair is zero, at which point the instruction ends.
The number of T-states required to execute the LDIR instruction depends on the value in the BC register pair. If the value in the BC register pair is not zero, the LDIR instruction will take 16 T-states to execute on the first iteration of the loop, and then an additional 5 T-states for each subsequent iteration of the loop. If the value in the BC register pair is zero, the LDIR instruction will not execute and will take 0 T-states to complete.
For example, if the value in the BC register pair is 5, the LDIR instruction will take a total of (16 + 5 * 5) = 41 T-states to complete.
Here is an example of how you can use the LDIR instruction in your assembly code, with the number of T-states added as a comment next to each instruction:
Код:
LD B, 5 ; 7 T-states
LD C, 0 ; 7 T-states
LD A, B ; 4 T-states
LD HL, 0x1234; 10 T-states
LD DE, 0x5678; 10 T-states
LDIR ; 16 + 5 * 5 = 41 T-states
At the end of this code, you can add a comment with the total number of T-states like this:
Код:
; Total T-states: 85
I hope this helps. Please let me know if you have any other questions.