LDIR and the LDD and LDDR is that the latter two transfer data
in descending order. HL and DE are set to the ending address of
the source and destination data blocks, respectively, and each is
decremented to point to the next lower byte by the LDD or LDDR.
To transfer data from the previous example, the code would read:
LD HL,ENDS
SOURCE END
LD DE,ENDD
DEST END
LD BC,64
# OF BYTES
LDDR
TRANSFER 64 BYTES
DONE
STAB
DEFS 64
SOURCE TABLE
ENDS
EQU $-1
DTAB
DEFS 64
DESTINATION TABLE
ENDD
EQU $-1
EXCHANGE GROUP
There are six instructions in the exchange group. Two of them
transfer data between the current set of CPU registers and the
primed (') set. Three others allow the HL and index registers to
exchange their contents with the top of the stack. The last simply
exchanges the contents of DE with HL.
When the CPU is initialized, one set of the two eight-register sets
becomes the current set. The other set containing A', F, B', C', D',
E', H', and L' may be accessed via the two exchange instructions
EX AF,AF' and EXX. EX AF,AF' swaps the contents of A and F
with A' and F'. To temporarily store A and F, the following code
could be used:
EX AF ,AF' SAVE A,F
c
PROCESSING
c
EX AF ,AF' RESTORE A,F
Likewise, EXX swaps BC, DE , and HL with BC', DE ', and HL'.
EXX SAVE BC, DE, HL
LD BC, NEW1 NEW ADDRESSES
LD DE,NEW2
LD HL,NEW3
PROCESSING
c
EXX RESTORE BC, DE,HL
159
Need help?
Do you have a question about the Z80 and is the answer not in the manual?
Questions and answers