From 9ffc3b667847aee0557cc3c020f3764524f9339d Mon Sep 17 00:00:00 2001 From: kitty Date: Mon, 16 Mar 2026 12:22:09 +1100 Subject: `find` --- sanctuary.s | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) (limited to 'sanctuary.s') 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 -- cgit v1.2.3