labashki/std/string/array/compare.lb

85 lines
839 B
Plaintext
Raw Permalink Normal View History

2024-06-17 22:56:21 +00:00
@ 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