Download Print this page

ZiLOG Z80 Handbook page 187

Hide thumbs Also See for Z80:

Advertisement

Table 13-1. Five-Character String Comparison
Character
Total of
String
ASCII
Bytes
WHITE
57H,
48,
49,
54,
45
181H
GREEN
47,
52,
45,
45,
4E
171 H
BROWN
42,
52,
4F,
57,
4E
17EH
MAUVE
4D,
41,
55,
56,
45
17EH
An implementation of a search based on this simple hash is shown
in the following code.
HASHSR LD IX,CHAR START OF 5-CHAR KEY
LD A,(IX + 1) LOAD KEY CHARACTERS
ADD A,(IX+2)
ADD A,( IX+3)
ADD A ,(IX+4)
LD D,A SAVE IN D
LD HL, STRING START OF STRING
LD BC , 60 60 BYTES = DONE
LOOP LD A,(CHAR + O) FIRST CHARACTER
CPIR SEARCH FOR 1ST CHAR
JP NZ,NFND GO IF NOT FOUND
SECLVL PUSH HL SAVE POINTER
POP IX POINT TO 2ND CHAR
LD A,(IX)
ADD A ,( IX+ 1)
ADD A ,( IX+2)
ADD A,( IX+3) COMPUTE HASH
CP D COMPARE TO KEY HASH
JP NZ ,LOOP
GO IF NO MATCH
MAYBE LD IY,CHAR + 1 POINT TO 2ND CHAR OF KEY
LD A,(IX)
CP A,(IY)
JP NZ , LOOP GO IF NO MATCH 2ND CHAR
LD A,(IX+1)
CP A,(IY+1)
JP NZ , LOOP GO IF NO MATCH 3RD CHAR
LD A,(IX+2)
CP A,(IY+2)
JP NZ,LOOP GO IF NO MATCH 4TH CHAR
LD A,(IX+3)
CP A,(IY+3)
JP NZ , LOOP GO IF NO MATCH 5TH CHAR
FOUND FOUND!
If a match is found on the first character , SECLVL is entered. A
hash is then computed for the remaining four characters of the
string and compared to the precomputed key hash in D. If there is
196

Advertisement

loading
Need help?

Need help?

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