RosettaCodeData/Task/Increment-a-numerical-string/Z80-Assembly/increment-a-numerical-strin...

44 lines
868 B
Z80 Assembly

;;;;;;;;;;;;;;;;;;; HEADER ;;;;;;;;;;;;;;;;;;;
read "\SrcCPC\winape_macros.asm"
read "\SrcCPC\MemoryMap.asm"
read "\SrcALL\winapeBuildCompat.asm"
;;;;;;;;;;;;;;;;;;; PROGRAM ;;;;;;;;;;;;;;;;;;;
org &1000
ld hl,NumericString
incstring:
ld a,(hl)
cp 255
jr z,displaystring
add &01
cp &3A
jr nz,displaystring
;carry forward
ld a,&30
ld (hl),a
inc hl
jr incstring
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
displaystring:
ld (hl),a ;store the last addition.
ld hl,NumericString_End
dec hl
disploop:
ld a,(hl)
cp 255
ret z
call &bb5a
dec hl
jr disploop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
db 255 ;terminator when reading in reverse
NumericString:
;stored little-endian for convenience
db &39,&39,&39,&31
NumericString_End:
db 255 ;terminator
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
read "\SrcCPC\winape_showhex.asm"
read "\SrcCPC\winape_stringop.asm"