all repos — xyw @ b4405494fd2f54383c8bcc2357b0e6b6e0b34d02

A minimal virtual machine and assembler for terminals.

examples/print8.xyw

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