LDDR¶
- LDDR
- Load and Decrement with Repeat
- Description
- Performs
ldd
untilBC
= 0, effectively copyingBC
bytes of data fromHL
toDE
, whereHL
andDE
point to the end of their respective blocks.ldd ret po jr -5
- Uses
- Copying lots of data
- Sprite routines
- Copying graphical data from some buffer to the actual screen
- Filling lots of space with one (or more) bytes
- Results
Register/Flag 16-bit (non-ADL) 24-bit (ADL) S
flagNot affected Z
flagNot affected H
flagReset P/V
flagSet if BC
≠ 0 after the operation; else resetN
flagReset C
flagNot affected - Allowed Instructions
Instruction Opcode CC (ADL/non-ADL) CC (.S) CC (.L) lddr $ED, $B8 2F + (1R + 1W + 1)* BC
3F + (1R + 1W + 1)* BC
3F + (1R + 1W + 1)* BC
- Notes
- Interrupts can be triggered while this instruction is in progress (unless they are disabled using
DI
, of course). - Since most of the time it’s more convenient to specify the beginning of a block of data than the end,
LDIR
is significantly more popular thanLDDR
. - Assuming you are copying hard-coded data and BC is NOT already set to the desired number of bytes, it is only faster to use hard-coded
LDD
s instead ofld bc,BytesToCopy \ lddr
if you are copying two bytes. Copying three bytes, the cycle times and size of the code are exactly the same (6 bytes, 6F+3R+3W+3). - If you want to copy a few more bytes than whatever number is in
BC
, it is both smaller and significantly faster to useINC BC
several times beforeLDDR
than a fewLDD
s after it. (INC BC
is one byte and only 1F (plus the extra 1R + 1W + 1 fromLDDR
) whereasLDD
is two bytes and 2F+1R+1W+1. So you just save one byte and 1F.)
- Interrupts can be triggered while this instruction is in progress (unless they are disabled using
- Examples
Filling a block of memory with a single byte
ld hl,EndOfBlock ld de,EndOfBlock-1 ld bc,SizeOfBlock-1 ld (hl),ByteToCopy lddr
- See Also
- CPDR, LD, LDD, LDI, LDIR