PUTD.xyw
putd.xyw; .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 PUTC
CLRx
RTS
.label putd.single
; Print single digit
PSHx $30 ADD PUTC
CLRx
RTS