aboutsummaryrefslogtreecommitdiff
path: root/projects/12/MemoryTest
diff options
context:
space:
mode:
authorYuchen Pei <me@ypei.me>2017-11-29 12:30:41 +0100
committerYuchen Pei <me@ypei.me>2017-11-29 12:30:41 +0100
commita000308104aab27c2dde9a306f1bc654b2db4806 (patch)
treeaecc628e14c1628b5714281437aba18680cdc27b /projects/12/MemoryTest
first commit
Diffstat (limited to 'projects/12/MemoryTest')
-rw-r--r--projects/12/MemoryTest/Main.jack42
-rw-r--r--projects/12/MemoryTest/MemoryTest.cmp2
-rw-r--r--projects/12/MemoryTest/MemoryTest.tst15
3 files changed, 59 insertions, 0 deletions
diff --git a/projects/12/MemoryTest/Main.jack b/projects/12/MemoryTest/Main.jack
new file mode 100644
index 0000000..77a53a9
--- /dev/null
+++ b/projects/12/MemoryTest/Main.jack
@@ -0,0 +1,42 @@
+// 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/MemoryTest/Main.jack
+
+/** Test program for the OS Memory class. */
+class Main {
+
+ /** Performs various memory manipulations. */
+ function void main() {
+ var int temp;
+ var Array a, b, c;
+
+ do Memory.poke(8000, 333); // RAM[8000] = 333
+ let temp = Memory.peek(8000);
+ do Memory.poke(8001, temp + 1); // RAM[8001] = 334
+
+ let a = Array.new(3); // uses Memory.alloc
+ let a[2] = 222;
+ do Memory.poke(8002, a[2]); // RAM[8002] = 222
+
+ let b = Array.new(3);
+ let b[1] = a[2] - 100;
+ do Memory.poke(8003, b[1]); // RAM[8003] = 122
+
+ let c = Array.new(500);
+ let c[499] = a[2] - b[1];
+ do Memory.poke(8004, c[499]); // RAM[8004] = 100
+
+ do a.dispose(); // uses Memory.deAlloc
+ do b.dispose();
+
+ let b = Array.new(3);
+ let b[0] = c[499] - 90;
+ do Memory.poke(8005, b[0]); // RAM[8005] = 10
+
+ do c.dispose();
+ do b.dispose();
+
+ return;
+ }
+}
diff --git a/projects/12/MemoryTest/MemoryTest.cmp b/projects/12/MemoryTest/MemoryTest.cmp
new file mode 100644
index 0000000..057958b
--- /dev/null
+++ b/projects/12/MemoryTest/MemoryTest.cmp
@@ -0,0 +1,2 @@
+|RAM[8000]|RAM[8001]|RAM[8002]|RAM[8003]|RAM[8004]|RAM[8005]|
+| 333 | 334 | 222 | 122 | 100 | 10 |
diff --git a/projects/12/MemoryTest/MemoryTest.tst b/projects/12/MemoryTest/MemoryTest.tst
new file mode 100644
index 0000000..1da34fd
--- /dev/null
+++ b/projects/12/MemoryTest/MemoryTest.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/MemoryTest/MemoryTest.tst
+
+load,
+output-file MemoryTest.out,
+compare-to MemoryTest.cmp,
+output-list RAM[8000]%D2.6.1 RAM[8001]%D2.6.1 RAM[8002]%D2.6.1 RAM[8003]%D2.6.1 RAM[8004]%D2.6.1 RAM[8005]%D2.6.1;
+
+repeat 1000000 {
+ vmstep;
+}
+
+output;