summaryrefslogtreecommitdiff
path: root/projects/08/FunctionCalls/FibonacciElement
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2022-08-24 08:34:12 +0800
committerFrederick Yin <fkfd@fkfd.me>2022-08-24 08:34:12 +0800
commitca3e66d0cb0825285af7ea34a73355cf34e00a62 (patch)
tree55c7e15d68fb369e7c4b16b42b3687cf9f26a509 /projects/08/FunctionCalls/FibonacciElement
parenta4587ecd741310585af0a667770be555a0f2f1f3 (diff)
Output assembly files in project 08
Diffstat (limited to 'projects/08/FunctionCalls/FibonacciElement')
-rw-r--r--projects/08/FunctionCalls/FibonacciElement/FibonacciElement.asm362
1 files changed, 362 insertions, 0 deletions
diff --git a/projects/08/FunctionCalls/FibonacciElement/FibonacciElement.asm b/projects/08/FunctionCalls/FibonacciElement/FibonacciElement.asm
new file mode 100644
index 0000000..e20efdd
--- /dev/null
+++ b/projects/08/FunctionCalls/FibonacciElement/FibonacciElement.asm
@@ -0,0 +1,362 @@
+@256
+D=A
+@SP
+M=D
+@FibonacciElement$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
+(FibonacciElement$ret_init)
+// function Main.fibonacci 0
+(Main.fibonacci)
+// push argument 0
+@ARG
+D=M
+@0
+A=D+A
+D=M
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// push constant 2
+@2
+D=A
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// lt
+@SP
+AM=M-1
+D=M
+A=A-1
+D=M-D
+M=0
+@END_LT_0
+D;JGE
+@SP
+A=M-1
+M=-1
+(END_LT_0)
+// if-goto IF_TRUE
+@SP
+AM=M-1
+D=M
+@Main$IF_TRUE
+D;JNE
+// goto IF_FALSE
+@Main$IF_FALSE
+0;JMP
+// label IF_TRUE
+(Main$IF_TRUE)
+// push argument 0
+@ARG
+D=M
+@0
+A=D+A
+D=M
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// 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
+// label IF_FALSE
+(Main$IF_FALSE)
+// push argument 0
+@ARG
+D=M
+@0
+A=D+A
+D=M
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// push constant 2
+@2
+D=A
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// sub
+@SP
+AM=M-1
+D=M
+A=A-1
+M=M-D
+// call Main.fibonacci 1
+@Main$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
+@6
+D=D-A
+@ARG
+M=D
+@Main.fibonacci
+0;JMP
+(Main$ret.0)
+// push argument 0
+@ARG
+D=M
+@0
+A=D+A
+D=M
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// push constant 1
+@1
+D=A
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// sub
+@SP
+AM=M-1
+D=M
+A=A-1
+M=M-D
+// call Main.fibonacci 1
+@Main$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
+@Main.fibonacci
+0;JMP
+(Main$ret.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
+// function Sys.init 0
+(Sys.init)
+// push constant 4
+@4
+D=A
+@SP
+A=M
+M=D
+@SP
+M=M+1
+// call Main.fibonacci 1
+@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
+@6
+D=D-A
+@ARG
+M=D
+@Main.fibonacci
+0;JMP
+(Sys$ret.0)
+// label WHILE
+(Sys$WHILE)
+// goto WHILE
+@Sys$WHILE
+0;JMP