LDDR¶
- LDDR
- Load and Decrement with Repeat
- Description
- Performs
ldduntilBC= 0, effectively copyingBCbytes of data fromHLtoDE, whereHLandDEpoint 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) SflagNot affected ZflagNot affected HflagReset P/VflagSet if BC≠ 0 after the operation; else resetNflagReset CflagNot affected - Allowed Instructions
Instruction Opcode CC (ADL/non-ADL) CC (.S) CC (.L) lddr $ED, $B8 2F + (1R + 1W + 1)* BC3F + (1R + 1W + 1)* BC3F + (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,
LDIRis 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
LDDs instead ofld bc,BytesToCopy \ lddrif 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 BCseveral times beforeLDDRthan a fewLDDs after it. (INC BCis one byte and only 1F (plus the extra 1R + 1W + 1 fromLDDR) whereasLDDis 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