added get_addr and jmp

This commit is contained in:
IgorCielniak
2026-02-12 17:39:05 +01:00
parent 709377a45b
commit a3c68860a7
4 changed files with 38 additions and 0 deletions

View File

@@ -1,3 +1,17 @@
#get_addr [*] -> [* | addr]
:asm get_addr {
mov rax, [rsp]
sub r12, 8
mov [r12], rax
};
#jmp [* | addr] -> [*]
:asm jmp {
mov rax, [r12]
add r12, 8
jmp rax
};
# Reserve 64 bytes in .bss # Reserve 64 bytes in .bss
# persistent: resb 64 # persistent: resb 64
# push the addr of it # push the addr of it

5
tests/jmp_test.expected Normal file
View File

@@ -0,0 +1,5 @@
gg
gg
gg
gg
gg

18
tests/jmp_test.sl Normal file
View File

@@ -0,0 +1,18 @@
import stdlib.sl
word main
5 # loop count
get_addr # push loop target address (next instruction)
"gg" puts
swap # bring count to top
1 - # decrement
dup 0 > if
swap # put addr on top
dup # keep a copy for next iteration
jmp
else
drop # drop count
drop # drop addr
end
end

1
tests/jmp_test.test Normal file
View File

@@ -0,0 +1 @@
python main.py tests/jmp_test.sl -o ./build/jmp_test > /dev/null && ./build/jmp_test