Download Print this page

ZiLOG Z80 Handbook page 196

Hide thumbs Also See for Z80:

Advertisement

HEADLS
MEMORY
LOCATION
1000H
1004
1008
100C
1010
1014
1018
101C
1020
1024
1028
102C
1030
1034
1038
103C
1040
1044
BYTE 0
1
2
3
KEY VALUE
OTHER DATA
LINK ADDRESS
TO NEXT ENTRY
- SHADED AREAS UNUSED ENTRY FORMAT
- VALUES IN ENTRIES ARE ADDRESS LINKS TO NEXT ENTRY IN LIST
Fig. 13 - 8. Typical single-ended linked list.
When data is to be deleted from the list, the previous pointer is
simply changed to the link address of the deleted item. When data
is to be inserted the pointer of the data item before the insertion
point is changed to the address of the new item. The address of the
new data item is loaded with the link address of the data item before
the insertion point. These actions are illustrated in Fig. 13-9.
The following Z-80 code shows a search of a single-ended linked
list for a given search key value. Each data item of the list consists
of an 8-bit data value and a 2-byte link address.
INSERT LD HL,HEADLS HEAD OF LIST
LD A,KEY SEARCH KEY
LD BC,1 FOR END OF LIST COMPARISON
OR A RESET CARRY
LOOP ADC HL,BC NEXT ADDRESS + 1
JP Z,END END OF LIST, NOT FOUND
DEC HL NEXT ADDRESS
LID D,(HL) GET NEXT ENTRY
CID D COMPARE NEXT TO S KEY
JP Z,FOUND GO IF FOUND
INC HL POINT TO ADDRESS
PUSH HL TRANSFER HL TO IX
POP IX
LD H,(IX+1) GET MSB OF ADDRESS
LD L,(IX) GET LSB OF ADDRESS
JP LOOP CONTINUE
1010
1004
1014
1000
-1
205

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