summaryrefslogtreecommitdiff
path: root/projects/08/FunctionCalls/NestedCall/Sys.vm
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2022-08-16 11:54:23 +0800
committerFrederick Yin <fkfd@fkfd.me>2022-08-16 11:54:23 +0800
commit9542deeb483a00b6fabed7574720926ce97d7511 (patch)
tree0f2c1f72c03dd4693fd59df67544d2a4dddc5494 /projects/08/FunctionCalls/NestedCall/Sys.vm
parent9c0cb1d1c32724fc95ac9548e4f8d873d3adaccc (diff)
Projects, 01-06 completed
Diffstat (limited to 'projects/08/FunctionCalls/NestedCall/Sys.vm')
-rw-r--r--projects/08/FunctionCalls/NestedCall/Sys.vm63
1 files changed, 63 insertions, 0 deletions
diff --git a/projects/08/FunctionCalls/NestedCall/Sys.vm b/projects/08/FunctionCalls/NestedCall/Sys.vm
new file mode 100644
index 0000000..8b0b003
--- /dev/null
+++ b/projects/08/FunctionCalls/NestedCall/Sys.vm
@@ -0,0 +1,63 @@
+// Sys.vm for NestedCall test.
+
+// Sys.init()
+//
+// Calls Sys.main() and stores return value in temp 1.
+// Does not return. (Enters infinite loop.)
+
+function Sys.init 0
+push constant 4000 // test THIS and THAT context save
+pop pointer 0
+push constant 5000
+pop pointer 1
+call Sys.main 0
+pop temp 1
+label LOOP
+goto LOOP
+
+// Sys.main()
+//
+// Sets locals 1, 2 and 3, leaving locals 0 and 4 unchanged to test
+// default local initialization to 0. (RAM set to -1 by test setup.)
+// Calls Sys.add12(123) and stores return value (135) in temp 0.
+// Returns local 0 + local 1 + local 2 + local 3 + local 4 (456) to confirm
+// that locals were not mangled by function call.
+
+function Sys.main 5
+push constant 4001
+pop pointer 0
+push constant 5001
+pop pointer 1
+push constant 200
+pop local 1
+push constant 40
+pop local 2
+push constant 6
+pop local 3
+push constant 123
+call Sys.add12 1
+pop temp 0
+push local 0
+push local 1
+push local 2
+push local 3
+push local 4
+add
+add
+add
+add
+return
+
+// Sys.add12(int n)
+//
+// Returns n+12.
+
+function Sys.add12 0
+push constant 4002
+pop pointer 0
+push constant 5002
+pop pointer 1
+push argument 0
+push constant 12
+add
+return