diff options
author | Frederick Yin <fkfd@fkfd.me> | 2022-08-24 08:34:12 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2022-08-24 08:34:12 +0800 |
commit | ca3e66d0cb0825285af7ea34a73355cf34e00a62 (patch) | |
tree | 55c7e15d68fb369e7c4b16b42b3687cf9f26a509 /projects | |
parent | a4587ecd741310585af0a667770be555a0f2f1f3 (diff) |
Output assembly files in project 08
Diffstat (limited to 'projects')
-rw-r--r-- | projects/08/FunctionCalls/FibonacciElement/FibonacciElement.asm | 362 | ||||
-rw-r--r-- | projects/08/FunctionCalls/NestedCall/NestedCall.asm | 501 | ||||
-rw-r--r-- | projects/08/FunctionCalls/SimpleFunction/SimpleFunction.asm | 115 | ||||
-rw-r--r-- | projects/08/FunctionCalls/StaticsTest/StaticsTest.asm | 539 | ||||
-rw-r--r-- | projects/08/ProgramFlow/BasicLoop/BasicLoop.asm | 125 | ||||
-rw-r--r-- | projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.asm | 214 |
6 files changed, 1856 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 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 diff --git a/projects/08/FunctionCalls/SimpleFunction/SimpleFunction.asm b/projects/08/FunctionCalls/SimpleFunction/SimpleFunction.asm new file mode 100644 index 0000000..174d7c3 --- /dev/null +++ b/projects/08/FunctionCalls/SimpleFunction/SimpleFunction.asm @@ -0,0 +1,115 @@ +// function SimpleFunction.test 2 +(SimpleFunction.test) +@SP +A=M +M=0 +@SP +AM=M+1 +M=0 +@SP +M=M+1 +// 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 +// add +@SP +AM=M-1 +D=M +A=A-1 +M=D+M +// not +@SP +A=M-1 +M=!M +// push argument 0 +@ARG +D=M +@0 +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 +// push argument 1 +@ARG +D=M +@1 +A=D+A +D=M +@SP +A=M +M=D +@SP +M=M+1 +// sub +@SP +AM=M-1 +D=M +A=A-1 +M=M-D +// return +@ARG +A=M +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 diff --git a/projects/08/FunctionCalls/StaticsTest/StaticsTest.asm b/projects/08/FunctionCalls/StaticsTest/StaticsTest.asm new file mode 100644 index 0000000..df3fe36 --- /dev/null +++ b/projects/08/FunctionCalls/StaticsTest/StaticsTest.asm @@ -0,0 +1,539 @@ +@256 +D=A +@SP +M=D +@StaticsTest$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 +(StaticsTest$ret_init) +// function Class2.set 0 +(Class2.set) +// push argument 0 +@ARG +D=M +@0 +A=D+A +D=M +@SP +A=M +M=D +@SP +M=M+1 +// pop static 0 +@SP +AM=M-1 +D=M +@Class2.0 +M=D +// push argument 1 +@ARG +D=M +@1 +A=D+A +D=M +@SP +A=M +M=D +@SP +M=M+1 +// pop static 1 +@SP +AM=M-1 +D=M +@Class2.1 +M=D +// push constant 0 +@0 +D=A +@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 +// function Class2.get 0 +(Class2.get) +// push static 0 +@Class2.0 +D=M +@SP +A=M +M=D +@SP +M=M+1 +// push static 1 +@Class2.1 +D=M +@SP +A=M +M=D +@SP +M=M+1 +// sub +@SP +AM=M-1 +D=M +A=A-1 +M=M-D +// 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 6 +@6 +D=A +@SP +A=M +M=D +@SP +M=M+1 +// push constant 8 +@8 +D=A +@SP +A=M +M=D +@SP +M=M+1 +// call Class1.set 2 +@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 +@7 +D=D-A +@ARG +M=D +@Class1.set +0;JMP +(Sys$ret.0) +// pop temp 0 +@SP +AM=M-1 +D=M +@5 +M=D +// push constant 23 +@23 +D=A +@SP +A=M +M=D +@SP +M=M+1 +// push constant 15 +@15 +D=A +@SP +A=M +M=D +@SP +M=M+1 +// call Class2.set 2 +@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 +@7 +D=D-A +@ARG +M=D +@Class2.set +0;JMP +(Sys$ret.1) +// pop temp 0 +@SP +AM=M-1 +D=M +@5 +M=D +// call Class1.get 0 +@Sys$ret.2 +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 +@Class1.get +0;JMP +(Sys$ret.2) +// call Class2.get 0 +@Sys$ret.3 +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 +@Class2.get +0;JMP +(Sys$ret.3) +// label WHILE +(Sys$WHILE) +// goto WHILE +@Sys$WHILE +0;JMP +// function Class1.set 0 +(Class1.set) +// push argument 0 +@ARG +D=M +@0 +A=D+A +D=M +@SP +A=M +M=D +@SP +M=M+1 +// pop static 0 +@SP +AM=M-1 +D=M +@Class1.0 +M=D +// push argument 1 +@ARG +D=M +@1 +A=D+A +D=M +@SP +A=M +M=D +@SP +M=M+1 +// pop static 1 +@SP +AM=M-1 +D=M +@Class1.1 +M=D +// push constant 0 +@0 +D=A +@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 +// function Class1.get 0 +(Class1.get) +// push static 0 +@Class1.0 +D=M +@SP +A=M +M=D +@SP +M=M+1 +// push static 1 +@Class1.1 +D=M +@SP +A=M +M=D +@SP +M=M+1 +// sub +@SP +AM=M-1 +D=M +A=A-1 +M=M-D +// 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 diff --git a/projects/08/ProgramFlow/BasicLoop/BasicLoop.asm b/projects/08/ProgramFlow/BasicLoop/BasicLoop.asm new file mode 100644 index 0000000..7ba9165 --- /dev/null +++ b/projects/08/ProgramFlow/BasicLoop/BasicLoop.asm @@ -0,0 +1,125 @@ +@0 +D=A +@SP +A=M +M=D +@SP +M=M+1 +@0 +D=A +@LCL +M=M+D +@SP +M=M-1 +A=M +D=M +@LCL +A=M +M=D +@0 +D=A +@LCL +M=M-D +(LOOP_START) +@ARG +D=M +@0 +A=D+A +D=M +@SP +A=M +M=D +@SP +M=M+1 +@LCL +D=M +@0 +A=D+A +D=M +@SP +A=M +M=D +@SP +M=M+1 +@SP +AM=M-1 +D=M +A=A-1 +M=D+M +@0 +D=A +@LCL +M=M+D +@SP +M=M-1 +A=M +D=M +@LCL +A=M +M=D +@0 +D=A +@LCL +M=M-D +@ARG +D=M +@0 +A=D+A +D=M +@SP +A=M +M=D +@SP +M=M+1 +@1 +D=A +@SP +A=M +M=D +@SP +M=M+1 +@SP +AM=M-1 +D=M +A=A-1 +M=M-D +@0 +D=A +@ARG +M=M+D +@SP +M=M-1 +A=M +D=M +@ARG +A=M +M=D +@0 +D=A +@ARG +M=M-D +@ARG +D=M +@0 +A=D+A +D=M +@SP +A=M +M=D +@SP +M=M+1 +@SP +AM=M-1 +D=M +@LOOP_START +D;JNE +@LCL +D=M +@0 +A=D+A +D=M +@SP +A=M +M=D +@SP +M=M+1 diff --git a/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.asm b/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.asm new file mode 100644 index 0000000..e84fad0 --- /dev/null +++ b/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.asm @@ -0,0 +1,214 @@ +@ARG +D=M +@1 +A=D+A +D=M +@SP +A=M +M=D +@SP +M=M+1 +@SP +AM=M-1 +D=M +@THAT +M=D +@0 +D=A +@SP +A=M +M=D +@SP +M=M+1 +@0 +D=A +@THAT +M=M+D +@SP +AM=M-1 +D=M +@THAT +A=M +M=D +@0 +D=A +@THAT +M=M-D +@1 +D=A +@SP +A=M +M=D +@SP +M=M+1 +@1 +D=A +@THAT +M=M+D +@SP +AM=M-1 +D=M +@THAT +A=M +M=D +@1 +D=A +@THAT +M=M-D +@ARG +D=M +@0 +A=D+A +D=M +@SP +A=M +M=D +@SP +M=M+1 +@2 +D=A +@SP +A=M +M=D +@SP +M=M+1 +@SP +AM=M-1 +D=M +A=A-1 +M=M-D +@0 +D=A +@ARG +M=M+D +@SP +AM=M-1 +D=M +@ARG +A=M +M=D +@0 +D=A +@ARG +M=M-D +(MAIN_LOOP_START) +@ARG +D=M +@0 +A=D+A +D=M +@SP +A=M +M=D +@SP +M=M+1 +@SP +AM=M-1 +D=M +@COMPUTE_ELEMENT +D;JNE +@END_PROGRAM +0;JMP +(COMPUTE_ELEMENT) +@THAT +D=M +@0 +A=D+A +D=M +@SP +A=M +M=D +@SP +M=M+1 +@THAT +D=M +@1 +A=D+A +D=M +@SP +A=M +M=D +@SP +M=M+1 +@SP +AM=M-1 +D=M +A=A-1 +M=D+M +@2 +D=A +@THAT +M=M+D +@SP +AM=M-1 +D=M +@THAT +A=M +M=D +@2 +D=A +@THAT +M=M-D +@THAT +D=M +@SP +A=M +M=D +@SP +M=M+1 +@1 +D=A +@SP +A=M +M=D +@SP +M=M+1 +@SP +AM=M-1 +D=M +A=A-1 +M=D+M +@SP +AM=M-1 +D=M +@THAT +M=D +@ARG +D=M +@0 +A=D+A +D=M +@SP +A=M +M=D +@SP +M=M+1 +@1 +D=A +@SP +A=M +M=D +@SP +M=M+1 +@SP +AM=M-1 +D=M +A=A-1 +M=M-D +@0 +D=A +@ARG +M=M+D +@SP +AM=M-1 +D=M +@ARG +A=M +M=D +@0 +D=A +@ARG +M=M-D +@MAIN_LOOP_START +0;JMP +(END_PROGRAM) |