Download Print this page

ZiLOG Z80 Handbook page 162

Hide thumbs Also See for Z80:

Advertisement

8-BIT KEY
A REGISTER
1
Fig. 11 -1. Table search example.
KEY 1
ENTRY 1
+7
+889
+890
+891
+892
+893
+894
+895
KEY 128
ENTRY 128
caution. The 16-bit INCs or DECs do not affect any condition code
flags. One implication of this is that a register pair cannot easily be
tested for a decrement of a count down to zero or a limit condition.
If a register pair is to be used to hold a count, a 16-bit add or sub-
tract may be used in place of the INC or DEC to increment or decre-
ment the register pair, as these instructions do set the carry and, in
some cases, the zero flag. Here is an example of how the ADD HL,SS
instruction may be used to control the number of iterations through
a LOOP.
LD DE,-1 LOAD -1 TO DE
LD IX,TABLE START OF TABLE
LD HL,COUNT LOAD COUNT OF N-1
LOOP
(PROCESSING)
INC IX POINT TO NEXT BYTE OF TABLE
ADD HL,DE DECREMENT COUNT BY 1
JP C,LOOP CONTINUE
The count is initialized to one less than the number of iterations
required. The last instruction of the routine tests the state of the
carry. The next to last instruction effectively decrements the count
in HL by one. No carry is produced (only if -1 is added to a 0 in
171

Advertisement

loading
Need help?

Need help?

Do you have a question about the Z80 and is the answer not in the manual?

Questions and answers