aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
l---------tests/stack_machine_function_call/Makefile1
-rw-r--r--tests/stack_machine_function_call/instructions.s.tcl88
l---------tests/stack_machine_function_call/test.v1
-rw-r--r--tests/stack_machine_function_call/words_to_verify.mem3
4 files changed, 93 insertions, 0 deletions
diff --git a/tests/stack_machine_function_call/Makefile b/tests/stack_machine_function_call/Makefile
new file mode 120000
index 0000000..2c3c770
--- /dev/null
+++ b/tests/stack_machine_function_call/Makefile
@@ -0,0 +1 @@
+../stack_machine_store/Makefile \ No newline at end of file
diff --git a/tests/stack_machine_function_call/instructions.s.tcl b/tests/stack_machine_function_call/instructions.s.tcl
new file mode 100644
index 0000000..450b669
--- /dev/null
+++ b/tests/stack_machine_function_call/instructions.s.tcl
@@ -0,0 +1,88 @@
+### call a simple function, that sums its 2 arguments
+
+## store sth at h1000 to later check if calee restored it properly
+# 1 16-bit instruction
+const h23
+# 2 16-bit instructions
+store h1000
+
+# function arguments - each loaded with 1 16-bit instruction
+const h32
+const h14
+# also 1 16-bit instruction
+call 18
+
+## this executes after return - store the computed difference at h400
+# this takes 2 16-bit instructions
+store h400
+# and this takes 1 16-bit instruction
+halt
+
+# address 18 here
+
+## function frame will look like this:
+## *****higher addresses*****
+## argument1
+## argument2
+## ...
+## return address
+## local1
+## local2
+## ...
+## previous frame address
+## *****lower addresses*****
+
+## push the arguments out of r0 and r1 to memory (+ claim space for
+## backed stack frame address and backed return address);
+## if we had n local variables, we'd repeat that n more times
+const 0
+const 0
+const 0
+
+## with this we get the address to reference our locals from into r1
+get_frame
+tee
+
+## we get our previous frame and back it up as first local
+load h1000
+store+ h0
+
+## we now store our new function frame
+store h1000
+
+## here the actual function body starts
+
+## fetch the first argument
+load h1000
+load+ hC
+
+## fetch the second one
+load h1000
+load+ h8
+
+sub
+
+## function exit - store the result at the the top of current frame
+load h1000
+swap
+store+ hC
+
+## put the return address just below result
+load h1000
+tee
+tee
+load+ h4
+store+ h8
+
+## restore old frame
+load+ 0
+store h1000
+
+## discard current frame
+drop
+drop
+drop
+drop
+
+## return
+ret
diff --git a/tests/stack_machine_function_call/test.v b/tests/stack_machine_function_call/test.v
new file mode 120000
index 0000000..f5b6a59
--- /dev/null
+++ b/tests/stack_machine_function_call/test.v
@@ -0,0 +1 @@
+../stack_machine_store/test.v \ No newline at end of file
diff --git a/tests/stack_machine_function_call/words_to_verify.mem b/tests/stack_machine_function_call/words_to_verify.mem
new file mode 100644
index 0000000..8048d6f
--- /dev/null
+++ b/tests/stack_machine_function_call/words_to_verify.mem
@@ -0,0 +1,3 @@
+// address value
+ 1000 23
+ 400 1E