examples/lib/PUTD.xyw
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
; .include "lib/macros.xyw"
; Print an 8bit integer as decimal
; a8 -- | [x]
.label PUTD
POPx
; If value is less than 10, print single digit
PSHx $0A LTH PUTD.single JCNw
; Divide by 10: stack becomes [remainder, quotient] with quotient on TOP
PSHx $0A DIV
; Call PUTD recursively with quotient (on top, consumed by POPx)
PUTD JSRw
; Remainder is still on stack, print it
$30 ADD terminal.output STB
CLRx
RTS
.label PUTD.single
; Print single digit
PSHx $30 ADD terminal.output STB
CLRx
RTS
|