all repos — xyw @ dff71d1935009002ad772f0a3246c823507f2976

A minimal virtual machine and assembler for terminals.

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