all repos — xyw @ 24fc8cfd45178b30d9c8e2bae216a4b2789bae27

A minimal virtual machine and assembler for terminals.

Implemented contains subroutine.
h3rald h3rald@h3rald.com
Thu, 06 Aug 2026 20:24:56 +0000
commit

24fc8cfd45178b30d9c8e2bae216a4b2789bae27

parent

f0a63ca87231d7c10f6026a68eb4599a309899cd

2 files changed, 46 insertions(+), 1 deletions(-)

jump to
M .gitignore.gitignore

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

xyw.exe xyw +examples/test.xyw tmp/ *.o -*.xim+*.xim
A examples/lib/contains.xyw

@@ -0,0 +1,44 @@

+; <str> <fragment> contains -> $00|$01 +; xw -> index of string +; yw -> index of fragment +; y -> internal index within fragment +; a16 b16 -[xxwyw]- a8 +.label contains + POPyw POPxw ; save both addresses to xw and yw + $00 POPy ; set y to zero + .label contains.checks + ; if at end of fragment, all good + LDByw $00 EQU contains.ok JCNw + ; if at end of string, fail + LDBxw $00 EQU contains.fail JCNw + ; check if contents of indexes are different + LDBxyw NEQ contains.different JCNw + ; otherwise they are matching + ; increment internal fragment index + INCy + ; increment both indexes + INCxyw + contains.checks JMPw + .label contains.str.incr + ; increment only string + INCxw + contains.checks JMPw + .label contains.different + ; letters are different + ; if started matching fragment, reset + PSHy contains.reset JCNw + ; otherwise increment string index + contains.str.incr JMPw + .label contains.reset + ; reset fragment scan + PSHyw $00 PSHy SUBw POPyw + ; reset string scan + PSHxw $00 PSHy SUBw POPxw + $00 POPy + contains.str.incr JMPw + .label contains.fail + ; no match + $00 RTS + .label contains.ok + ; fragment is contained in string + $01 RTS