examples/print16.xyw
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
; .include "devices.xyw"
; Print a 16bit integer
; a16 -- | [x]
.label print16
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 print16.single JCNw
; Divide by 10, stack becomes [remainder, quotient] with quotient on top
PSHxw $00 $0A DIVw
; Call print16 recursively with quotient (on top, consumed by POPxw)
print16 JSRw
; Remainder (16-bit) is still on stack, get low byte and print it
SWP POP $30 ADD terminal.output STB
CLRxw
RTS
.label print16.single
; Print single digit (need low byte of XW since value is 0-9)
PSHxw SWP POP $30 ADD terminal.output STB
CLRxw
RTS
|