summaryrefslogtreecommitdiff
path: root/projects/08/FunctionCalls/NestedCall
diff options
context:
space:
mode:
Diffstat (limited to 'projects/08/FunctionCalls/NestedCall')
-rw-r--r--projects/08/FunctionCalls/NestedCall/NestedCall.asm501
1 files changed, 501 insertions, 0 deletions
diff --git a/projects/08/FunctionCalls/NestedCall/NestedCall.asm b/projects/08/FunctionCalls/NestedCall/NestedCall.asm
new file mode 100644
index 0000000..98c3438
--- /dev/null
+++ b/projects/08/FunctionCalls/NestedCall/NestedCall.asm
@@ -0,0 +1,501 @@
+@256
+D=A
+@SP
+M=D
+@NestedCall$ret_init
+D=A
+@SP
+A=M
+M=D
+@LCL
+D=M
+@SP
+AM=M+1
+M=D
+@ARG
+D=M
+@SP
+AM=M+1
+M=D
+@THIS
+D=M
+@SP
+AM=M+1
+M=D
+@THAT
+D=M
+@SP
+AM=M+1
+M=D
+@SP
+MD=M+1
+@LCL
+M=D
+@5
+D=D-A
+@ARG
+M=D
+@Sys.init
+0;JMP
+(NestedCall$ret_init)
+// function Sys.init 0
+(Sys.init)
+// push constant 4000
+@4000
+D=A
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// pop pointer 0
+@SP
+AM=M-1
+D=M
+@THIS
+M=D
+// push constant 5000
+@5000
+D=A
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// pop pointer 1
+@SP
+AM=M-1
+D=M
+@THAT
+M=D
+// call Sys.main 0
+@Sys$ret.0
+D=A
+@SP
+A=M
+M=D
+@LCL
+D=M
+@SP
+AM=M+1
+M=D
+@ARG
+D=M
+@SP
+AM=M+1
+M=D
+@THIS
+D=M
+@SP
+AM=M+1
+M=D
+@THAT
+D=M
+@SP
+AM=M+1
+M=D
+@SP
+MD=M+1
+@LCL
+M=D
+@5
+D=D-A
+@ARG
+M=D
+@Sys.main
+0;JMP
+(Sys$ret.0)
+// pop temp 1
+@SP
+AM=M-1
+D=M
+@6
+M=D
+// label LOOP
+(Sys$LOOP)
+// goto LOOP
+@Sys$LOOP
+0;JMP
+// function Sys.main 5
+(Sys.main)
+@SP
+A=M
+M=0
+@SP
+AM=M+1
+M=0
+@SP
+AM=M+1
+M=0
+@SP
+AM=M+1
+M=0
+@SP
+AM=M+1
+M=0
+@SP
+M=M+1
+// push constant 4001
+@4001
+D=A
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// pop pointer 0
+@SP
+AM=M-1
+D=M
+@THIS
+M=D
+// push constant 5001
+@5001
+D=A
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// pop pointer 1
+@SP
+AM=M-1
+D=M
+@THAT
+M=D
+// push constant 200
+@200
+D=A
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// pop local 1
+@1
+D=A
+@LCL
+M=M+D
+@SP
+AM=M-1
+D=M
+@LCL
+A=M
+M=D
+@1
+D=A
+@LCL
+M=M-D
+// push constant 40
+@40
+D=A
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// pop local 2
+@2
+D=A
+@LCL
+M=M+D
+@SP
+AM=M-1
+D=M
+@LCL
+A=M
+M=D
+@2
+D=A
+@LCL
+M=M-D
+// push constant 6
+@6
+D=A
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// pop local 3
+@3
+D=A
+@LCL
+M=M+D
+@SP
+AM=M-1
+D=M
+@LCL
+A=M
+M=D
+@3
+D=A
+@LCL
+M=M-D
+// push constant 123
+@123
+D=A
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// call Sys.add12 1
+@Sys$ret.1
+D=A
+@SP
+A=M
+M=D
+@LCL
+D=M
+@SP
+AM=M+1
+M=D
+@ARG
+D=M
+@SP
+AM=M+1
+M=D
+@THIS
+D=M
+@SP
+AM=M+1
+M=D
+@THAT
+D=M
+@SP
+AM=M+1
+M=D
+@SP
+MD=M+1
+@LCL
+M=D
+@6
+D=D-A
+@ARG
+M=D
+@Sys.add12
+0;JMP
+(Sys$ret.1)
+// pop temp 0
+@SP
+AM=M-1
+D=M
+@5
+M=D
+// push local 0
+@LCL
+D=M
+@0
+A=D+A
+D=M
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// push local 1
+@LCL
+D=M
+@1
+A=D+A
+D=M
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// push local 2
+@LCL
+D=M
+@2
+A=D+A
+D=M
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// push local 3
+@LCL
+D=M
+@3
+A=D+A
+D=M
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// push local 4
+@LCL
+D=M
+@4
+A=D+A
+D=M
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// add
+@SP
+AM=M-1
+D=M
+A=A-1
+M=D+M
+// add
+@SP
+AM=M-1
+D=M
+A=A-1
+M=D+M
+// add
+@SP
+AM=M-1
+D=M
+A=A-1
+M=D+M
+// add
+@SP
+AM=M-1
+D=M
+A=A-1
+M=D+M
+// return
+@LCL
+D=M
+@5
+A=D-A
+D=M
+@R13
+M=D
+@SP
+A=M-1
+D=M
+@ARG
+A=M
+M=D
+@ARG
+D=M+1
+@SP
+M=D
+@LCL
+AM=M-1
+D=M
+@THAT
+M=D
+@LCL
+AM=M-1
+D=M
+@THIS
+M=D
+@LCL
+AM=M-1
+D=M
+@ARG
+M=D
+@LCL
+AM=M-1
+D=M
+@LCL
+M=D
+@R13
+A=M
+0;JMP
+// function Sys.add12 0
+(Sys.add12)
+// push constant 4002
+@4002
+D=A
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// pop pointer 0
+@SP
+AM=M-1
+D=M
+@THIS
+M=D
+// push constant 5002
+@5002
+D=A
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// pop pointer 1
+@SP
+AM=M-1
+D=M
+@THAT
+M=D
+// push argument 0
+@ARG
+D=M
+@0
+A=D+A
+D=M
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// push constant 12
+@12
+D=A
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// add
+@SP
+AM=M-1
+D=M
+A=A-1
+M=D+M
+// return
+@LCL
+D=M
+@5
+A=D-A
+D=M
+@R13
+M=D
+@SP
+A=M-1
+D=M
+@ARG
+A=M
+M=D
+@ARG
+D=M+1
+@SP
+M=D
+@LCL
+AM=M-1
+D=M
+@THAT
+M=D
+@LCL
+AM=M-1
+D=M
+@THIS
+M=D
+@LCL
+AM=M-1
+D=M
+@ARG
+M=D
+@LCL
+AM=M-1
+D=M
+@LCL
+M=D
+@R13
+A=M
+0;JMP