aboutsummaryrefslogtreecommitdiff
path: root/projects/08/ProgramFlow
diff options
context:
space:
mode:
authorYuchen Pei <me@ypei.me>2018-01-05 13:10:41 +0100
committerYuchen Pei <me@ypei.me>2018-01-05 13:10:41 +0100
commit0b1849231f9fbd5b6ab44dfb8c831a3893996dfb (patch)
treee4e790377095a9cf5e74032f3aa2ae7e676b32ce /projects/08/ProgramFlow
parent040cf91851036a0216e7b5faea1f74ecd674db50 (diff)
partially finished project 08
- finished flow bit (will need to change the labels to f$label) - finished simplefunction test
Diffstat (limited to 'projects/08/ProgramFlow')
-rw-r--r--projects/08/ProgramFlow/BasicLoop/BasicLoop.asm140
-rw-r--r--projects/08/ProgramFlow/BasicLoop/BasicLoop.out2
-rw-r--r--projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.asm241
-rw-r--r--projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.out2
4 files changed, 385 insertions, 0 deletions
diff --git a/projects/08/ProgramFlow/BasicLoop/BasicLoop.asm b/projects/08/ProgramFlow/BasicLoop/BasicLoop.asm
new file mode 100644
index 0000000..62aa0cf
--- /dev/null
+++ b/projects/08/ProgramFlow/BasicLoop/BasicLoop.asm
@@ -0,0 +1,140 @@
+@256
+D=A
+@SP
+M=D
+@0
+D=A
+@SP
+A=M
+M=D
+@SP
+M=M+1
+@LCL
+D=M
+@0
+D=A+D
+@R13
+M=D
+@SP
+AM=M-1
+D=M
+@R13
+A=M
+M=D
+(LOOP_START)
+@ARG
+D=M
+@0
+D=A+D
+A=D
+D=M
+@SP
+A=M
+M=D
+@SP
+M=M+1
+@LCL
+D=M
+@0
+D=A+D
+A=D
+D=M
+@SP
+A=M
+M=D
+@SP
+M=M+1
+@SP
+AM=M-1
+D=M
+@SP
+AM=M-1
+D=M+D
+@SP
+A=M
+M=D
+@SP
+M=M+1
+@LCL
+D=M
+@0
+D=A+D
+@R13
+M=D
+@SP
+AM=M-1
+D=M
+@R13
+A=M
+M=D
+@ARG
+D=M
+@0
+D=A+D
+A=D
+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
+@SP
+AM=M-1
+D=M-D
+@SP
+A=M
+M=D
+@SP
+M=M+1
+@ARG
+D=M
+@0
+D=A+D
+@R13
+M=D
+@SP
+AM=M-1
+D=M
+@R13
+A=M
+M=D
+@ARG
+D=M
+@0
+D=A+D
+A=D
+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
+D=A+D
+A=D
+D=M
+@SP
+A=M
+M=D
+@SP
+M=M+1
+(END)
+@END
+0;JMP \ No newline at end of file
diff --git a/projects/08/ProgramFlow/BasicLoop/BasicLoop.out b/projects/08/ProgramFlow/BasicLoop/BasicLoop.out
new file mode 100644
index 0000000..1786c7c
--- /dev/null
+++ b/projects/08/ProgramFlow/BasicLoop/BasicLoop.out
@@ -0,0 +1,2 @@
+| RAM[0] |RAM[256]|
+| 257 | 6 |
diff --git a/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.asm b/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.asm
new file mode 100644
index 0000000..68a4c8e
--- /dev/null
+++ b/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.asm
@@ -0,0 +1,241 @@
+@256
+D=A
+@SP
+M=D
+@ARG
+D=M
+@1
+D=A+D
+A=D
+D=M
+@SP
+A=M
+M=D
+@SP
+M=M+1
+@SP
+AM=M-1
+D=M
+@4
+M=D
+@0
+D=A
+@SP
+A=M
+M=D
+@SP
+M=M+1
+@THAT
+D=M
+@0
+D=A+D
+@R13
+M=D
+@SP
+AM=M-1
+D=M
+@R13
+A=M
+M=D
+@1
+D=A
+@SP
+A=M
+M=D
+@SP
+M=M+1
+@THAT
+D=M
+@1
+D=A+D
+@R13
+M=D
+@SP
+AM=M-1
+D=M
+@R13
+A=M
+M=D
+@ARG
+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P
+(END_PROGRAM)
+(END)
+@END
+0;JMP \ No newline at end of file
diff --git a/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.out b/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.out
new file mode 100644
index 0000000..304e7c1
--- /dev/null
+++ b/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.out
@@ -0,0 +1,2 @@
+|RAM[3000]|RAM[3001]|RAM[3002]|RAM[3003]|RAM[3004]|RAM[3005]|
+| 0 | 1 | 1 | 2 | 3 | 5 |