25 lines
887 B
Z80 Assembly
25 lines
887 B
Z80 Assembly
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
|