Add std/string/array/compare.lb

This commit is contained in:
bʰedoh₂ swé 2024-06-18 03:56:21 +05:00
parent efa1d86be9
commit ba274c0371

View File

@ -0,0 +1,84 @@
@ 0 ; Getting all arguments
args 0
size
args 1
dup
|#insert push
push 1
|#insert jmp
|args
jmp 255
@ 1
dup
#expr +
pick ; Finish getting arguments
dup ; Duplicate top two elements
push 2
pick
sub ; Lengths unequal => strings unequal
jnz 2
pop
push 0
@ 4
dup ; Duplicate top two elements
push 2
pick
; |str_size index...>
sub
jz 5
; |index str_size...>
dup ; Get current symbol of s1
push 2
add
pick
; |char index str_size...>
push 2 ; Get string size
pick
push 2 ; Get current symbol of s2
pick
add
push 4
add
pick
sub ; Check symbol equality
jnz 2
; |index...>
#expr +
jmp 4
@ 2 ; Clear stack (diff)
size
jz 3
pop
jmp 2
@ 3 ; Exit, string are different
push 0
quit
@ 6 ; Clear stack (equ)
size
jz 5
pop
jmp 6
@ 5 ; Exit, string are the same
push 1
quit
@ 255