I came up with this:
Code: Select all
;
num2ascii: ;arrive A holding number 0-163
ld hl,numstr
ld (hl),'0'
inc hl
ld (hl),47 ;'0'-1
dec hl ;back to numstring
cp 100
jr c,nhun
ld (hl),'1' ;the hundred digit is now set
sub 100 ;account for that in A
nhun: inc hl ;onto the tens
ld b,10
tlp: inc (hl)
sub b ;keep subbing 10, and INCing digit until the carry is set
jr nc,tlp
inc hl ;now the ones, A is now 0-8
add a,58 ;add the ASCII '0' (48), and the extra 10 we subtracted when A overspun
ld (hl),a ;done
ret
;
numstring: db '000'
;