examples/lib/PUTDw.xyw
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
; .include "_macros.xyw"
; Print a 16bit integer as decimal
; a16 -- | [x]
.label PUTDw
POPxw
; If value is less than 10, print single digit
; Push 16-bit literal as two bytes (high, low), then compare
PSHxw $00 $0A LTHw SWP POP PUTDw.single JCNw
; Divide by 10, stack becomes [remainder, quotient] with quotient on top
PSHxw $00 $0A DIVw
; Call PUTDw recursively with quotient (on top, consumed by POPxw)
PUTDw JSRw
; Remainder (16-bit) is still on stack, get low byte and print it
SWP POP $30 ADD terminal.output STB
CLRxw
RTS
.label PUTDw.single
; Print single digit (need low byte of XW since value is 0-9)
PSHxw SWP POP $30 ADD terminal.output STB
CLRxw
RTS
|