all repos — xyw @ f789e941e1f994ca076b6e14f1fafee9273850e2

A minimal virtual machine and assembler for terminals.

added examples
h3rald h3rald@h3rald.com
Thu, 11 Dec 2025 10:38:49 +0100
commit

f789e941e1f994ca076b6e14f1fafee9273850e2

parent

0a1a637d34e7e6011e534681839a73fe619a8fb7

3 files changed, 54 insertions(+), 0 deletions(-)

jump to
A examples/d6.xyw

@@ -0,0 +1,18 @@

+.include "devices.xyw" + +; Get random number and calculate modulo 6 +clock.random LDBw $6 modulo JSRw + +; Print result+1 and new line +$31 ADD console.output STBw +$0d console.output STBw + +; Terminate +$0 system.state STBw + +; Calculate the modulo +; a b -- a%b +.label modulo + POPy POPx + PSHx PSHy PSHx PSHy DIV MUL SUB + RTS
A examples/factorial.xyw

@@ -0,0 +1,12 @@

+; main program +$5 fact JSRw +$0 system.state STBw + +; a8 -- +.label fact + $1 EQU fact.end JCNw + INC MUL + fact JMPw + .label fact.end + ; TODO: print + RTS
A examples/helloworld.xyw

@@ -0,0 +1,24 @@

+; include device macros +.include "devices.xyw" + +; main program +hello print JSRw +; terminate +$0 system.state STBw + +; a16 -- +; printing subroutine +.label print + ; store top of stack to register XW + POPxw + .label print.loop + ; dereference address in XW and print + LDBxw console.output STBw + ; increment address, dereference + ; go back to loop unless zero + INCxw LDBxw print.loop JCNw + RTS + +; store null-terminated string +.label hello +.string "Hello, World!\n"