added get_addr and jmp
This commit is contained in:
@@ -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
|
||||
# persistent: resb 64
|
||||
# push the addr of it
|
||||
|
||||
5
tests/jmp_test.expected
Normal file
5
tests/jmp_test.expected
Normal file
@@ -0,0 +1,5 @@
|
||||
gg
|
||||
gg
|
||||
gg
|
||||
gg
|
||||
gg
|
||||
18
tests/jmp_test.sl
Normal file
18
tests/jmp_test.sl
Normal 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
1
tests/jmp_test.test
Normal file
@@ -0,0 +1 @@
|
||||
python main.py tests/jmp_test.sl -o ./build/jmp_test > /dev/null && ./build/jmp_test
|
||||
Reference in New Issue
Block a user