all repos — xyw @ 0c93fbcf0b954125fea52bcba6b44f82ebbbe7c5

A minimal virtual machine and assembler for terminals.

examples/lib/contains.xyw

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 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