EX AF,AF' and EXX would probably be used most frequently in
saving the environment during interrupt processing. One reason for
not using the instructions at other times is that if the primed registers
are used for temporary storage and also used for interrupt storage,
it is very probable that some of the temporary data.will be de-
stroyed if interrupts are permitted while both sets of CPU registers
are being used . It is best to reserve the primed registers for process-
ing use only and utilize the stack or memory for temporary storage.
The EX DE,HL instruction swaps the contents of register pair
DE and HL. The instruction is useful for moving data from the DE
to HL for the limited arithmetic operations that can be performed
to HL. As an example of this , suppose the contents of DE were to
be doubled. The following code would move DE to HL, add HL to
itself to double the contents and move the result back into DE.
EX DE,HL DE TO HL
ADD HL, HL HL + HL TO HL
EX DE, HL HL TO DE
The remaining three instructions in this group exchange the con-
tents of the top of stack with either HL, IX, or IY. The SP is not
affected by the swap. Clearly, the manufacturer had a good reason
for the exchange of HL and top of stack [EX (SP),HL - Intel] and
the index registers [EX (SP), IX or .... IY - Zilog]. It will be left
as an exercise for the reader to discover for himself what those rea-
sons are. (Seriously, one application is to permit adjustment of the
return address for a call to enable a return to a location other than
the one following the call.)
160
Need help?
Do you have a question about the Z80 and is the answer not in the manual?
Questions and answers