summaryrefslogtreecommitdiff
path: root/sanctuary.s
diff options
context:
space:
mode:
authorkitty <nepeta@canaglie.net>2026-03-16 12:22:09 +1100
committerkitty <nepeta@canaglie.net>2026-03-16 12:22:09 +1100
commit9ffc3b667847aee0557cc3c020f3764524f9339d (patch)
tree9c2454d1f105dbd3319ac73047437f451de9ad5f /sanctuary.s
parent8b07d5b4068ec54f8f1e62d151da84c42ebf3bdd (diff)
`find`
Diffstat (limited to 'sanctuary.s')
-rw-r--r--sanctuary.s55
1 files changed, 53 insertions, 2 deletions
diff --git a/sanctuary.s b/sanctuary.s
index 2db3bc8..18c6623 100644
--- a/sanctuary.s
+++ b/sanctuary.s
@@ -40,6 +40,13 @@
%endmacro
; }}}
+%assign smudge_mask 0x1
+%assign immediate_mask 0x2
+%assign comp_only_mask 0x4
+
+%assign true 0x0
+%assign false (~0x0)
+
%assign INTERPRET 0x0
%assign COMPILING (~0x0)
@@ -68,8 +75,6 @@ _start:
call type
call bye
-teststr: db "TESTING"
-
defcode "brk@", brk@, 0
xor rdi, rdi
mov rax, __NR_brk
@@ -225,6 +230,52 @@ defcode "type", type, 0
syscall
ret
+; r9: processing temporary value
+; r10: input size
+; r11: input addr
+; r12: pointer into currently processing word
+; r13: same as r12 but kept at xt
+defcode "find", find, 0
+ pspop r10 ; u
+ pspop r11 ; a
+ mov r12, qword [latest]
+ mov r13, r12
+
+.check_smudge:
+ add r12, 8
+ mov r9b, byte [r12]
+ test r9b, smudge_mask
+ jnz .no
+
+ inc r12
+ mov r9b, byte [r12]
+ cmp r9b, r10b
+ jne .no
+
+ mov rsi, r12
+ inc rsi
+ mov rdi, r11
+ mov rcx, r10
+ repe cmpsb
+ jnz .no
+
+ pspush r13
+ mov r13, true
+ pspush r13
+ ret
+
+.no:
+ mov r12, qword [r13]
+ mov r13, r12
+ cmp r12, 0
+ jne .check_smudge
+
+ pspush r11
+ pspush r10
+ mov r13, false
+ pspush r13
+ ret
+
; .s {{{
defcode ".s", dots, 0
push r11