all repos — xyw @ 51f5be3e8e93c45dd88cf45723892f328abb1f84

A minimal virtual machine and assembler for terminals.

Updated notation for stack effects.
h3rald h3rald@h3rald.com
Sun, 16 Aug 2026 20:17:13 +0200
commit

51f5be3e8e93c45dd88cf45723892f328abb1f84

parent

7080189bfbe1142ee142ec78c35df1b34184a68a

M examples/clock-repl.xywexamples/clock-repl.xyw

@@ -50,12 +50,12 @@ ; Echo the character

PUTC RTS -; a8 -> +; b -> .label on-ignore POP RTS ; Enter: echo back the line -; a8 -> +; b -> .label on-enter POP NL

@@ -69,7 +69,7 @@ print-prompt JSRw

RTS ; Backspace: remove last character -; a8 -> +; b -> .label on-backspace POP buf-len LDBw $00 EQU on-backspace.done JCNw

@@ -114,7 +114,7 @@ .label print-buffer.done

RTS ; Print 8-bit value with leading zero if < 10 -; a8 -> +; b -> .label ZEROPADx POPx PSHx $0A LTH zeropad.zero JCNw .label zeropad.digit
M examples/factorial16.xywexamples/factorialw.xyw

@@ -7,7 +7,7 @@ NL

HLT ; Factorial subroutine -; a16 -> +; w -> .label fact ; Save argument to both registers POPxyw
M examples/factorial8.xywexamples/factorial.xyw

@@ -7,7 +7,7 @@ NL

HLT ; Factorial subroutine -; a8 -> +; b -> .label fact ; Save argument to both registers POPxy
M examples/helloworld.xywexamples/helloworld.xyw

@@ -3,7 +3,7 @@ hello print JSRw

HLT ; printing subroutine -; a16 -> +; s -> .label print ; store top of stack to register XW POPxw
M examples/korobeiniki.xywexamples/korobeiniki.xyw

@@ -12,7 +12,7 @@ ; Store address of start song in xw

start-song POPxw ; Process <length> <pitch> pairs until end-song -; a16 b16 -> +; w1 w2 -> .label play ; Set length LDWxw beeper.length STW
M examples/lib/contains.xywexamples/lib/contains.xyw

@@ -1,8 +1,8 @@

-; <str> <fragment> contains -> $00|$01 -; xw -> index of string -; yw -> index of fragment -; y -> internal index within fragment -; a16 b16 -> a8 +; Pushes $01 if s1 contains s2, $00 otherwise +; s1 s2 -> f +; xw: index of string +; yw: index of fragment +; y : internal index within fragment .label contains POPyw POPxw ; save both addresses to xw and yw $00 POPy ; set y to zero
M examples/lib/equals.xywexamples/lib/equals.xyw

@@ -1,5 +1,5 @@

-; Check if two strings are equal -; a16 b16 -> a8 +; Pushes $01 if s1 == s2, $00 otherwise +; s1 s2 -> f .label equals ; save addresses to registers POPyw POPxw
M examples/lib/length.xywexamples/lib/length.xyw

@@ -1,5 +1,5 @@

-; returns the length of a string (max: 255) -; a16 -> a8 +; Pushes the length of s +; s -> b .label length POPxw ; store start address $00 POPx ; counter
M examples/lib/lengthw.xywexamples/lib/lengthw.xyw

@@ -1,5 +1,5 @@

-; returns the length of a string -; a16 -> b16 +; Pushes the length of s +; s -> w .label lengthw POPxw ; store start address $0000 POPyw ; counter
M examples/lib/lowcase.xywexamples/lib/lowcase.xyw

@@ -1,5 +1,5 @@

; Convert a string to lowercase -; a16 -> +; s -> .label lowcase ; store index POPxw
M examples/lib/oneof.xywexamples/lib/oneof.xyw

@@ -1,5 +1,5 @@

-; Checks if char a16 is one of chars in b16 (string) -; a16 b16 -> a8 +; Checks if char in a is one of chars in s2 +; a s2 -> f .label oneof POPyw POPxw
M examples/lib/osdetect.xywexamples/lib/osdetect.xyw

@@ -3,7 +3,7 @@ ; .include "lib/lowcase.xyw"

; .include "lib/contains.xyw" ; Pushes address to OS identifier -; -> a16 +; -> s .label osdetect ; Set command to execute osdetect.cmd file.path STW
M examples/lib/putd.xywexamples/lib/putd.xyw

@@ -1,5 +1,7 @@

+; .include "lib/macros.xyw" + ; Print an 8bit integer as decimal -; a8 -> +; b -> .label putd POPx ; If value is less than 10, print single digit
M examples/lib/putdw.xywexamples/lib/putdw.xyw

@@ -1,7 +1,7 @@

; .include "lib/macros.xyw" ; Print a 16bit integer as decimal -; a16 -> +; w -> .label putdw POPxw ; If value is less than 10, print single digit
M examples/lib/puts.xywexamples/lib/puts.xyw

@@ -1,7 +1,7 @@

; .include "lib/macros.xyw" ; Print a string starting at address -; a16 -> +; s -> .label puts POPxw .label puts.loop
M examples/lib/trimend.xywexamples/lib/trimend.xyw

@@ -1,7 +1,7 @@

; .include "lib/oneof.xyw" -; Remeve space chats at end of string -; a16 -> +; Remeve space chars at end of string +; s -> .label trimend ; save string address POPxw
M examples/lib/trimstart.xywexamples/lib/trimstart.xyw

@@ -1,7 +1,7 @@

; .include "lib/oneof.xyw" ; Pushes the address of string trimmed at start -; a16 -> b16 +; s1 -> s2 .label trimstart ; Save string address POPxw ; start address (to return) m
M examples/lib/upcase.xywexamples/lib/upcase.xyw

@@ -1,5 +1,5 @@

; Convert a string to uppercase -; a16 -> +; s -> .label upcase ; store index POPxw
M examples/time.xywexamples/time.xyw

@@ -40,7 +40,7 @@ ZEROPADx JSRw

RTS ; Print an 8bit integer as decimal, with leading zero if less than 10 -; a8 -> +; b -> .label ZEROPADx POPx PSHx $0A LTH put-zero JCNw .label put-digit
M test.shtest.sh

@@ -8,8 +8,8 @@ run_test helloworld.xyw -- assert_output_equals $'Hello, World!\n'

run_test d6.xyw -- assert_output_in_range 1 6 run_test on-error.xyw -- assert_output_equals $'Error: Division by zero.\n' run_test print-args.xyw test1 test2 -- assert_output_equals $'print-args.xim, test1, test2\n' - run_test factorial8.xyw -- assert_output_equals $'120\n' - run_test factorial16.xyw -- assert_output_equals $'5040\n' + run_test factorial.xyw -- assert_output_equals $'120\n' + run_test factorialw.xyw -- assert_output_equals $'5040\n' run_test fileops.xyw -- assert_output_equals $'This is a test file.\nIt has multiple lines.\n' # Cleanup test file rm -f "$EXAMPLES_DIR/test.txt"