summaryrefslogtreecommitdiff
path: root/projects/12/ArrayTest
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/12/ArrayTest
parent9c0cb1d1c32724fc95ac9548e4f8d873d3adaccc (diff)
Projects, 01-06 completed
Diffstat (limited to 'projects/12/ArrayTest')
-rw-r--r--projects/12/ArrayTest/ArrayTest.cmp2
-rw-r--r--projects/12/ArrayTest/ArrayTest.tst15
-rw-r--r--projects/12/ArrayTest/Main.jack40
3 files changed, 57 insertions, 0 deletions
diff --git a/projects/12/ArrayTest/ArrayTest.cmp b/projects/12/ArrayTest/ArrayTest.cmp
new file mode 100644
index 0000000..d1a9798
--- /dev/null
+++ b/projects/12/ArrayTest/ArrayTest.cmp
@@ -0,0 +1,2 @@
+|RAM[8000]|RAM[8001]|RAM[8002]|RAM[8003]|
+| 222 | 122 | 100 | 10 |
diff --git a/projects/12/ArrayTest/ArrayTest.tst b/projects/12/ArrayTest/ArrayTest.tst
new file mode 100644
index 0000000..89934b9
--- /dev/null
+++ b/projects/12/ArrayTest/ArrayTest.tst
@@ -0,0 +1,15 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: projects/12/ArrayTest/ArrayTest.tst
+
+load,
+output-file ArrayTest.out,
+compare-to ArrayTest.cmp,
+output-list RAM[8000]%D2.6.1 RAM[8001]%D2.6.1 RAM[8002]%D2.6.1 RAM[8003]%D2.6.1;
+
+repeat 1000000 {
+ vmstep;
+}
+
+output;
diff --git a/projects/12/ArrayTest/Main.jack b/projects/12/ArrayTest/Main.jack
new file mode 100644
index 0000000..439770a
--- /dev/null
+++ b/projects/12/ArrayTest/Main.jack
@@ -0,0 +1,40 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: projects/12/ArrayTest/Main.jack
+
+/** Test program for the OS Array class. */
+class Main {
+
+ /** Performs several Array manipulations. */
+ function void main() {
+ var Array r; // stores test results
+ var Array a, b, c;
+
+ let r = 8000;
+
+ let a = Array.new(3);
+ let a[2] = 222;
+ let r[0] = a[2]; // RAM[8000] = 222
+
+ let b = Array.new(3);
+ let b[1] = a[2] - 100;
+ let r[1] = b[1]; // RAM[8001] = 122
+
+ let c = Array.new(500);
+ let c[499] = a[2] - b[1];
+ let r[2] = c[499]; // RAM[8002] = 100
+
+ do a.dispose();
+ do b.dispose();
+
+ let b = Array.new(3);
+ let b[0] = c[499] - 90;
+ let r[3] = b[0]; // RAM[8003] = 10
+
+ do c.dispose();
+ do b.dispose();
+
+ return;
+ }
+}