RosettaCodeData/Task/Collections/Z80-Assembly/collections-2.z80
2023-07-01 13:44:08 -04:00

25 lines
887 B
Z80 Assembly
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

List:
byte 5 ;size byte
byte 1,2,3,4,5 ;the actual list
byte 0,0,0,0,0 ;free space
;NOTE: separating the above list into different rows is just for visual clarity - it makes no difference to the CPU!
AppendList:
;input: A = the value you wish to append.
ld hl,List
ld a,(HL) ;get the size byte
ld b,a ;store in B to use as loop counter for DJNZ
inc hl ;increment HL past the "size byte" to the actual data.
push hl ;save this pointer for later
push af ;save the value we want to append for later.
GotoEndOfList:
inc hl
djnz GotoEndOfList
;now, HL points to the first "free" byte.
pop af
ld (HL),a ;store at the end of the list
pop hl ;go back to beginning of the list.
inc (hl) ;add 1 to the size byte.
ret