Download Print this page

ZiLOG Z80 Handbook page 185

Hide thumbs Also See for Z80:

Advertisement

list. The contents of HL is decremented after each iteration of the
instruction; the contents of BC is, of course, decremented as in the
CPIR. The initialization for a 64-character string for use with a
CPDR is as follows.
SRCHD LD A,24H DOLLAR SIGN
LD HL,STRING+63 ADDRESS OF LAST CHAR
LD BC,64 64 BYTES MAXIMUM
CPDR SEARCH FOR $ BACKWARDS
CPIR and CPDR work extremely efficiently for one-character
keys. The time per iteration if the key is not found is 5.25 microsec-
onds, making the average search time through a 64-character string
(64/2) x 5.25 = 168 microseconds. The corresponding code for an
access, compare, conditional test, adjust of byte count and pointer,
and conditional test would be about double the CPIR or CPDR and
occupy a great deal more memory.
If a key of more than one character is required, the compare
string instructions may also be used, but the comparison process will
not be quite as efficient as a search for a single byte. If the first char-
acter search is made on a frequently occurring character (such as
A
I
24 H
SEARCH KEY
SEARCH D IRECTION
I
+63
B
00
Z
1
24H
STRING +8
F I R ST MATCH
C
5610
0
Fig. 13-1. String search terminating conditions.
194

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

Subscribe to Our Youtube Channel