all repos — xyw @ 88877124cdbbd5971f945225c8ec4a7589014f6b

A minimal virtual machine and assembler for terminals.

Changed conventions for macros
h3rald h3rald@h3rald.com
Fri, 06 Feb 2026 20:54:15 +0100
commit

88877124cdbbd5971f945225c8ec4a7589014f6b

parent

1b6b52288f1fb5be2400a519dca0dc21f67ab66a

M examples/clock.xywexamples/clock.xyw

@@ -13,13 +13,13 @@ end JMPw

; a8 -- | [x] .label ZEROPADx - POPx PSHx $0A LTH put_zero JCNw - .label put_digit - PSHx PUTD JSRw + POPx PSHx $0A LTH put-zero JCNw + .label put-digit + PSHx putd JSRw RTS - .label put_zero + .label put-zero $30 PUTC - put_digit JMPw + put-digit JMPw -.include "lib/PUTD.xyw" +.include "lib/putd.xyw" .label end
M examples/factorial16.xywexamples/factorial16.xyw

@@ -2,7 +2,7 @@ .include "lib/macros.xyw"

; Main program: calculate and print factorial of 7 $0007 fact JSRw -PUTDw JSRw +putdw JSRw NL end JMPw

@@ -30,6 +30,6 @@ PSHxw

CLRxyw RTS -.include "lib/PUTDw.xyw" +.include "lib/putdw.xyw" .label end
M examples/factorial8.xywexamples/factorial8.xyw

@@ -2,7 +2,7 @@ .include "lib/macros.xyw"

; Main program: calculate and print factorial of 5 $05 fact JSRw -PUTD JSRw +putd JSRw NL end JMPw

@@ -28,6 +28,6 @@ PSHx

CLRxy RTS -.include "lib/PUTD.xyw" +.include "lib/putd.xyw" .label end
M examples/lib/PUTD.xywexamples/lib/putd.xyw

@@ -2,20 +2,20 @@ ; .include "lib/macros.xyw"

; Print an 8bit integer as decimal ; a8 -- | [x] -.label PUTD +.label putd POPx ; If value is less than 10, print single digit - PSHx $0A LTH PUTD.single JCNw + 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 + putd JSRw ; Remainder is still on stack, print it - $30 ADD terminal.output STB + $30 ADD PUTC CLRx RTS - .label PUTD.single + .label putd.single ; Print single digit - PSHx $30 ADD terminal.output STB + PSHx $30 ADD PUTC CLRx RTS
M examples/lib/PUTDw.xywexamples/lib/putdw.xyw

@@ -2,21 +2,21 @@ ; .include "lib/macros.xyw"

; Print a 16bit integer as decimal ; a16 -- | [x] -.label PUTDw +.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 + PSHxw $000A LTHw LBYTE putdw.single JCNw ; Divide by 10, stack becomes [remainder, quotient] with quotient on top - PSHxw $00 $0A DIVw + PSHxw $000A DIVw ; Call PUTDw recursively with quotient (on top, consumed by POPxw) - PUTDw JSRw + putdw JSRw ; Remainder (16-bit) is still on stack, get low byte and print it - SWP POP $30 ADD terminal.output STB + SWP POP $30 ADD PUTC CLRxw RTS - .label PUTDw.single + .label putdw.single ; Print single digit (need low byte of XW since value is 0-9) - PSHxw SWP POP $30 ADD terminal.output STB + PSHxw SWP POP $30 ADD PUTC CLRxw RTS
M examples/lib/PUTS.xywexamples/lib/puts.xyw

@@ -2,10 +2,10 @@ ; .include "lib/macros.xyw"

; Print a string starting at address ; a16 -- | [xw] -.label PUTS +.label puts POPxw .label PUTS.loop - LDBxw terminal.output STB - INCxw LDBxw PUTS.loop JCNw + LDBxw PUTC + INCxw LDBxw puts.loop JCNw CLRxw RTS
M examples/on-error.xywexamples/on-error.xyw

@@ -10,15 +10,15 @@

; on error handler .label on_error system.error LDB $01 EQU on_error.div-by-zero.print JCNw - unknown-error PUTS JSRw + unknown-error puts JSRw $00 system.error STB RTS .label on_error.div-by-zero.print - div-by-zero-error PUTS JSRw + div-by-zero-error puts JSRw $03 system.error STB RTS -.include "lib/PUTS.xyw" +.include "lib/puts.xyw" .label div-by-zero-error .string "Error: Division by zero.\n"