diff --git a/original/projects/0/file.txt b/original/projects/0/file.txt
new file mode 100644
index 0000000..119034e
--- /dev/null
+++ b/original/projects/0/file.txt
@@ -0,0 +1,7 @@
+There is no need to modify the contents of this file.
+All you have to do is submit it as is, following the
+Project 0 guidelines in your course website.
+
+It is possible that the Nand to Tetris course that
+you are taking does not require a project 0 submission.
+That's OK.
diff --git a/original/projects/1/And.cmp b/original/projects/1/And.cmp
new file mode 100644
index 0000000..7a3c7de
--- /dev/null
+++ b/original/projects/1/And.cmp
@@ -0,0 +1,5 @@
+| a | b |out|
+| 0 | 0 | 0 |
+| 0 | 1 | 0 |
+| 1 | 0 | 0 |
+| 1 | 1 | 1 |
diff --git a/original/projects/1/And.hdl b/original/projects/1/And.hdl
new file mode 100644
index 0000000..658ff73
--- /dev/null
+++ b/original/projects/1/And.hdl
@@ -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/1/And.hdl
+/**
+ * And gate:
+ * if (a and b) out = 1, else out = 0
+ */
+CHIP And {
+ IN a, b;
+ OUT out;
+
+ PARTS:
+ //// Replace this comment with your code.
+}
\ No newline at end of file
diff --git a/original/projects/1/And.tst b/original/projects/1/And.tst
new file mode 100644
index 0000000..92d93ad
--- /dev/null
+++ b/original/projects/1/And.tst
@@ -0,0 +1,29 @@
+// 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/1/And.tst
+
+load And.hdl,
+output-file And.out,
+compare-to And.cmp,
+output-list a b out;
+
+set a 0,
+set b 0,
+eval,
+output;
+
+set a 0,
+set b 1,
+eval,
+output;
+
+set a 1,
+set b 0,
+eval,
+output;
+
+set a 1,
+set b 1,
+eval,
+output;
diff --git a/original/projects/1/And16.cmp b/original/projects/1/And16.cmp
new file mode 100644
index 0000000..fb8dbfc
--- /dev/null
+++ b/original/projects/1/And16.cmp
@@ -0,0 +1,7 @@
+| a | b | out |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 |
+| 0000000000000000 | 1111111111111111 | 0000000000000000 |
+| 1111111111111111 | 1111111111111111 | 1111111111111111 |
+| 1010101010101010 | 0101010101010101 | 0000000000000000 |
+| 0011110011000011 | 0000111111110000 | 0000110011000000 |
+| 0001001000110100 | 1001100001110110 | 0001000000110100 |
diff --git a/original/projects/1/And16.hdl b/original/projects/1/And16.hdl
new file mode 100644
index 0000000..dfd56bc
--- /dev/null
+++ b/original/projects/1/And16.hdl
@@ -0,0 +1,16 @@
+// 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/1/And16.hdl
+/**
+ * 16-bit And gate:
+ * for i = 0, ..., 15:
+ * out[i] = a[i] And b[i]
+ */
+CHIP And16 {
+ IN a[16], b[16];
+ OUT out[16];
+
+ PARTS:
+ //// Replace this comment with your code.
+}
\ No newline at end of file
diff --git a/original/projects/1/And16.tst b/original/projects/1/And16.tst
new file mode 100644
index 0000000..52a7884
--- /dev/null
+++ b/original/projects/1/And16.tst
@@ -0,0 +1,39 @@
+// 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/1/And16.tst
+
+load And16.hdl,
+output-file And16.out,
+compare-to And16.cmp,
+output-list a%B1.16.1 b%B1.16.1 out%B1.16.1;
+
+set a %B0000000000000000,
+set b %B0000000000000000,
+eval,
+output;
+
+set a %B0000000000000000,
+set b %B1111111111111111,
+eval,
+output;
+
+set a %B1111111111111111,
+set b %B1111111111111111,
+eval,
+output;
+
+set a %B1010101010101010,
+set b %B0101010101010101,
+eval,
+output;
+
+set a %B0011110011000011,
+set b %B0000111111110000,
+eval,
+output;
+
+set a %B0001001000110100,
+set b %B1001100001110110,
+eval,
+output;
\ No newline at end of file
diff --git a/original/projects/1/DMux.cmp b/original/projects/1/DMux.cmp
new file mode 100644
index 0000000..5b65adb
--- /dev/null
+++ b/original/projects/1/DMux.cmp
@@ -0,0 +1,5 @@
+|in |sel| a | b |
+| 0 | 0 | 0 | 0 |
+| 0 | 1 | 0 | 0 |
+| 1 | 0 | 1 | 0 |
+| 1 | 1 | 0 | 1 |
diff --git a/original/projects/1/DMux.hdl b/original/projects/1/DMux.hdl
new file mode 100644
index 0000000..9dbdfb9
--- /dev/null
+++ b/original/projects/1/DMux.hdl
@@ -0,0 +1,16 @@
+// 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/1/DMux.hdl
+/**
+ * Demultiplexor:
+ * [a, b] = [in, 0] if sel = 0
+ * [0, in] if sel = 1
+ */
+CHIP DMux {
+ IN in, sel;
+ OUT a, b;
+
+ PARTS:
+ //// Replace this comment with your code.
+}
diff --git a/original/projects/1/DMux.tst b/original/projects/1/DMux.tst
new file mode 100644
index 0000000..cebda16
--- /dev/null
+++ b/original/projects/1/DMux.tst
@@ -0,0 +1,27 @@
+// 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/1/DMux.tst
+
+load DMux.hdl,
+output-file DMux.out,
+compare-to DMux.cmp,
+output-list in sel a b;
+
+set in 0,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set in 1,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
diff --git a/original/projects/1/DMux4Way.cmp b/original/projects/1/DMux4Way.cmp
new file mode 100644
index 0000000..7734e2a
--- /dev/null
+++ b/original/projects/1/DMux4Way.cmp
@@ -0,0 +1,9 @@
+|in | sel | a | b | c | d |
+| 0 | 00 | 0 | 0 | 0 | 0 |
+| 0 | 01 | 0 | 0 | 0 | 0 |
+| 0 | 10 | 0 | 0 | 0 | 0 |
+| 0 | 11 | 0 | 0 | 0 | 0 |
+| 1 | 00 | 1 | 0 | 0 | 0 |
+| 1 | 01 | 0 | 1 | 0 | 0 |
+| 1 | 10 | 0 | 0 | 1 | 0 |
+| 1 | 11 | 0 | 0 | 0 | 1 |
diff --git a/original/projects/1/DMux4Way.hdl b/original/projects/1/DMux4Way.hdl
new file mode 100644
index 0000000..399729e
--- /dev/null
+++ b/original/projects/1/DMux4Way.hdl
@@ -0,0 +1,18 @@
+// 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/1/DMux4Way.hdl
+/**
+ * 4-way demultiplexor:
+ * [a, b, c, d] = [in, 0, 0, 0] if sel = 00
+ * [0, in, 0, 0] if sel = 01
+ * [0, 0, in, 0] if sel = 10
+ * [0, 0, 0, in] if sel = 11
+ */
+CHIP DMux4Way {
+ IN in, sel[2];
+ OUT a, b, c, d;
+
+ PARTS:
+ //// Replace this comment with your code.
+}
\ No newline at end of file
diff --git a/original/projects/1/DMux4Way.tst b/original/projects/1/DMux4Way.tst
new file mode 100644
index 0000000..4f5b6a4
--- /dev/null
+++ b/original/projects/1/DMux4Way.tst
@@ -0,0 +1,43 @@
+// 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/1/DMux4Way.tst
+
+load DMux4Way.hdl,
+output-file DMux4Way.out,
+compare-to DMux4Way.cmp,
+output-list in sel%B2.2.2 a b c d;
+
+set in 0,
+set sel %B00,
+eval,
+output;
+
+set sel %B01,
+eval,
+output;
+
+set sel %B10,
+eval,
+output;
+
+set sel %B11,
+eval,
+output;
+
+set in 1,
+set sel %B00,
+eval,
+output;
+
+set sel %B01,
+eval,
+output;
+
+set sel %B10,
+eval,
+output;
+
+set sel %B11,
+eval,
+output;
diff --git a/original/projects/1/DMux8Way.cmp b/original/projects/1/DMux8Way.cmp
new file mode 100644
index 0000000..e1b2e74
--- /dev/null
+++ b/original/projects/1/DMux8Way.cmp
@@ -0,0 +1,17 @@
+|in | sel | a | b | c | d | e | f | g | h |
+| 0 | 000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+| 0 | 001 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+| 0 | 010 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+| 0 | 011 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+| 0 | 100 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+| 0 | 101 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+| 0 | 110 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+| 0 | 111 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+| 1 | 000 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+| 1 | 001 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
+| 1 | 010 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
+| 1 | 011 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
+| 1 | 100 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
+| 1 | 101 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
+| 1 | 110 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
+| 1 | 111 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
diff --git a/original/projects/1/DMux8Way.hdl b/original/projects/1/DMux8Way.hdl
new file mode 100644
index 0000000..e3d3dca
--- /dev/null
+++ b/original/projects/1/DMux8Way.hdl
@@ -0,0 +1,22 @@
+// 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/1/DMux8Way.hdl
+/**
+ * 8-way demultiplexor:
+ * [a, b, c, d, e, f, g, h] = [in, 0, 0, 0, 0, 0, 0, 0] if sel = 000
+ * [0, in, 0, 0, 0, 0, 0, 0] if sel = 001
+ * [0, 0, in, 0, 0, 0, 0, 0] if sel = 010
+ * [0, 0, 0, in, 0, 0, 0, 0] if sel = 011
+ * [0, 0, 0, 0, in, 0, 0, 0] if sel = 100
+ * [0, 0, 0, 0, 0, in, 0, 0] if sel = 101
+ * [0, 0, 0, 0, 0, 0, in, 0] if sel = 110
+ * [0, 0, 0, 0, 0, 0, 0, in] if sel = 111
+ */
+CHIP DMux8Way {
+ IN in, sel[3];
+ OUT a, b, c, d, e, f, g, h;
+
+ PARTS:
+ //// Replace this comment with your code.
+}
diff --git a/original/projects/1/DMux8Way.tst b/original/projects/1/DMux8Way.tst
new file mode 100644
index 0000000..ec1fc9b
--- /dev/null
+++ b/original/projects/1/DMux8Way.tst
@@ -0,0 +1,75 @@
+// 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/1/DMux8Way.tst
+
+load DMux8Way.hdl,
+output-file DMux8Way.out,
+compare-to DMux8Way.cmp,
+output-list in sel%B2.3.2 a b c d e f g h;
+
+set in 0,
+set sel %B000,
+eval,
+output;
+
+set sel %B001,
+eval,
+output;
+
+set sel %B010,
+eval,
+output;
+
+set sel %B011,
+eval,
+output;
+
+set sel %B100,
+eval,
+output;
+
+set sel %B101,
+eval,
+output;
+
+set sel %B110,
+eval,
+output;
+
+set sel %B111,
+eval,
+output;
+
+set in 1,
+set sel %B000,
+eval,
+output;
+
+set sel %B001,
+eval,
+output;
+
+set sel %B010,
+eval,
+output;
+
+set sel %B011,
+eval,
+output;
+
+set sel %B100,
+eval,
+output;
+
+set sel %B101,
+eval,
+output;
+
+set sel %B110,
+eval,
+output;
+
+set sel %B111,
+eval,
+output;
diff --git a/original/projects/1/Mux.cmp b/original/projects/1/Mux.cmp
new file mode 100644
index 0000000..eb25f2e
--- /dev/null
+++ b/original/projects/1/Mux.cmp
@@ -0,0 +1,9 @@
+| a | b |sel|out|
+| 0 | 0 | 0 | 0 |
+| 0 | 0 | 1 | 0 |
+| 0 | 1 | 0 | 0 |
+| 0 | 1 | 1 | 1 |
+| 1 | 0 | 0 | 1 |
+| 1 | 0 | 1 | 0 |
+| 1 | 1 | 0 | 1 |
+| 1 | 1 | 1 | 1 |
diff --git a/original/projects/1/Mux.hdl b/original/projects/1/Mux.hdl
new file mode 100644
index 0000000..9f9e720
--- /dev/null
+++ b/original/projects/1/Mux.hdl
@@ -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/1/Mux.hdl
+/**
+ * Multiplexor:
+ * if (sel = 0) out = a, else out = b
+ */
+CHIP Mux {
+ IN a, b, sel;
+ OUT out;
+
+ PARTS:
+ //// Replace this comment with your code.
+}
\ No newline at end of file
diff --git a/original/projects/1/Mux.tst b/original/projects/1/Mux.tst
new file mode 100644
index 0000000..8e5c43e
--- /dev/null
+++ b/original/projects/1/Mux.tst
@@ -0,0 +1,49 @@
+// 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/1/Mux.tst
+
+load Mux.hdl,
+output-file Mux.out,
+compare-to Mux.cmp,
+output-list a b sel out;
+
+set a 0,
+set b 0,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set a 0,
+set b 1,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set a 1,
+set b 0,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set a 1,
+set b 1,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
diff --git a/original/projects/1/Mux16.cmp b/original/projects/1/Mux16.cmp
new file mode 100644
index 0000000..80b6ece
--- /dev/null
+++ b/original/projects/1/Mux16.cmp
@@ -0,0 +1,9 @@
+| a | b |sel| out |
+| 0000000000000000 | 0000000000000000 | 0 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 1 | 0000000000000000 |
+| 0000000000000000 | 0001001000110100 | 0 | 0000000000000000 |
+| 0000000000000000 | 0001001000110100 | 1 | 0001001000110100 |
+| 1001100001110110 | 0000000000000000 | 0 | 1001100001110110 |
+| 1001100001110110 | 0000000000000000 | 1 | 0000000000000000 |
+| 1010101010101010 | 0101010101010101 | 0 | 1010101010101010 |
+| 1010101010101010 | 0101010101010101 | 1 | 0101010101010101 |
diff --git a/original/projects/1/Mux16.hdl b/original/projects/1/Mux16.hdl
new file mode 100644
index 0000000..3d2bccf
--- /dev/null
+++ b/original/projects/1/Mux16.hdl
@@ -0,0 +1,16 @@
+// 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/1/Mux16.hdl
+/**
+ * 16-bit multiplexor:
+ * for i = 0, ..., 15:
+ * if (sel = 0) out[i] = a[i], else out[i] = b[i]
+ */
+CHIP Mux16 {
+ IN a[16], b[16], sel;
+ OUT out[16];
+
+ PARTS:
+ //// Replace this comment with your code.
+}
diff --git a/original/projects/1/Mux16.tst b/original/projects/1/Mux16.tst
new file mode 100644
index 0000000..2a1ae88
--- /dev/null
+++ b/original/projects/1/Mux16.tst
@@ -0,0 +1,49 @@
+// 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/1/Mux16.tst
+
+load Mux16.hdl,
+output-file Mux16.out,
+compare-to Mux16.cmp,
+output-list a%B1.16.1 b%B1.16.1 sel out%B1.16.1;
+
+set a 0,
+set b 0,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set a %B0000000000000000,
+set b %B0001001000110100,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set a %B1001100001110110,
+set b %B0000000000000000,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set a %B1010101010101010,
+set b %B0101010101010101,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
\ No newline at end of file
diff --git a/original/projects/1/Mux4Way16.cmp b/original/projects/1/Mux4Way16.cmp
new file mode 100644
index 0000000..659176d
--- /dev/null
+++ b/original/projects/1/Mux4Way16.cmp
@@ -0,0 +1,9 @@
+| a | b | c | d | sel | out |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 00 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 01 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 10 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 11 | 0000000000000000 |
+| 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 00 | 0001001000110100 |
+| 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 01 | 1001100001110110 |
+| 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 10 | 1010101010101010 |
+| 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 11 | 0101010101010101 |
diff --git a/original/projects/1/Mux4Way16.hdl b/original/projects/1/Mux4Way16.hdl
new file mode 100644
index 0000000..8d6b645
--- /dev/null
+++ b/original/projects/1/Mux4Way16.hdl
@@ -0,0 +1,18 @@
+// 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/1/Mux4Way16.hdl
+/**
+ * 4-way 16-bit multiplexor:
+ * out = a if sel = 00
+ * b if sel = 01
+ * c if sel = 10
+ * d if sel = 11
+ */
+CHIP Mux4Way16 {
+ IN a[16], b[16], c[16], d[16], sel[2];
+ OUT out[16];
+
+ PARTS:
+ //// Replace this comment with your code.
+}
\ No newline at end of file
diff --git a/original/projects/1/Mux4Way16.tst b/original/projects/1/Mux4Way16.tst
new file mode 100644
index 0000000..0ff852f
--- /dev/null
+++ b/original/projects/1/Mux4Way16.tst
@@ -0,0 +1,49 @@
+// 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/1/Mux4Way16.tst
+
+load Mux4Way16.hdl,
+output-file Mux4Way16.out,
+compare-to Mux4Way16.cmp,
+output-list a%B1.16.1 b%B1.16.1 c%B1.16.1 d%B1.16.1 sel%B2.2.2 out%B1.16.1;
+
+set a 0,
+set b 0,
+set c 0,
+set d 0,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set sel 2,
+eval,
+output;
+
+set sel 3,
+eval,
+output;
+
+set a %B0001001000110100,
+set b %B1001100001110110,
+set c %B1010101010101010,
+set d %B0101010101010101,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set sel 2,
+eval,
+output;
+
+set sel 3,
+eval,
+output;
diff --git a/original/projects/1/Mux8Way16.cmp b/original/projects/1/Mux8Way16.cmp
new file mode 100644
index 0000000..11ff518
--- /dev/null
+++ b/original/projects/1/Mux8Way16.cmp
@@ -0,0 +1,17 @@
+| a | b | c | d | e | f | g | h | sel | out |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 000 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 001 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 010 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 011 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 100 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 101 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 110 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 111 | 0000000000000000 |
+| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 000 | 0001001000110100 |
+| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 001 | 0010001101000101 |
+| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 010 | 0011010001010110 |
+| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 011 | 0100010101100111 |
+| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 100 | 0101011001111000 |
+| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 101 | 0110011110001001 |
+| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 110 | 0111100010011010 |
+| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 111 | 1000100110101011 |
diff --git a/original/projects/1/Mux8Way16.hdl b/original/projects/1/Mux8Way16.hdl
new file mode 100644
index 0000000..4fe712e
--- /dev/null
+++ b/original/projects/1/Mux8Way16.hdl
@@ -0,0 +1,24 @@
+// 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/1/Mux8Way16.hdl
+/**
+ * 8-way 16-bit multiplexor:
+ * out = a if sel = 000
+ * b if sel = 001
+ * c if sel = 010
+ * d if sel = 011
+ * e if sel = 100
+ * f if sel = 101
+ * g if sel = 110
+ * h if sel = 111
+ */
+CHIP Mux8Way16 {
+ IN a[16], b[16], c[16], d[16],
+ e[16], f[16], g[16], h[16],
+ sel[3];
+ OUT out[16];
+
+ PARTS:
+ //// Replace this comment with your code.
+}
diff --git a/original/projects/1/Mux8Way16.tst b/original/projects/1/Mux8Way16.tst
new file mode 100644
index 0000000..aced052
--- /dev/null
+++ b/original/projects/1/Mux8Way16.tst
@@ -0,0 +1,89 @@
+// 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/1/Mux8Way16.tst
+
+load Mux8Way16.hdl,
+output-file Mux8Way16.out,
+compare-to Mux8Way16.cmp,
+output-list a%B1.16.1 b%B1.16.1 c%B1.16.1 d%B1.16.1 e%B1.16.1 f%B1.16.1 g%B1.16.1 h%B1.16.1 sel%B2.3.2 out%B1.16.1;
+
+set a 0,
+set b 0,
+set c 0,
+set d 0,
+set e 0,
+set f 0,
+set g 0,
+set h 0,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set sel 2,
+eval,
+output;
+
+set sel 3,
+eval,
+output;
+
+set sel 4,
+eval,
+output;
+
+set sel 5,
+eval,
+output;
+
+set sel 6,
+eval,
+output;
+
+set sel 7,
+eval,
+output;
+
+set a %B0001001000110100,
+set b %B0010001101000101,
+set c %B0011010001010110,
+set d %B0100010101100111,
+set e %B0101011001111000,
+set f %B0110011110001001,
+set g %B0111100010011010,
+set h %B1000100110101011,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set sel 2,
+eval,
+output;
+
+set sel 3,
+eval,
+output;
+
+set sel 4,
+eval,
+output;
+
+set sel 5,
+eval,
+output;
+
+set sel 6,
+eval,
+output;
+
+set sel 7,
+eval,
+output;
diff --git a/original/projects/1/Not.cmp b/original/projects/1/Not.cmp
new file mode 100644
index 0000000..9b48db2
--- /dev/null
+++ b/original/projects/1/Not.cmp
@@ -0,0 +1,3 @@
+|in |out|
+| 0 | 1 |
+| 1 | 0 |
diff --git a/original/projects/1/Not.hdl b/original/projects/1/Not.hdl
new file mode 100644
index 0000000..9ce0063
--- /dev/null
+++ b/original/projects/1/Not.hdl
@@ -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/1/Not.hdl
+/**
+ * Not gate:
+ * if (in) out = 0, else out = 1
+ */
+CHIP Not {
+ IN in;
+ OUT out;
+
+ PARTS:
+ //// Replace this comment with your code.
+}
diff --git a/original/projects/1/Not.tst b/original/projects/1/Not.tst
new file mode 100644
index 0000000..ed0c8f9
--- /dev/null
+++ b/original/projects/1/Not.tst
@@ -0,0 +1,17 @@
+// 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/1/Not.tst
+
+load Not.hdl,
+output-file Not.out,
+compare-to Not.cmp,
+output-list in out;
+
+set in 0,
+eval,
+output;
+
+set in 1,
+eval,
+output;
diff --git a/original/projects/1/Not16.cmp b/original/projects/1/Not16.cmp
new file mode 100644
index 0000000..ae2ad1d
--- /dev/null
+++ b/original/projects/1/Not16.cmp
@@ -0,0 +1,6 @@
+| in | out |
+| 0000000000000000 | 1111111111111111 |
+| 1111111111111111 | 0000000000000000 |
+| 1010101010101010 | 0101010101010101 |
+| 0011110011000011 | 1100001100111100 |
+| 0001001000110100 | 1110110111001011 |
diff --git a/original/projects/1/Not16.hdl b/original/projects/1/Not16.hdl
new file mode 100644
index 0000000..e88babf
--- /dev/null
+++ b/original/projects/1/Not16.hdl
@@ -0,0 +1,16 @@
+// 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/1/Not16.hdl
+/**
+ * 16-bit Not gate:
+ * for i = 0, ..., 15:
+ * out[i] = Not(a[i])
+ */
+CHIP Not16 {
+ IN in[16];
+ OUT out[16];
+
+ PARTS:
+ //// Replace this comment with your code.
+}
\ No newline at end of file
diff --git a/original/projects/1/Not16.tst b/original/projects/1/Not16.tst
new file mode 100644
index 0000000..4bde067
--- /dev/null
+++ b/original/projects/1/Not16.tst
@@ -0,0 +1,29 @@
+// 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/1/Not16.tst
+
+load Not16.hdl,
+output-file Not16.out,
+compare-to Not16.cmp,
+output-list in%B1.16.1 out%B1.16.1;
+
+set in %B0000000000000000,
+eval,
+output;
+
+set in %B1111111111111111,
+eval,
+output;
+
+set in %B1010101010101010,
+eval,
+output;
+
+set in %B0011110011000011,
+eval,
+output;
+
+set in %B0001001000110100,
+eval,
+output;
\ No newline at end of file
diff --git a/original/projects/1/Or.cmp b/original/projects/1/Or.cmp
new file mode 100644
index 0000000..11f9d64
--- /dev/null
+++ b/original/projects/1/Or.cmp
@@ -0,0 +1,5 @@
+| a | b |out|
+| 0 | 0 | 0 |
+| 0 | 1 | 1 |
+| 1 | 0 | 1 |
+| 1 | 1 | 1 |
diff --git a/original/projects/1/Or.hdl b/original/projects/1/Or.hdl
new file mode 100644
index 0000000..1aa2dd7
--- /dev/null
+++ b/original/projects/1/Or.hdl
@@ -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/1/Or.hdl
+/**
+ * Or gate:
+ * if (a or b) out = 1, else out = 0
+ */
+CHIP Or {
+ IN a, b;
+ OUT out;
+
+ PARTS:
+ //// Replace this comment with your code.
+}
diff --git a/original/projects/1/Or.tst b/original/projects/1/Or.tst
new file mode 100644
index 0000000..65f07ad
--- /dev/null
+++ b/original/projects/1/Or.tst
@@ -0,0 +1,29 @@
+// 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/1/Or.tst
+
+load Or.hdl,
+output-file Or.out,
+compare-to Or.cmp,
+output-list a b out;
+
+set a 0,
+set b 0,
+eval,
+output;
+
+set a 0,
+set b 1,
+eval,
+output;
+
+set a 1,
+set b 0,
+eval,
+output;
+
+set a 1,
+set b 1,
+eval,
+output;
diff --git a/original/projects/1/Or16.cmp b/original/projects/1/Or16.cmp
new file mode 100644
index 0000000..8664afe
--- /dev/null
+++ b/original/projects/1/Or16.cmp
@@ -0,0 +1,7 @@
+| a | b | out |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 |
+| 0000000000000000 | 1111111111111111 | 1111111111111111 |
+| 1111111111111111 | 1111111111111111 | 1111111111111111 |
+| 1010101010101010 | 0101010101010101 | 1111111111111111 |
+| 0011110011000011 | 0000111111110000 | 0011111111110011 |
+| 0001001000110100 | 1001100001110110 | 1001101001110110 |
diff --git a/original/projects/1/Or16.hdl b/original/projects/1/Or16.hdl
new file mode 100644
index 0000000..4337602
--- /dev/null
+++ b/original/projects/1/Or16.hdl
@@ -0,0 +1,16 @@
+// 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/1/Or16.hdl
+/**
+ * 16-bit Or gate:
+ * for i = 0, ..., 15:
+ * out[i] = a[i] Or b[i]
+ */
+CHIP Or16 {
+ IN a[16], b[16];
+ OUT out[16];
+
+ PARTS:
+ //// Replace this comment with your code.
+}
\ No newline at end of file
diff --git a/original/projects/1/Or16.tst b/original/projects/1/Or16.tst
new file mode 100644
index 0000000..a2e221a
--- /dev/null
+++ b/original/projects/1/Or16.tst
@@ -0,0 +1,39 @@
+// 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/1/Or16.tst
+
+load Or16.hdl,
+output-file Or16.out,
+compare-to Or16.cmp,
+output-list a%B1.16.1 b%B1.16.1 out%B1.16.1;
+
+set a %B0000000000000000,
+set b %B0000000000000000,
+eval,
+output;
+
+set a %B0000000000000000,
+set b %B1111111111111111,
+eval,
+output;
+
+set a %B1111111111111111,
+set b %B1111111111111111,
+eval,
+output;
+
+set a %B1010101010101010,
+set b %B0101010101010101,
+eval,
+output;
+
+set a %B0011110011000011,
+set b %B0000111111110000,
+eval,
+output;
+
+set a %B0001001000110100,
+set b %B1001100001110110,
+eval,
+output;
\ No newline at end of file
diff --git a/original/projects/1/Or8Way.cmp b/original/projects/1/Or8Way.cmp
new file mode 100644
index 0000000..a1d2c4a
--- /dev/null
+++ b/original/projects/1/Or8Way.cmp
@@ -0,0 +1,6 @@
+| in |out|
+| 00000000 | 0 |
+| 11111111 | 1 |
+| 00010000 | 1 |
+| 00000001 | 1 |
+| 00100110 | 1 |
diff --git a/original/projects/1/Or8Way.hdl b/original/projects/1/Or8Way.hdl
new file mode 100644
index 0000000..6eff8a2
--- /dev/null
+++ b/original/projects/1/Or8Way.hdl
@@ -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/1/Or8Way.hdl
+/**
+ * 8-way Or gate:
+ * out = in[0] Or in[1] Or ... Or in[7]
+ */
+CHIP Or8Way {
+ IN in[8];
+ OUT out;
+
+ PARTS:
+ //// Replace this comment with your code.
+}
\ No newline at end of file
diff --git a/original/projects/1/Or8Way.tst b/original/projects/1/Or8Way.tst
new file mode 100644
index 0000000..e8e7e37
--- /dev/null
+++ b/original/projects/1/Or8Way.tst
@@ -0,0 +1,29 @@
+// 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/1/Or8Way.tst
+
+load Or8Way.hdl,
+output-file Or8Way.out,
+compare-to Or8Way.cmp,
+output-list in%B2.8.2 out;
+
+set in %B00000000,
+eval,
+output;
+
+set in %B11111111,
+eval,
+output;
+
+set in %B00010000,
+eval,
+output;
+
+set in %B00000001,
+eval,
+output;
+
+set in %B00100110,
+eval,
+output;
\ No newline at end of file
diff --git a/original/projects/1/Xor.cmp b/original/projects/1/Xor.cmp
new file mode 100644
index 0000000..3737173
--- /dev/null
+++ b/original/projects/1/Xor.cmp
@@ -0,0 +1,5 @@
+| a | b |out|
+| 0 | 0 | 0 |
+| 0 | 1 | 1 |
+| 1 | 0 | 1 |
+| 1 | 1 | 0 |
diff --git a/original/projects/1/Xor.hdl b/original/projects/1/Xor.hdl
new file mode 100644
index 0000000..c6d90f9
--- /dev/null
+++ b/original/projects/1/Xor.hdl
@@ -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/1/Xor.hdl
+/**
+ * Exclusive-or gate:
+ * if ((a and Not(b)) or (Not(a) and b)) out = 1, else out = 0
+ */
+CHIP Xor {
+ IN a, b;
+ OUT out;
+
+ PARTS:
+ //// Replace this comment with your code.
+}
\ No newline at end of file
diff --git a/original/projects/1/Xor.tst b/original/projects/1/Xor.tst
new file mode 100644
index 0000000..a6af078
--- /dev/null
+++ b/original/projects/1/Xor.tst
@@ -0,0 +1,29 @@
+// 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/1/Xor.tst
+
+load Xor.hdl,
+output-file Xor.out,
+compare-to Xor.cmp,
+output-list a b out;
+
+set a 0,
+set b 0,
+eval,
+output;
+
+set a 0,
+set b 1,
+eval,
+output;
+
+set a 1,
+set b 0,
+eval,
+output;
+
+set a 1,
+set b 1,
+eval,
+output;
diff --git a/original/projects/10/ArrayTest/Main.jack b/original/projects/10/ArrayTest/Main.jack
new file mode 100644
index 0000000..475c80d
--- /dev/null
+++ b/original/projects/10/ArrayTest/Main.jack
@@ -0,0 +1,38 @@
+// 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/10/ArrayTest/Main.jack
+
+// (same as projects/9/Average/Main.jack)
+
+/** Computes the average of a sequence of integers. */
+class Main {
+ function void main() {
+ var Array a;
+ var int length;
+ var int i, sum;
+
+ let length = Keyboard.readInt("HOW MANY NUMBERS? ");
+ let a = Array.new(length);
+ let i = 0;
+
+ while (i < length) {
+ let a[i] = Keyboard.readInt("ENTER THE NEXT NUMBER: ");
+ let i = i + 1;
+ }
+
+ let i = 0;
+ let sum = 0;
+
+ while (i < length) {
+ let sum = sum + a[i];
+ let i = i + 1;
+ }
+
+ do Output.printString("THE AVERAGE IS: ");
+ do Output.printInt(sum / length);
+ do Output.println();
+
+ return;
+ }
+}
diff --git a/original/projects/10/ArrayTest/Main.xml b/original/projects/10/ArrayTest/Main.xml
new file mode 100644
index 0000000..0ea96df
--- /dev/null
+++ b/original/projects/10/ArrayTest/Main.xml
@@ -0,0 +1,286 @@
+
+ class
+ Main
+ {
+
+ function
+ void
+ main
+ (
+
+
+ )
+
+ {
+
+ var
+ Array
+ a
+ ;
+
+
+ var
+ int
+ length
+ ;
+
+
+ var
+ int
+ i
+ ,
+ sum
+ ;
+
+
+
+ let
+ length
+ =
+
+
+ Keyboard
+ .
+ readInt
+ (
+
+
+
+ HOW MANY NUMBERS?
+
+
+
+ )
+
+
+ ;
+
+
+ let
+ a
+ =
+
+
+ Array
+ .
+ new
+ (
+
+
+
+ length
+
+
+
+ )
+
+
+ ;
+
+
+ let
+ i
+ =
+
+
+ 0
+
+
+ ;
+
+
+ while
+ (
+
+
+ i
+
+ <
+
+ length
+
+
+ )
+ {
+
+
+ let
+ a
+ [
+
+
+ i
+
+
+ ]
+ =
+
+
+ Keyboard
+ .
+ readInt
+ (
+
+
+
+ ENTER THE NEXT NUMBER:
+
+
+
+ )
+
+
+ ;
+
+
+ let
+ i
+ =
+
+
+ i
+
+ +
+
+ 1
+
+
+ ;
+
+
+ }
+
+
+ let
+ i
+ =
+
+
+ 0
+
+
+ ;
+
+
+ let
+ sum
+ =
+
+
+ 0
+
+
+ ;
+
+
+ while
+ (
+
+
+ i
+
+ <
+
+ length
+
+
+ )
+ {
+
+
+ let
+ sum
+ =
+
+
+ sum
+
+ +
+
+ a
+ [
+
+
+ i
+
+
+ ]
+
+
+ ;
+
+
+ let
+ i
+ =
+
+
+ i
+
+ +
+
+ 1
+
+
+ ;
+
+
+ }
+
+
+ do
+ Output
+ .
+ printString
+ (
+
+
+
+ THE AVERAGE IS:
+
+
+
+ )
+ ;
+
+
+ do
+ Output
+ .
+ printInt
+ (
+
+
+
+ sum
+
+ /
+
+ length
+
+
+
+ )
+ ;
+
+
+ do
+ Output
+ .
+ println
+ (
+
+
+ )
+ ;
+
+
+ return
+ ;
+
+
+ }
+
+
+ }
+
diff --git a/original/projects/10/ArrayTest/MainT.xml b/original/projects/10/ArrayTest/MainT.xml
new file mode 100644
index 0000000..68721ec
--- /dev/null
+++ b/original/projects/10/ArrayTest/MainT.xml
@@ -0,0 +1,142 @@
+
+ class
+ Main
+ {
+ function
+ void
+ main
+ (
+ )
+ {
+ var
+ Array
+ a
+ ;
+ var
+ int
+ length
+ ;
+ var
+ int
+ i
+ ,
+ sum
+ ;
+ let
+ length
+ =
+ Keyboard
+ .
+ readInt
+ (
+ HOW MANY NUMBERS?
+ )
+ ;
+ let
+ a
+ =
+ Array
+ .
+ new
+ (
+ length
+ )
+ ;
+ let
+ i
+ =
+ 0
+ ;
+ while
+ (
+ i
+ <
+ length
+ )
+ {
+ let
+ a
+ [
+ i
+ ]
+ =
+ Keyboard
+ .
+ readInt
+ (
+ ENTER THE NEXT NUMBER:
+ )
+ ;
+ let
+ i
+ =
+ i
+ +
+ 1
+ ;
+ }
+ let
+ i
+ =
+ 0
+ ;
+ let
+ sum
+ =
+ 0
+ ;
+ while
+ (
+ i
+ <
+ length
+ )
+ {
+ let
+ sum
+ =
+ sum
+ +
+ a
+ [
+ i
+ ]
+ ;
+ let
+ i
+ =
+ i
+ +
+ 1
+ ;
+ }
+ do
+ Output
+ .
+ printString
+ (
+ THE AVERAGE IS:
+ )
+ ;
+ do
+ Output
+ .
+ printInt
+ (
+ sum
+ /
+ length
+ )
+ ;
+ do
+ Output
+ .
+ println
+ (
+ )
+ ;
+ return
+ ;
+ }
+ }
+
diff --git a/original/projects/10/ExpressionLessSquare/Main.jack b/original/projects/10/ExpressionLessSquare/Main.jack
new file mode 100644
index 0000000..94764ad
--- /dev/null
+++ b/original/projects/10/ExpressionLessSquare/Main.jack
@@ -0,0 +1,28 @@
+// 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/10/ExpressionLessSquare/Main.jack
+
+/** Expressionless version of projects/10/Square/Main.jack. */
+
+class Main {
+ static boolean test; // Added for testing -- there is no static keyword
+ // in the Square files.
+
+ function void main() {
+ var SquareGame game;
+ let game = game;
+ do game.run();
+ do game.dispose();
+ return;
+ }
+
+ function void more() { // Added to test Jack syntax that is not used in
+ var boolean b; // the Square files.
+ if (b) {
+ }
+ else { // There is no else keyword in the Square files.
+ }
+ return;
+ }
+}
diff --git a/original/projects/10/ExpressionLessSquare/Main.xml b/original/projects/10/ExpressionLessSquare/Main.xml
new file mode 100644
index 0000000..f71a0ef
--- /dev/null
+++ b/original/projects/10/ExpressionLessSquare/Main.xml
@@ -0,0 +1,114 @@
+
+ class
+ Main
+ {
+
+ static
+ boolean
+ test
+ ;
+
+
+ function
+ void
+ main
+ (
+
+
+ )
+
+ {
+
+ var
+ SquareGame
+ game
+ ;
+
+
+
+ let
+ game
+ =
+
+
+ game
+
+
+ ;
+
+
+ do
+ game
+ .
+ run
+ (
+
+
+ )
+ ;
+
+
+ do
+ game
+ .
+ dispose
+ (
+
+
+ )
+ ;
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ function
+ void
+ more
+ (
+
+
+ )
+
+ {
+
+ var
+ boolean
+ b
+ ;
+
+
+
+ if
+ (
+
+
+ b
+
+
+ )
+ {
+
+
+ }
+ else
+ {
+
+
+ }
+
+
+ return
+ ;
+
+
+ }
+
+
+ }
+
diff --git a/original/projects/10/ExpressionLessSquare/MainT.xml b/original/projects/10/ExpressionLessSquare/MainT.xml
new file mode 100644
index 0000000..441dfed
--- /dev/null
+++ b/original/projects/10/ExpressionLessSquare/MainT.xml
@@ -0,0 +1,64 @@
+
+ class
+ Main
+ {
+ static
+ boolean
+ test
+ ;
+ function
+ void
+ main
+ (
+ )
+ {
+ var
+ SquareGame
+ game
+ ;
+ let
+ game
+ =
+ game
+ ;
+ do
+ game
+ .
+ run
+ (
+ )
+ ;
+ do
+ game
+ .
+ dispose
+ (
+ )
+ ;
+ return
+ ;
+ }
+ function
+ void
+ more
+ (
+ )
+ {
+ var
+ boolean
+ b
+ ;
+ if
+ (
+ b
+ )
+ {
+ }
+ else
+ {
+ }
+ return
+ ;
+ }
+ }
+
diff --git a/original/projects/10/ExpressionLessSquare/Square.jack b/original/projects/10/ExpressionLessSquare/Square.jack
new file mode 100644
index 0000000..33a54ad
--- /dev/null
+++ b/original/projects/10/ExpressionLessSquare/Square.jack
@@ -0,0 +1,99 @@
+// 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/10/ExpressionLessSquare/Square.jack
+
+/** Expressionless version of projects/10/Square/Square.jack. */
+
+class Square {
+
+ field int x, y;
+ field int size;
+
+ constructor Square new(int Ax, int Ay, int Asize) {
+ let x = Ax;
+ let y = Ay;
+ let size = Asize;
+ do draw();
+ return x;
+ }
+
+ method void dispose() {
+ do Memory.deAlloc(this);
+ return;
+ }
+
+ method void draw() {
+ do Screen.setColor(x);
+ do Screen.drawRectangle(x, y, x, y);
+ return;
+ }
+
+ method void erase() {
+ do Screen.setColor(x);
+ do Screen.drawRectangle(x, y, x, y);
+ return;
+ }
+
+ method void incSize() {
+ if (x) {
+ do erase();
+ let size = size;
+ do draw();
+ }
+ return;
+ }
+
+ method void decSize() {
+ if (size) {
+ do erase();
+ let size = size;
+ do draw();
+ }
+ return;
+ }
+
+ method void moveUp() {
+ if (y) {
+ do Screen.setColor(x);
+ do Screen.drawRectangle(x, y, x, y);
+ let y = y;
+ do Screen.setColor(x);
+ do Screen.drawRectangle(x, y, x, y);
+ }
+ return;
+ }
+
+ method void moveDown() {
+ if (y) {
+ do Screen.setColor(x);
+ do Screen.drawRectangle(x, y, x, y);
+ let y = y;
+ do Screen.setColor(x);
+ do Screen.drawRectangle(x, y, x, y);
+ }
+ return;
+ }
+
+ method void moveLeft() {
+ if (x) {
+ do Screen.setColor(x);
+ do Screen.drawRectangle(x, y, x, y);
+ let x = x;
+ do Screen.setColor(x);
+ do Screen.drawRectangle(x, y, x, y);
+ }
+ return;
+ }
+
+ method void moveRight() {
+ if (x) {
+ do Screen.setColor(x);
+ do Screen.drawRectangle(x, y, x, y);
+ let x = x;
+ do Screen.setColor(x);
+ do Screen.drawRectangle(x, y, x, y);
+ }
+ return;
+ }
+}
diff --git a/original/projects/10/ExpressionLessSquare/Square.xml b/original/projects/10/ExpressionLessSquare/Square.xml
new file mode 100644
index 0000000..ed0e6ec
--- /dev/null
+++ b/original/projects/10/ExpressionLessSquare/Square.xml
@@ -0,0 +1,967 @@
+
+ class
+ Square
+ {
+
+ field
+ int
+ x
+ ,
+ y
+ ;
+
+
+ field
+ int
+ size
+ ;
+
+
+ constructor
+ Square
+ new
+ (
+
+ int
+ Ax
+ ,
+ int
+ Ay
+ ,
+ int
+ Asize
+
+ )
+
+ {
+
+
+ let
+ x
+ =
+
+
+ Ax
+
+
+ ;
+
+
+ let
+ y
+ =
+
+
+ Ay
+
+
+ ;
+
+
+ let
+ size
+ =
+
+
+ Asize
+
+
+ ;
+
+
+ do
+ draw
+ (
+
+
+ )
+ ;
+
+
+ return
+
+
+ x
+
+
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ dispose
+ (
+
+
+ )
+
+ {
+
+
+ do
+ Memory
+ .
+ deAlloc
+ (
+
+
+
+ this
+
+
+
+ )
+ ;
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ draw
+ (
+
+
+ )
+
+ {
+
+
+ do
+ Screen
+ .
+ setColor
+ (
+
+
+
+ x
+
+
+
+ )
+ ;
+
+
+ do
+ Screen
+ .
+ drawRectangle
+ (
+
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+ ,
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+
+ )
+ ;
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ erase
+ (
+
+
+ )
+
+ {
+
+
+ do
+ Screen
+ .
+ setColor
+ (
+
+
+
+ x
+
+
+
+ )
+ ;
+
+
+ do
+ Screen
+ .
+ drawRectangle
+ (
+
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+ ,
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+
+ )
+ ;
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ incSize
+ (
+
+
+ )
+
+ {
+
+
+ if
+ (
+
+
+ x
+
+
+ )
+ {
+
+
+ do
+ erase
+ (
+
+
+ )
+ ;
+
+
+ let
+ size
+ =
+
+
+ size
+
+
+ ;
+
+
+ do
+ draw
+ (
+
+
+ )
+ ;
+
+
+ }
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ decSize
+ (
+
+
+ )
+
+ {
+
+
+ if
+ (
+
+
+ size
+
+
+ )
+ {
+
+
+ do
+ erase
+ (
+
+
+ )
+ ;
+
+
+ let
+ size
+ =
+
+
+ size
+
+
+ ;
+
+
+ do
+ draw
+ (
+
+
+ )
+ ;
+
+
+ }
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ moveUp
+ (
+
+
+ )
+
+ {
+
+
+ if
+ (
+
+
+ y
+
+
+ )
+ {
+
+
+ do
+ Screen
+ .
+ setColor
+ (
+
+
+
+ x
+
+
+
+ )
+ ;
+
+
+ do
+ Screen
+ .
+ drawRectangle
+ (
+
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+ ,
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+
+ )
+ ;
+
+
+ let
+ y
+ =
+
+
+ y
+
+
+ ;
+
+
+ do
+ Screen
+ .
+ setColor
+ (
+
+
+
+ x
+
+
+
+ )
+ ;
+
+
+ do
+ Screen
+ .
+ drawRectangle
+ (
+
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+ ,
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+
+ )
+ ;
+
+
+ }
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ moveDown
+ (
+
+
+ )
+
+ {
+
+
+ if
+ (
+
+
+ y
+
+
+ )
+ {
+
+
+ do
+ Screen
+ .
+ setColor
+ (
+
+
+
+ x
+
+
+
+ )
+ ;
+
+
+ do
+ Screen
+ .
+ drawRectangle
+ (
+
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+ ,
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+
+ )
+ ;
+
+
+ let
+ y
+ =
+
+
+ y
+
+
+ ;
+
+
+ do
+ Screen
+ .
+ setColor
+ (
+
+
+
+ x
+
+
+
+ )
+ ;
+
+
+ do
+ Screen
+ .
+ drawRectangle
+ (
+
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+ ,
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+
+ )
+ ;
+
+
+ }
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ moveLeft
+ (
+
+
+ )
+
+ {
+
+
+ if
+ (
+
+
+ x
+
+
+ )
+ {
+
+
+ do
+ Screen
+ .
+ setColor
+ (
+
+
+
+ x
+
+
+
+ )
+ ;
+
+
+ do
+ Screen
+ .
+ drawRectangle
+ (
+
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+ ,
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+
+ )
+ ;
+
+
+ let
+ x
+ =
+
+
+ x
+
+
+ ;
+
+
+ do
+ Screen
+ .
+ setColor
+ (
+
+
+
+ x
+
+
+
+ )
+ ;
+
+
+ do
+ Screen
+ .
+ drawRectangle
+ (
+
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+ ,
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+
+ )
+ ;
+
+
+ }
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ moveRight
+ (
+
+
+ )
+
+ {
+
+
+ if
+ (
+
+
+ x
+
+
+ )
+ {
+
+
+ do
+ Screen
+ .
+ setColor
+ (
+
+
+
+ x
+
+
+
+ )
+ ;
+
+
+ do
+ Screen
+ .
+ drawRectangle
+ (
+
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+ ,
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+
+ )
+ ;
+
+
+ let
+ x
+ =
+
+
+ x
+
+
+ ;
+
+
+ do
+ Screen
+ .
+ setColor
+ (
+
+
+
+ x
+
+
+
+ )
+ ;
+
+
+ do
+ Screen
+ .
+ drawRectangle
+ (
+
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+ ,
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+
+ )
+ ;
+
+
+ }
+
+
+ return
+ ;
+
+
+ }
+
+
+ }
+
diff --git a/original/projects/10/ExpressionLessSquare/SquareGame.jack b/original/projects/10/ExpressionLessSquare/SquareGame.jack
new file mode 100644
index 0000000..2866f0d
--- /dev/null
+++ b/original/projects/10/ExpressionLessSquare/SquareGame.jack
@@ -0,0 +1,60 @@
+// 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/10/ExpressionLessSquare/SquareGame.jack
+
+/** Expressionless version of projects/10/Square/SquareGame.jack. */
+
+class SquareGame {
+ field Square square;
+ field int direction;
+
+ constructor SquareGame new() {
+ let square = square;
+ let direction = direction;
+ return square;
+ }
+
+ method void dispose() {
+ do square.dispose();
+ do Memory.deAlloc(square);
+ return;
+ }
+
+ method void moveSquare() {
+ if (direction) { do square.moveUp(); }
+ if (direction) { do square.moveDown(); }
+ if (direction) { do square.moveLeft(); }
+ if (direction) { do square.moveRight(); }
+ do Sys.wait(direction);
+ return;
+ }
+
+ method void run() {
+ var char key;
+ var boolean exit;
+
+ let exit = key;
+ while (exit) {
+ while (key) {
+ let key = key;
+ do moveSquare();
+ }
+
+ if (key) { let exit = exit; }
+ if (key) { do square.decSize(); }
+ if (key) { do square.incSize(); }
+ if (key) { let direction = exit; }
+ if (key) { let direction = key; }
+ if (key) { let direction = square; }
+ if (key) { let direction = direction; }
+
+ while (key) {
+ let key = key;
+ do moveSquare();
+ }
+ }
+ return;
+ }
+}
+
diff --git a/original/projects/10/ExpressionLessSquare/SquareGame.xml b/original/projects/10/ExpressionLessSquare/SquareGame.xml
new file mode 100644
index 0000000..288c6cd
--- /dev/null
+++ b/original/projects/10/ExpressionLessSquare/SquareGame.xml
@@ -0,0 +1,544 @@
+
+ class
+ SquareGame
+ {
+
+ field
+ Square
+ square
+ ;
+
+
+ field
+ int
+ direction
+ ;
+
+
+ constructor
+ SquareGame
+ new
+ (
+
+
+ )
+
+ {
+
+
+ let
+ square
+ =
+
+
+ square
+
+
+ ;
+
+
+ let
+ direction
+ =
+
+
+ direction
+
+
+ ;
+
+
+ return
+
+
+ square
+
+
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ dispose
+ (
+
+
+ )
+
+ {
+
+
+ do
+ square
+ .
+ dispose
+ (
+
+
+ )
+ ;
+
+
+ do
+ Memory
+ .
+ deAlloc
+ (
+
+
+
+ square
+
+
+
+ )
+ ;
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ moveSquare
+ (
+
+
+ )
+
+ {
+
+
+ if
+ (
+
+
+ direction
+
+
+ )
+ {
+
+
+ do
+ square
+ .
+ moveUp
+ (
+
+
+ )
+ ;
+
+
+ }
+
+
+ if
+ (
+
+
+ direction
+
+
+ )
+ {
+
+
+ do
+ square
+ .
+ moveDown
+ (
+
+
+ )
+ ;
+
+
+ }
+
+
+ if
+ (
+
+
+ direction
+
+
+ )
+ {
+
+
+ do
+ square
+ .
+ moveLeft
+ (
+
+
+ )
+ ;
+
+
+ }
+
+
+ if
+ (
+
+
+ direction
+
+
+ )
+ {
+
+
+ do
+ square
+ .
+ moveRight
+ (
+
+
+ )
+ ;
+
+
+ }
+
+
+ do
+ Sys
+ .
+ wait
+ (
+
+
+
+ direction
+
+
+
+ )
+ ;
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ run
+ (
+
+
+ )
+
+ {
+
+ var
+ char
+ key
+ ;
+
+
+ var
+ boolean
+ exit
+ ;
+
+
+
+ let
+ exit
+ =
+
+
+ key
+
+
+ ;
+
+
+ while
+ (
+
+
+ exit
+
+
+ )
+ {
+
+
+ while
+ (
+
+
+ key
+
+
+ )
+ {
+
+
+ let
+ key
+ =
+
+
+ key
+
+
+ ;
+
+
+ do
+ moveSquare
+ (
+
+
+ )
+ ;
+
+
+ }
+
+
+ if
+ (
+
+
+ key
+
+
+ )
+ {
+
+
+ let
+ exit
+ =
+
+
+ exit
+
+
+ ;
+
+
+ }
+
+
+ if
+ (
+
+
+ key
+
+
+ )
+ {
+
+
+ do
+ square
+ .
+ decSize
+ (
+
+
+ )
+ ;
+
+
+ }
+
+
+ if
+ (
+
+
+ key
+
+
+ )
+ {
+
+
+ do
+ square
+ .
+ incSize
+ (
+
+
+ )
+ ;
+
+
+ }
+
+
+ if
+ (
+
+
+ key
+
+
+ )
+ {
+
+
+ let
+ direction
+ =
+
+
+ exit
+
+
+ ;
+
+
+ }
+
+
+ if
+ (
+
+
+ key
+
+
+ )
+ {
+
+
+ let
+ direction
+ =
+
+
+ key
+
+
+ ;
+
+
+ }
+
+
+ if
+ (
+
+
+ key
+
+
+ )
+ {
+
+
+ let
+ direction
+ =
+
+
+ square
+
+
+ ;
+
+
+ }
+
+
+ if
+ (
+
+
+ key
+
+
+ )
+ {
+
+
+ let
+ direction
+ =
+
+
+ direction
+
+
+ ;
+
+
+ }
+
+
+ while
+ (
+
+
+ key
+
+
+ )
+ {
+
+
+ let
+ key
+ =
+
+
+ key
+
+
+ ;
+
+
+ do
+ moveSquare
+ (
+
+
+ )
+ ;
+
+
+ }
+
+
+ }
+
+
+ return
+ ;
+
+
+ }
+
+
+ }
+
diff --git a/original/projects/10/ExpressionLessSquare/SquareGameT.xml b/original/projects/10/ExpressionLessSquare/SquareGameT.xml
new file mode 100644
index 0000000..278a8a9
--- /dev/null
+++ b/original/projects/10/ExpressionLessSquare/SquareGameT.xml
@@ -0,0 +1,268 @@
+
+ class
+ SquareGame
+ {
+ field
+ Square
+ square
+ ;
+ field
+ int
+ direction
+ ;
+ constructor
+ SquareGame
+ new
+ (
+ )
+ {
+ let
+ square
+ =
+ square
+ ;
+ let
+ direction
+ =
+ direction
+ ;
+ return
+ square
+ ;
+ }
+ method
+ void
+ dispose
+ (
+ )
+ {
+ do
+ square
+ .
+ dispose
+ (
+ )
+ ;
+ do
+ Memory
+ .
+ deAlloc
+ (
+ square
+ )
+ ;
+ return
+ ;
+ }
+ method
+ void
+ moveSquare
+ (
+ )
+ {
+ if
+ (
+ direction
+ )
+ {
+ do
+ square
+ .
+ moveUp
+ (
+ )
+ ;
+ }
+ if
+ (
+ direction
+ )
+ {
+ do
+ square
+ .
+ moveDown
+ (
+ )
+ ;
+ }
+ if
+ (
+ direction
+ )
+ {
+ do
+ square
+ .
+ moveLeft
+ (
+ )
+ ;
+ }
+ if
+ (
+ direction
+ )
+ {
+ do
+ square
+ .
+ moveRight
+ (
+ )
+ ;
+ }
+ do
+ Sys
+ .
+ wait
+ (
+ direction
+ )
+ ;
+ return
+ ;
+ }
+ method
+ void
+ run
+ (
+ )
+ {
+ var
+ char
+ key
+ ;
+ var
+ boolean
+ exit
+ ;
+ let
+ exit
+ =
+ key
+ ;
+ while
+ (
+ exit
+ )
+ {
+ while
+ (
+ key
+ )
+ {
+ let
+ key
+ =
+ key
+ ;
+ do
+ moveSquare
+ (
+ )
+ ;
+ }
+ if
+ (
+ key
+ )
+ {
+ let
+ exit
+ =
+ exit
+ ;
+ }
+ if
+ (
+ key
+ )
+ {
+ do
+ square
+ .
+ decSize
+ (
+ )
+ ;
+ }
+ if
+ (
+ key
+ )
+ {
+ do
+ square
+ .
+ incSize
+ (
+ )
+ ;
+ }
+ if
+ (
+ key
+ )
+ {
+ let
+ direction
+ =
+ exit
+ ;
+ }
+ if
+ (
+ key
+ )
+ {
+ let
+ direction
+ =
+ key
+ ;
+ }
+ if
+ (
+ key
+ )
+ {
+ let
+ direction
+ =
+ square
+ ;
+ }
+ if
+ (
+ key
+ )
+ {
+ let
+ direction
+ =
+ direction
+ ;
+ }
+ while
+ (
+ key
+ )
+ {
+ let
+ key
+ =
+ key
+ ;
+ do
+ moveSquare
+ (
+ )
+ ;
+ }
+ }
+ return
+ ;
+ }
+ }
+
diff --git a/original/projects/10/ExpressionLessSquare/SquareT.xml b/original/projects/10/ExpressionLessSquare/SquareT.xml
new file mode 100644
index 0000000..cd03a1e
--- /dev/null
+++ b/original/projects/10/ExpressionLessSquare/SquareT.xml
@@ -0,0 +1,449 @@
+
+ class
+ Square
+ {
+ field
+ int
+ x
+ ,
+ y
+ ;
+ field
+ int
+ size
+ ;
+ constructor
+ Square
+ new
+ (
+ int
+ Ax
+ ,
+ int
+ Ay
+ ,
+ int
+ Asize
+ )
+ {
+ let
+ x
+ =
+ Ax
+ ;
+ let
+ y
+ =
+ Ay
+ ;
+ let
+ size
+ =
+ Asize
+ ;
+ do
+ draw
+ (
+ )
+ ;
+ return
+ x
+ ;
+ }
+ method
+ void
+ dispose
+ (
+ )
+ {
+ do
+ Memory
+ .
+ deAlloc
+ (
+ this
+ )
+ ;
+ return
+ ;
+ }
+ method
+ void
+ draw
+ (
+ )
+ {
+ do
+ Screen
+ .
+ setColor
+ (
+ x
+ )
+ ;
+ do
+ Screen
+ .
+ drawRectangle
+ (
+ x
+ ,
+ y
+ ,
+ x
+ ,
+ y
+ )
+ ;
+ return
+ ;
+ }
+ method
+ void
+ erase
+ (
+ )
+ {
+ do
+ Screen
+ .
+ setColor
+ (
+ x
+ )
+ ;
+ do
+ Screen
+ .
+ drawRectangle
+ (
+ x
+ ,
+ y
+ ,
+ x
+ ,
+ y
+ )
+ ;
+ return
+ ;
+ }
+ method
+ void
+ incSize
+ (
+ )
+ {
+ if
+ (
+ x
+ )
+ {
+ do
+ erase
+ (
+ )
+ ;
+ let
+ size
+ =
+ size
+ ;
+ do
+ draw
+ (
+ )
+ ;
+ }
+ return
+ ;
+ }
+ method
+ void
+ decSize
+ (
+ )
+ {
+ if
+ (
+ size
+ )
+ {
+ do
+ erase
+ (
+ )
+ ;
+ let
+ size
+ =
+ size
+ ;
+ do
+ draw
+ (
+ )
+ ;
+ }
+ return
+ ;
+ }
+ method
+ void
+ moveUp
+ (
+ )
+ {
+ if
+ (
+ y
+ )
+ {
+ do
+ Screen
+ .
+ setColor
+ (
+ x
+ )
+ ;
+ do
+ Screen
+ .
+ drawRectangle
+ (
+ x
+ ,
+ y
+ ,
+ x
+ ,
+ y
+ )
+ ;
+ let
+ y
+ =
+ y
+ ;
+ do
+ Screen
+ .
+ setColor
+ (
+ x
+ )
+ ;
+ do
+ Screen
+ .
+ drawRectangle
+ (
+ x
+ ,
+ y
+ ,
+ x
+ ,
+ y
+ )
+ ;
+ }
+ return
+ ;
+ }
+ method
+ void
+ moveDown
+ (
+ )
+ {
+ if
+ (
+ y
+ )
+ {
+ do
+ Screen
+ .
+ setColor
+ (
+ x
+ )
+ ;
+ do
+ Screen
+ .
+ drawRectangle
+ (
+ x
+ ,
+ y
+ ,
+ x
+ ,
+ y
+ )
+ ;
+ let
+ y
+ =
+ y
+ ;
+ do
+ Screen
+ .
+ setColor
+ (
+ x
+ )
+ ;
+ do
+ Screen
+ .
+ drawRectangle
+ (
+ x
+ ,
+ y
+ ,
+ x
+ ,
+ y
+ )
+ ;
+ }
+ return
+ ;
+ }
+ method
+ void
+ moveLeft
+ (
+ )
+ {
+ if
+ (
+ x
+ )
+ {
+ do
+ Screen
+ .
+ setColor
+ (
+ x
+ )
+ ;
+ do
+ Screen
+ .
+ drawRectangle
+ (
+ x
+ ,
+ y
+ ,
+ x
+ ,
+ y
+ )
+ ;
+ let
+ x
+ =
+ x
+ ;
+ do
+ Screen
+ .
+ setColor
+ (
+ x
+ )
+ ;
+ do
+ Screen
+ .
+ drawRectangle
+ (
+ x
+ ,
+ y
+ ,
+ x
+ ,
+ y
+ )
+ ;
+ }
+ return
+ ;
+ }
+ method
+ void
+ moveRight
+ (
+ )
+ {
+ if
+ (
+ x
+ )
+ {
+ do
+ Screen
+ .
+ setColor
+ (
+ x
+ )
+ ;
+ do
+ Screen
+ .
+ drawRectangle
+ (
+ x
+ ,
+ y
+ ,
+ x
+ ,
+ y
+ )
+ ;
+ let
+ x
+ =
+ x
+ ;
+ do
+ Screen
+ .
+ setColor
+ (
+ x
+ )
+ ;
+ do
+ Screen
+ .
+ drawRectangle
+ (
+ x
+ ,
+ y
+ ,
+ x
+ ,
+ y
+ )
+ ;
+ }
+ return
+ ;
+ }
+ }
+
diff --git a/original/projects/10/Square/Main.jack b/original/projects/10/Square/Main.jack
new file mode 100644
index 0000000..09b6877
--- /dev/null
+++ b/original/projects/10/Square/Main.jack
@@ -0,0 +1,36 @@
+// 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/10/Square/Main.jack
+
+// (similar to projects/9/Square/Main.jack, with testing additions)
+
+/** Initializes a new Square game and starts running it. */
+class Main {
+ static boolean test; // Added for testing -- there is no static keyword
+ // in the Square files.
+ function void main() {
+ var SquareGame game;
+ let game = SquareGame.new();
+ do game.run();
+ do game.dispose();
+ return;
+ }
+
+ function void more() { // Added to test Jack syntax that is not used in
+ var int i, j; // the Square files.
+ var String s;
+ var Array a;
+ if (false) {
+ let s = "string constant";
+ let s = null;
+ let a[1] = a[2];
+ }
+ else { // There is no else keyword in the Square files.
+ let i = i * (-j);
+ let j = j / (-2); // note: unary negate constant 2
+ let i = i | j;
+ }
+ return;
+ }
+}
diff --git a/original/projects/10/Square/Main.xml b/original/projects/10/Square/Main.xml
new file mode 100644
index 0000000..8796fa9
--- /dev/null
+++ b/original/projects/10/Square/Main.xml
@@ -0,0 +1,244 @@
+
+ class
+ Main
+ {
+
+ static
+ boolean
+ test
+ ;
+
+
+ function
+ void
+ main
+ (
+
+
+ )
+
+ {
+
+ var
+ SquareGame
+ game
+ ;
+
+
+
+ let
+ game
+ =
+
+
+ SquareGame
+ .
+ new
+ (
+
+
+ )
+
+
+ ;
+
+
+ do
+ game
+ .
+ run
+ (
+
+
+ )
+ ;
+
+
+ do
+ game
+ .
+ dispose
+ (
+
+
+ )
+ ;
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ function
+ void
+ more
+ (
+
+
+ )
+
+ {
+
+ var
+ int
+ i
+ ,
+ j
+ ;
+
+
+ var
+ String
+ s
+ ;
+
+
+ var
+ Array
+ a
+ ;
+
+
+
+ if
+ (
+
+
+ false
+
+
+ )
+ {
+
+
+ let
+ s
+ =
+
+
+ string constant
+
+
+ ;
+
+
+ let
+ s
+ =
+
+
+ null
+
+
+ ;
+
+
+ let
+ a
+ [
+
+
+ 1
+
+
+ ]
+ =
+
+
+ a
+ [
+
+
+ 2
+
+
+ ]
+
+
+ ;
+
+
+ }
+ else
+ {
+
+
+ let
+ i
+ =
+
+
+ i
+
+ *
+
+ (
+
+
+ -
+
+ j
+
+
+
+ )
+
+
+ ;
+
+
+ let
+ j
+ =
+
+
+ j
+
+ /
+
+ (
+
+
+ -
+
+ 2
+
+
+
+ )
+
+
+ ;
+
+
+ let
+ i
+ =
+
+
+ i
+
+ |
+
+ j
+
+
+ ;
+
+
+ }
+
+
+ return
+ ;
+
+
+ }
+
+
+ }
+
diff --git a/original/projects/10/Square/MainT.xml b/original/projects/10/Square/MainT.xml
new file mode 100644
index 0000000..bc92200
--- /dev/null
+++ b/original/projects/10/Square/MainT.xml
@@ -0,0 +1,126 @@
+
+ class
+ Main
+ {
+ static
+ boolean
+ test
+ ;
+ function
+ void
+ main
+ (
+ )
+ {
+ var
+ SquareGame
+ game
+ ;
+ let
+ game
+ =
+ SquareGame
+ .
+ new
+ (
+ )
+ ;
+ do
+ game
+ .
+ run
+ (
+ )
+ ;
+ do
+ game
+ .
+ dispose
+ (
+ )
+ ;
+ return
+ ;
+ }
+ function
+ void
+ more
+ (
+ )
+ {
+ var
+ int
+ i
+ ,
+ j
+ ;
+ var
+ String
+ s
+ ;
+ var
+ Array
+ a
+ ;
+ if
+ (
+ false
+ )
+ {
+ let
+ s
+ =
+ string constant
+ ;
+ let
+ s
+ =
+ null
+ ;
+ let
+ a
+ [
+ 1
+ ]
+ =
+ a
+ [
+ 2
+ ]
+ ;
+ }
+ else
+ {
+ let
+ i
+ =
+ i
+ *
+ (
+ -
+ j
+ )
+ ;
+ let
+ j
+ =
+ j
+ /
+ (
+ -
+ 2
+ )
+ ;
+ let
+ i
+ =
+ i
+ |
+ j
+ ;
+ }
+ return
+ ;
+ }
+ }
+
diff --git a/original/projects/10/Square/Square.jack b/original/projects/10/Square/Square.jack
new file mode 100644
index 0000000..e24c92c
--- /dev/null
+++ b/original/projects/10/Square/Square.jack
@@ -0,0 +1,110 @@
+// 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/10/Square/Square.jack
+
+// (same as projects/9/Square/Square.jack)
+
+/** Implements a graphical square. */
+class Square {
+
+ field int x, y; // screen location of the square's top-left corner
+ field int size; // length of this square, in pixels
+
+ /** Constructs a new square with a given location and size. */
+ constructor Square new(int Ax, int Ay, int Asize) {
+ let x = Ax;
+ let y = Ay;
+ let size = Asize;
+ do draw();
+ return this;
+ }
+
+ /** Disposes this square. */
+ method void dispose() {
+ do Memory.deAlloc(this);
+ return;
+ }
+
+ /** Draws the square on the screen. */
+ method void draw() {
+ do Screen.setColor(true);
+ do Screen.drawRectangle(x, y, x + size, y + size);
+ return;
+ }
+
+ /** Erases the square from the screen. */
+ method void erase() {
+ do Screen.setColor(false);
+ do Screen.drawRectangle(x, y, x + size, y + size);
+ return;
+ }
+
+ /** Increments the square size by 2 pixels. */
+ method void incSize() {
+ if (((y + size) < 254) & ((x + size) < 510)) {
+ do erase();
+ let size = size + 2;
+ do draw();
+ }
+ return;
+ }
+
+ /** Decrements the square size by 2 pixels. */
+ method void decSize() {
+ if (size > 2) {
+ do erase();
+ let size = size - 2;
+ do draw();
+ }
+ return;
+ }
+
+ /** Moves the square up by 2 pixels. */
+ method void moveUp() {
+ if (y > 1) {
+ do Screen.setColor(false);
+ do Screen.drawRectangle(x, (y + size) - 1, x + size, y + size);
+ let y = y - 2;
+ do Screen.setColor(true);
+ do Screen.drawRectangle(x, y, x + size, y + 1);
+ }
+ return;
+ }
+
+ /** Moves the square down by 2 pixels. */
+ method void moveDown() {
+ if ((y + size) < 254) {
+ do Screen.setColor(false);
+ do Screen.drawRectangle(x, y, x + size, y + 1);
+ let y = y + 2;
+ do Screen.setColor(true);
+ do Screen.drawRectangle(x, (y + size) - 1, x + size, y + size);
+ }
+ return;
+ }
+
+ /** Moves the square left by 2 pixels. */
+ method void moveLeft() {
+ if (x > 1) {
+ do Screen.setColor(false);
+ do Screen.drawRectangle((x + size) - 1, y, x + size, y + size);
+ let x = x - 2;
+ do Screen.setColor(true);
+ do Screen.drawRectangle(x, y, x + 1, y + size);
+ }
+ return;
+ }
+
+ /** Moves the square right by 2 pixels. */
+ method void moveRight() {
+ if ((x + size) < 510) {
+ do Screen.setColor(false);
+ do Screen.drawRectangle(x, y, x + 1, y + size);
+ let x = x + 2;
+ do Screen.setColor(true);
+ do Screen.drawRectangle((x + size) - 1, y, x + size, y + size);
+ }
+ return;
+ }
+}
diff --git a/original/projects/10/Square/Square.xml b/original/projects/10/Square/Square.xml
new file mode 100644
index 0000000..ff5f235
--- /dev/null
+++ b/original/projects/10/Square/Square.xml
@@ -0,0 +1,1211 @@
+
+ class
+ Square
+ {
+
+ field
+ int
+ x
+ ,
+ y
+ ;
+
+
+ field
+ int
+ size
+ ;
+
+
+ constructor
+ Square
+ new
+ (
+
+ int
+ Ax
+ ,
+ int
+ Ay
+ ,
+ int
+ Asize
+
+ )
+
+ {
+
+
+ let
+ x
+ =
+
+
+ Ax
+
+
+ ;
+
+
+ let
+ y
+ =
+
+
+ Ay
+
+
+ ;
+
+
+ let
+ size
+ =
+
+
+ Asize
+
+
+ ;
+
+
+ do
+ draw
+ (
+
+
+ )
+ ;
+
+
+ return
+
+
+ this
+
+
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ dispose
+ (
+
+
+ )
+
+ {
+
+
+ do
+ Memory
+ .
+ deAlloc
+ (
+
+
+
+ this
+
+
+
+ )
+ ;
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ draw
+ (
+
+
+ )
+
+ {
+
+
+ do
+ Screen
+ .
+ setColor
+ (
+
+
+
+ true
+
+
+
+ )
+ ;
+
+
+ do
+ Screen
+ .
+ drawRectangle
+ (
+
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+ ,
+
+
+ x
+
+ +
+
+ size
+
+
+ ,
+
+
+ y
+
+ +
+
+ size
+
+
+
+ )
+ ;
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ erase
+ (
+
+
+ )
+
+ {
+
+
+ do
+ Screen
+ .
+ setColor
+ (
+
+
+
+ false
+
+
+
+ )
+ ;
+
+
+ do
+ Screen
+ .
+ drawRectangle
+ (
+
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+ ,
+
+
+ x
+
+ +
+
+ size
+
+
+ ,
+
+
+ y
+
+ +
+
+ size
+
+
+
+ )
+ ;
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ incSize
+ (
+
+
+ )
+
+ {
+
+
+ if
+ (
+
+
+ (
+
+
+ (
+
+
+ y
+
+ +
+
+ size
+
+
+ )
+
+ <
+
+ 254
+
+
+ )
+
+ &
+
+ (
+
+
+ (
+
+
+ x
+
+ +
+
+ size
+
+
+ )
+
+ <
+
+ 510
+
+
+ )
+
+
+ )
+ {
+
+
+ do
+ erase
+ (
+
+
+ )
+ ;
+
+
+ let
+ size
+ =
+
+
+ size
+
+ +
+
+ 2
+
+
+ ;
+
+
+ do
+ draw
+ (
+
+
+ )
+ ;
+
+
+ }
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ decSize
+ (
+
+
+ )
+
+ {
+
+
+ if
+ (
+
+
+ size
+
+ >
+
+ 2
+
+
+ )
+ {
+
+
+ do
+ erase
+ (
+
+
+ )
+ ;
+
+
+ let
+ size
+ =
+
+
+ size
+
+ -
+
+ 2
+
+
+ ;
+
+
+ do
+ draw
+ (
+
+
+ )
+ ;
+
+
+ }
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ moveUp
+ (
+
+
+ )
+
+ {
+
+
+ if
+ (
+
+
+ y
+
+ >
+
+ 1
+
+
+ )
+ {
+
+
+ do
+ Screen
+ .
+ setColor
+ (
+
+
+
+ false
+
+
+
+ )
+ ;
+
+
+ do
+ Screen
+ .
+ drawRectangle
+ (
+
+
+
+ x
+
+
+ ,
+
+
+ (
+
+
+ y
+
+ +
+
+ size
+
+
+ )
+
+ -
+
+ 1
+
+
+ ,
+
+
+ x
+
+ +
+
+ size
+
+
+ ,
+
+
+ y
+
+ +
+
+ size
+
+
+
+ )
+ ;
+
+
+ let
+ y
+ =
+
+
+ y
+
+ -
+
+ 2
+
+
+ ;
+
+
+ do
+ Screen
+ .
+ setColor
+ (
+
+
+
+ true
+
+
+
+ )
+ ;
+
+
+ do
+ Screen
+ .
+ drawRectangle
+ (
+
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+ ,
+
+
+ x
+
+ +
+
+ size
+
+
+ ,
+
+
+ y
+
+ +
+
+ 1
+
+
+
+ )
+ ;
+
+
+ }
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ moveDown
+ (
+
+
+ )
+
+ {
+
+
+ if
+ (
+
+
+ (
+
+
+ y
+
+ +
+
+ size
+
+
+ )
+
+ <
+
+ 254
+
+
+ )
+ {
+
+
+ do
+ Screen
+ .
+ setColor
+ (
+
+
+
+ false
+
+
+
+ )
+ ;
+
+
+ do
+ Screen
+ .
+ drawRectangle
+ (
+
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+ ,
+
+
+ x
+
+ +
+
+ size
+
+
+ ,
+
+
+ y
+
+ +
+
+ 1
+
+
+
+ )
+ ;
+
+
+ let
+ y
+ =
+
+
+ y
+
+ +
+
+ 2
+
+
+ ;
+
+
+ do
+ Screen
+ .
+ setColor
+ (
+
+
+
+ true
+
+
+
+ )
+ ;
+
+
+ do
+ Screen
+ .
+ drawRectangle
+ (
+
+
+
+ x
+
+
+ ,
+
+
+ (
+
+
+ y
+
+ +
+
+ size
+
+
+ )
+
+ -
+
+ 1
+
+
+ ,
+
+
+ x
+
+ +
+
+ size
+
+
+ ,
+
+
+ y
+
+ +
+
+ size
+
+
+
+ )
+ ;
+
+
+ }
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ moveLeft
+ (
+
+
+ )
+
+ {
+
+
+ if
+ (
+
+
+ x
+
+ >
+
+ 1
+
+
+ )
+ {
+
+
+ do
+ Screen
+ .
+ setColor
+ (
+
+
+
+ false
+
+
+
+ )
+ ;
+
+
+ do
+ Screen
+ .
+ drawRectangle
+ (
+
+
+
+ (
+
+
+ x
+
+ +
+
+ size
+
+
+ )
+
+ -
+
+ 1
+
+
+ ,
+
+
+ y
+
+
+ ,
+
+
+ x
+
+ +
+
+ size
+
+
+ ,
+
+
+ y
+
+ +
+
+ size
+
+
+
+ )
+ ;
+
+
+ let
+ x
+ =
+
+
+ x
+
+ -
+
+ 2
+
+
+ ;
+
+
+ do
+ Screen
+ .
+ setColor
+ (
+
+
+
+ true
+
+
+
+ )
+ ;
+
+
+ do
+ Screen
+ .
+ drawRectangle
+ (
+
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+ ,
+
+
+ x
+
+ +
+
+ 1
+
+
+ ,
+
+
+ y
+
+ +
+
+ size
+
+
+
+ )
+ ;
+
+
+ }
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ moveRight
+ (
+
+
+ )
+
+ {
+
+
+ if
+ (
+
+
+ (
+
+
+ x
+
+ +
+
+ size
+
+
+ )
+
+ <
+
+ 510
+
+
+ )
+ {
+
+
+ do
+ Screen
+ .
+ setColor
+ (
+
+
+
+ false
+
+
+
+ )
+ ;
+
+
+ do
+ Screen
+ .
+ drawRectangle
+ (
+
+
+
+ x
+
+
+ ,
+
+
+ y
+
+
+ ,
+
+
+ x
+
+ +
+
+ 1
+
+
+ ,
+
+
+ y
+
+ +
+
+ size
+
+
+
+ )
+ ;
+
+
+ let
+ x
+ =
+
+
+ x
+
+ +
+
+ 2
+
+
+ ;
+
+
+ do
+ Screen
+ .
+ setColor
+ (
+
+
+
+ true
+
+
+
+ )
+ ;
+
+
+ do
+ Screen
+ .
+ drawRectangle
+ (
+
+
+
+ (
+
+
+ x
+
+ +
+
+ size
+
+
+ )
+
+ -
+
+ 1
+
+
+ ,
+
+
+ y
+
+
+ ,
+
+
+ x
+
+ +
+
+ size
+
+
+ ,
+
+
+ y
+
+ +
+
+ size
+
+
+
+ )
+ ;
+
+
+ }
+
+
+ return
+ ;
+
+
+ }
+
+
+ }
+
diff --git a/original/projects/10/Square/SquareGame.jack b/original/projects/10/Square/SquareGame.jack
new file mode 100644
index 0000000..38b4c6d
--- /dev/null
+++ b/original/projects/10/Square/SquareGame.jack
@@ -0,0 +1,79 @@
+// 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/10/Square/SquareGame.jack
+
+// (same as projects/9/Square/SquareGame.jack)
+/**
+ * Implements the Square game.
+ * This simple game allows the user to move a black square around
+ * the screen, and change the square's size during the movement.
+ * When the game starts, a square of 30 by 30 pixels is shown at the
+ * top-left corner of the screen. The user controls the square as follows.
+ * The 4 arrow keys are used to move the square up, down, left, and right.
+ * The 'z' and 'x' keys are used, respectively, to decrement and increment
+ * the square's size. The 'q' key is used to quit the game.
+ */
+class SquareGame {
+ field Square square; // the square of this game
+ field int direction; // the square's current direction:
+ // 0=none, 1=up, 2=down, 3=left, 4=right
+
+ /** Constructs a new Square Game. */
+ constructor SquareGame new() {
+ // Creates a 30 by 30 pixels square and positions it at the top-left
+ // of the screen.
+ let square = Square.new(0, 0, 30);
+ let direction = 0; // initial state is no movement
+ return this;
+ }
+
+ /** Disposes this game. */
+ method void dispose() {
+ do square.dispose();
+ do Memory.deAlloc(this);
+ return;
+ }
+
+ /** Moves the square in the current direction. */
+ method void moveSquare() {
+ if (direction = 1) { do square.moveUp(); }
+ if (direction = 2) { do square.moveDown(); }
+ if (direction = 3) { do square.moveLeft(); }
+ if (direction = 4) { do square.moveRight(); }
+ do Sys.wait(5); // delays the next movement
+ return;
+ }
+
+ /** Runs the game: handles the user's inputs and moves the square accordingly */
+ method void run() {
+ var char key; // the key currently pressed by the user
+ var boolean exit;
+ let exit = false;
+
+ while (~exit) {
+ // waits for a key to be pressed
+ while (key = 0) {
+ let key = Keyboard.keyPressed();
+ do moveSquare();
+ }
+ if (key = 81) { let exit = true; } // q key
+ if (key = 90) { do square.decSize(); } // z key
+ if (key = 88) { do square.incSize(); } // x key
+ if (key = 131) { let direction = 1; } // up arrow
+ if (key = 133) { let direction = 2; } // down arrow
+ if (key = 130) { let direction = 3; } // left arrow
+ if (key = 132) { let direction = 4; } // right arrow
+
+ // waits for the key to be released
+ while (~(key = 0)) {
+ let key = Keyboard.keyPressed();
+ do moveSquare();
+ }
+ } // while
+ return;
+ }
+}
+
+
+
diff --git a/original/projects/10/Square/SquareGame.xml b/original/projects/10/Square/SquareGame.xml
new file mode 100644
index 0000000..ed3ab6e
--- /dev/null
+++ b/original/projects/10/Square/SquareGame.xml
@@ -0,0 +1,643 @@
+
+ class
+ SquareGame
+ {
+
+ field
+ Square
+ square
+ ;
+
+
+ field
+ int
+ direction
+ ;
+
+
+ constructor
+ SquareGame
+ new
+ (
+
+
+ )
+
+ {
+
+
+ let
+ square
+ =
+
+
+ Square
+ .
+ new
+ (
+
+
+
+ 0
+
+
+ ,
+
+
+ 0
+
+
+ ,
+
+
+ 30
+
+
+
+ )
+
+
+ ;
+
+
+ let
+ direction
+ =
+
+
+ 0
+
+
+ ;
+
+
+ return
+
+
+ this
+
+
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ dispose
+ (
+
+
+ )
+
+ {
+
+
+ do
+ square
+ .
+ dispose
+ (
+
+
+ )
+ ;
+
+
+ do
+ Memory
+ .
+ deAlloc
+ (
+
+
+
+ this
+
+
+
+ )
+ ;
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ moveSquare
+ (
+
+
+ )
+
+ {
+
+
+ if
+ (
+
+
+ direction
+
+ =
+
+ 1
+
+
+ )
+ {
+
+
+ do
+ square
+ .
+ moveUp
+ (
+
+
+ )
+ ;
+
+
+ }
+
+
+ if
+ (
+
+
+ direction
+
+ =
+
+ 2
+
+
+ )
+ {
+
+
+ do
+ square
+ .
+ moveDown
+ (
+
+
+ )
+ ;
+
+
+ }
+
+
+ if
+ (
+
+
+ direction
+
+ =
+
+ 3
+
+
+ )
+ {
+
+
+ do
+ square
+ .
+ moveLeft
+ (
+
+
+ )
+ ;
+
+
+ }
+
+
+ if
+ (
+
+
+ direction
+
+ =
+
+ 4
+
+
+ )
+ {
+
+
+ do
+ square
+ .
+ moveRight
+ (
+
+
+ )
+ ;
+
+
+ }
+
+
+ do
+ Sys
+ .
+ wait
+ (
+
+
+
+ 5
+
+
+
+ )
+ ;
+
+
+ return
+ ;
+
+
+ }
+
+
+
+ method
+ void
+ run
+ (
+
+
+ )
+
+ {
+
+ var
+ char
+ key
+ ;
+
+
+ var
+ boolean
+ exit
+ ;
+
+
+
+ let
+ exit
+ =
+
+
+ false
+
+
+ ;
+
+
+ while
+ (
+
+
+ ~
+
+ exit
+
+
+
+ )
+ {
+
+
+ while
+ (
+
+
+ key
+
+ =
+
+ 0
+
+
+ )
+ {
+
+
+ let
+ key
+ =
+
+
+ Keyboard
+ .
+ keyPressed
+ (
+
+
+ )
+
+
+ ;
+
+
+ do
+ moveSquare
+ (
+
+
+ )
+ ;
+
+
+ }
+
+
+ if
+ (
+
+
+ key
+
+ =
+
+ 81
+
+
+ )
+ {
+
+
+ let
+ exit
+ =
+
+
+ true
+
+
+ ;
+
+
+ }
+
+
+ if
+ (
+
+
+ key
+
+ =
+
+ 90
+
+
+ )
+ {
+
+
+ do
+ square
+ .
+ decSize
+ (
+
+
+ )
+ ;
+
+
+ }
+
+
+ if
+ (
+
+
+ key
+
+ =
+
+ 88
+
+
+ )
+ {
+
+
+ do
+ square
+ .
+ incSize
+ (
+
+
+ )
+ ;
+
+
+ }
+
+
+ if
+ (
+
+
+ key
+
+ =
+
+ 131
+
+
+ )
+ {
+
+
+ let
+ direction
+ =
+
+
+ 1
+
+
+ ;
+
+
+ }
+
+
+ if
+ (
+
+
+ key
+
+ =
+
+ 133
+
+
+ )
+ {
+
+
+ let
+ direction
+ =
+
+
+ 2
+
+
+ ;
+
+
+ }
+
+
+ if
+ (
+
+
+ key
+
+ =
+
+ 130
+
+
+ )
+ {
+
+
+ let
+ direction
+ =
+
+
+ 3
+
+
+ ;
+
+
+ }
+
+
+ if
+ (
+
+
+ key
+
+ =
+
+ 132
+
+
+ )
+ {
+
+
+ let
+ direction
+ =
+
+
+ 4
+
+
+ ;
+
+
+ }
+
+
+ while
+ (
+
+
+ ~
+
+ (
+
+
+ key
+
+ =
+
+ 0
+
+
+ )
+
+
+
+ )
+ {
+
+
+ let
+ key
+ =
+
+
+ Keyboard
+ .
+ keyPressed
+ (
+
+
+ )
+
+
+ ;
+
+
+ do
+ moveSquare
+ (
+
+
+ )
+ ;
+
+
+ }
+
+
+ }
+
+
+ return
+ ;
+
+
+ }
+
+
+ }
+
diff --git a/original/projects/10/Square/SquareGameT.xml b/original/projects/10/Square/SquareGameT.xml
new file mode 100644
index 0000000..3136af2
--- /dev/null
+++ b/original/projects/10/Square/SquareGameT.xml
@@ -0,0 +1,315 @@
+
+ class
+ SquareGame
+ {
+ field
+ Square
+ square
+ ;
+ field
+ int
+ direction
+ ;
+ constructor
+ SquareGame
+ new
+ (
+ )
+ {
+ let
+ square
+ =
+ Square
+ .
+ new
+ (
+ 0
+ ,
+ 0
+ ,
+ 30
+ )
+ ;
+ let
+ direction
+ =
+ 0
+ ;
+ return
+ this
+ ;
+ }
+ method
+ void
+ dispose
+ (
+ )
+ {
+ do
+ square
+ .
+ dispose
+ (
+ )
+ ;
+ do
+ Memory
+ .
+ deAlloc
+ (
+ this
+ )
+ ;
+ return
+ ;
+ }
+ method
+ void
+ moveSquare
+ (
+ )
+ {
+ if
+ (
+ direction
+ =
+ 1
+ )
+ {
+ do
+ square
+ .
+ moveUp
+ (
+ )
+ ;
+ }
+ if
+ (
+ direction
+ =
+ 2
+ )
+ {
+ do
+ square
+ .
+ moveDown
+ (
+ )
+ ;
+ }
+ if
+ (
+ direction
+ =
+ 3
+ )
+ {
+ do
+ square
+ .
+ moveLeft
+ (
+ )
+ ;
+ }
+ if
+ (
+ direction
+ =
+ 4
+ )
+ {
+ do
+ square
+ .
+ moveRight
+ (
+ )
+ ;
+ }
+ do
+ Sys
+ .
+ wait
+ (
+ 5
+ )
+ ;
+ return
+ ;
+ }
+ method
+ void
+ run
+ (
+ )
+ {
+ var
+ char
+ key
+ ;
+ var
+ boolean
+ exit
+ ;
+ let
+ exit
+ =
+ false
+ ;
+ while
+ (
+ ~
+ exit
+ )
+ {
+ while
+ (
+ key
+ =
+ 0
+ )
+ {
+ let
+ key
+ =
+ Keyboard
+ .
+ keyPressed
+ (
+ )
+ ;
+ do
+ moveSquare
+ (
+ )
+ ;
+ }
+ if
+ (
+ key
+ =
+ 81
+ )
+ {
+ let
+ exit
+ =
+ true
+ ;
+ }
+ if
+ (
+ key
+ =
+ 90
+ )
+ {
+ do
+ square
+ .
+ decSize
+ (
+ )
+ ;
+ }
+ if
+ (
+ key
+ =
+ 88
+ )
+ {
+ do
+ square
+ .
+ incSize
+ (
+ )
+ ;
+ }
+ if
+ (
+ key
+ =
+ 131
+ )
+ {
+ let
+ direction
+ =
+ 1
+ ;
+ }
+ if
+ (
+ key
+ =
+ 133
+ )
+ {
+ let
+ direction
+ =
+ 2
+ ;
+ }
+ if
+ (
+ key
+ =
+ 130
+ )
+ {
+ let
+ direction
+ =
+ 3
+ ;
+ }
+ if
+ (
+ key
+ =
+ 132
+ )
+ {
+ let
+ direction
+ =
+ 4
+ ;
+ }
+ while
+ (
+ ~
+ (
+ key
+ =
+ 0
+ )
+ )
+ {
+ let
+ key
+ =
+ Keyboard
+ .
+ keyPressed
+ (
+ )
+ ;
+ do
+ moveSquare
+ (
+ )
+ ;
+ }
+ }
+ return
+ ;
+ }
+ }
+
diff --git a/original/projects/10/Square/SquareT.xml b/original/projects/10/Square/SquareT.xml
new file mode 100644
index 0000000..69a8ca0
--- /dev/null
+++ b/original/projects/10/Square/SquareT.xml
@@ -0,0 +1,561 @@
+
+ class
+ Square
+ {
+ field
+ int
+ x
+ ,
+ y
+ ;
+ field
+ int
+ size
+ ;
+ constructor
+ Square
+ new
+ (
+ int
+ Ax
+ ,
+ int
+ Ay
+ ,
+ int
+ Asize
+ )
+ {
+ let
+ x
+ =
+ Ax
+ ;
+ let
+ y
+ =
+ Ay
+ ;
+ let
+ size
+ =
+ Asize
+ ;
+ do
+ draw
+ (
+ )
+ ;
+ return
+ this
+ ;
+ }
+ method
+ void
+ dispose
+ (
+ )
+ {
+ do
+ Memory
+ .
+ deAlloc
+ (
+ this
+ )
+ ;
+ return
+ ;
+ }
+ method
+ void
+ draw
+ (
+ )
+ {
+ do
+ Screen
+ .
+ setColor
+ (
+ true
+ )
+ ;
+ do
+ Screen
+ .
+ drawRectangle
+ (
+ x
+ ,
+ y
+ ,
+ x
+ +
+ size
+ ,
+ y
+ +
+ size
+ )
+ ;
+ return
+ ;
+ }
+ method
+ void
+ erase
+ (
+ )
+ {
+ do
+ Screen
+ .
+ setColor
+ (
+ false
+ )
+ ;
+ do
+ Screen
+ .
+ drawRectangle
+ (
+ x
+ ,
+ y
+ ,
+ x
+ +
+ size
+ ,
+ y
+ +
+ size
+ )
+ ;
+ return
+ ;
+ }
+ method
+ void
+ incSize
+ (
+ )
+ {
+ if
+ (
+ (
+ (
+ y
+ +
+ size
+ )
+ <
+ 254
+ )
+ &
+ (
+ (
+ x
+ +
+ size
+ )
+ <
+ 510
+ )
+ )
+ {
+ do
+ erase
+ (
+ )
+ ;
+ let
+ size
+ =
+ size
+ +
+ 2
+ ;
+ do
+ draw
+ (
+ )
+ ;
+ }
+ return
+ ;
+ }
+ method
+ void
+ decSize
+ (
+ )
+ {
+ if
+ (
+ size
+ >
+ 2
+ )
+ {
+ do
+ erase
+ (
+ )
+ ;
+ let
+ size
+ =
+ size
+ -
+ 2
+ ;
+ do
+ draw
+ (
+ )
+ ;
+ }
+ return
+ ;
+ }
+ method
+ void
+ moveUp
+ (
+ )
+ {
+ if
+ (
+ y
+ >
+ 1
+ )
+ {
+ do
+ Screen
+ .
+ setColor
+ (
+ false
+ )
+ ;
+ do
+ Screen
+ .
+ drawRectangle
+ (
+ x
+ ,
+ (
+ y
+ +
+ size
+ )
+ -
+ 1
+ ,
+ x
+ +
+ size
+ ,
+ y
+ +
+ size
+ )
+ ;
+ let
+ y
+ =
+ y
+ -
+ 2
+ ;
+ do
+ Screen
+ .
+ setColor
+ (
+ true
+ )
+ ;
+ do
+ Screen
+ .
+ drawRectangle
+ (
+ x
+ ,
+ y
+ ,
+ x
+ +
+ size
+ ,
+ y
+ +
+ 1
+ )
+ ;
+ }
+ return
+ ;
+ }
+ method
+ void
+ moveDown
+ (
+ )
+ {
+ if
+ (
+ (
+ y
+ +
+ size
+ )
+ <
+ 254
+ )
+ {
+ do
+ Screen
+ .
+ setColor
+ (
+ false
+ )
+ ;
+ do
+ Screen
+ .
+ drawRectangle
+ (
+ x
+ ,
+ y
+ ,
+ x
+ +
+ size
+ ,
+ y
+ +
+ 1
+ )
+ ;
+ let
+ y
+ =
+ y
+ +
+ 2
+ ;
+ do
+ Screen
+ .
+ setColor
+ (
+ true
+ )
+ ;
+ do
+ Screen
+ .
+ drawRectangle
+ (
+ x
+ ,
+ (
+ y
+ +
+ size
+ )
+ -
+ 1
+ ,
+ x
+ +
+ size
+ ,
+ y
+ +
+ size
+ )
+ ;
+ }
+ return
+ ;
+ }
+ method
+ void
+ moveLeft
+ (
+ )
+ {
+ if
+ (
+ x
+ >
+ 1
+ )
+ {
+ do
+ Screen
+ .
+ setColor
+ (
+ false
+ )
+ ;
+ do
+ Screen
+ .
+ drawRectangle
+ (
+ (
+ x
+ +
+ size
+ )
+ -
+ 1
+ ,
+ y
+ ,
+ x
+ +
+ size
+ ,
+ y
+ +
+ size
+ )
+ ;
+ let
+ x
+ =
+ x
+ -
+ 2
+ ;
+ do
+ Screen
+ .
+ setColor
+ (
+ true
+ )
+ ;
+ do
+ Screen
+ .
+ drawRectangle
+ (
+ x
+ ,
+ y
+ ,
+ x
+ +
+ 1
+ ,
+ y
+ +
+ size
+ )
+ ;
+ }
+ return
+ ;
+ }
+ method
+ void
+ moveRight
+ (
+ )
+ {
+ if
+ (
+ (
+ x
+ +
+ size
+ )
+ <
+ 510
+ )
+ {
+ do
+ Screen
+ .
+ setColor
+ (
+ false
+ )
+ ;
+ do
+ Screen
+ .
+ drawRectangle
+ (
+ x
+ ,
+ y
+ ,
+ x
+ +
+ 1
+ ,
+ y
+ +
+ size
+ )
+ ;
+ let
+ x
+ =
+ x
+ +
+ 2
+ ;
+ do
+ Screen
+ .
+ setColor
+ (
+ true
+ )
+ ;
+ do
+ Screen
+ .
+ drawRectangle
+ (
+ (
+ x
+ +
+ size
+ )
+ -
+ 1
+ ,
+ y
+ ,
+ x
+ +
+ size
+ ,
+ y
+ +
+ size
+ )
+ ;
+ }
+ return
+ ;
+ }
+ }
+
diff --git a/original/projects/11/Average/Main.jack b/original/projects/11/Average/Main.jack
new file mode 100644
index 0000000..e04ae4d
--- /dev/null
+++ b/original/projects/11/Average/Main.jack
@@ -0,0 +1,27 @@
+// 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/11/Average/Main.jack
+
+// Inputs some numbers and computes their average
+class Main {
+ function void main() {
+ var Array a;
+ var int length;
+ var int i, sum;
+
+ let length = Keyboard.readInt("How many numbers? ");
+ let a = Array.new(length); // constructs the array
+
+ let i = 0;
+ while (i < length) {
+ let a[i] = Keyboard.readInt("Enter a number: ");
+ let sum = sum + a[i];
+ let i = i + 1;
+ }
+
+ do Output.printString("The average is ");
+ do Output.printInt(sum / length);
+ return;
+ }
+}
diff --git a/original/projects/11/ComplexArrays/Main.jack b/original/projects/11/ComplexArrays/Main.jack
new file mode 100644
index 0000000..e050b63
--- /dev/null
+++ b/original/projects/11/ComplexArrays/Main.jack
@@ -0,0 +1,69 @@
+// 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/11/ComplexArrays/Main.jack
+/**
+ * Performs several complex array processing tests.
+ * For each test, the expected result is printed, along with the
+ * actual result. In each test, the two results should be equal.
+ */
+class Main {
+
+ function void main() {
+ var Array a, b, c;
+
+ let a = Array.new(10);
+ let b = Array.new(5);
+ let c = Array.new(1);
+
+ let a[3] = 2;
+ let a[4] = 8;
+ let a[5] = 4;
+ let b[a[3]] = a[3] + 3; // b[2] = 5
+ let a[b[a[3]]] = a[a[5]] * b[((7 - a[3]) - Main.double(2)) + 1]; // a[5] = 8 * 5 = 40
+ let c[0] = null;
+ let c = c[0];
+
+ do Output.printString("Test 1: expected result: 5; actual result: ");
+ do Output.printInt(b[2]);
+ do Output.println();
+ do Output.printString("Test 2: expected result: 40; actual result: ");
+ do Output.printInt(a[5]);
+ do Output.println();
+ do Output.printString("Test 3: expected result: 0; actual result: ");
+ do Output.printInt(c);
+ do Output.println();
+
+ let c = null;
+
+ if (c = null) {
+ do Main.fill(a, 10);
+ let c = a[3];
+ let c[1] = 33;
+ let c = a[7];
+ let c[1] = 77;
+ let b = a[3];
+ let b[1] = b[1] + c[1]; // b[1] = 33 + 77 = 110;
+ }
+
+ do Output.printString("Test 4: expected result: 77; actual result: ");
+ do Output.printInt(c[1]);
+ do Output.println();
+ do Output.printString("Test 5: expected result: 110; actual result: ");
+ do Output.printInt(b[1]);
+ do Output.println();
+ return;
+ }
+
+ function int double(int a) {
+ return a * 2;
+ }
+
+ function void fill(Array a, int size) {
+ while (size > 0) {
+ let size = size - 1;
+ let a[size] = Array.new(3);
+ }
+ return;
+ }
+}
diff --git a/original/projects/11/ConvertToBin/Main.jack b/original/projects/11/ConvertToBin/Main.jack
new file mode 100644
index 0000000..518c0a7
--- /dev/null
+++ b/original/projects/11/ConvertToBin/Main.jack
@@ -0,0 +1,81 @@
+// 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/11/ConvertToBin/Main.jack
+/**
+ * Unpacks a 16-bit number into its binary representation:
+ * Takes the 16-bit number stored in RAM[8000] and stores its individual
+ * bits in RAM[8001]..RAM[8016] (each location will contain 0 or 1).
+ * Before the conversion, RAM[8001]..RAM[8016] are initialized to -1.
+ *
+ * The program should be tested as follows:
+ * 1) Load the program into the supplied VM emulator
+ * 2) Put some value in RAM[8000]
+ * 3) Switch to "no animation"
+ * 4) Run the program (give it enough time to run)
+ * 5) Stop the program
+ * 6) Check that RAM[8001]..RAM[8016] contain the correct bits, and
+ * that none of these memory locations contains -1.
+ */
+class Main {
+
+ /**
+ * Initializes RAM[8001]..RAM[8016] to -1,
+ * and converts the value in RAM[8000] to binary.
+ */
+ function void main() {
+ var int value;
+ do Main.fillMemory(8001, 16, -1); // sets RAM[8001]..RAM[8016] to -1
+ let value = Memory.peek(8000); // Uses an OS routine to read the input
+ do Main.convert(value); // performs the conversion
+ return;
+ }
+
+ /** Converts the given decimal value to binary, and puts
+ * the resulting bits in RAM[8001]..RAM[8016]. */
+ function void convert(int value) {
+ var int mask, position;
+ var boolean loop;
+
+ let loop = true;
+ while (loop) {
+ let position = position + 1;
+ let mask = Main.nextMask(mask);
+
+ if (~(position > 16)) {
+
+ if (~((value & mask) = 0)) {
+ do Memory.poke(8000 + position, 1);
+ }
+ else {
+ do Memory.poke(8000 + position, 0);
+ }
+ }
+ else {
+ let loop = false;
+ }
+ }
+ return;
+ }
+
+ /** Returns the next mask (the mask that should follow the given mask). */
+ function int nextMask(int mask) {
+ if (mask = 0) {
+ return 1;
+ }
+ else {
+ return mask * 2;
+ }
+ }
+
+ /** Fills 'length' consecutive memory locations with 'value',
+ * starting at 'address'. */
+ function void fillMemory(int address, int length, int value) {
+ while (length > 0) {
+ do Memory.poke(address, value);
+ let length = length - 1;
+ let address = address + 1;
+ }
+ return;
+ }
+}
diff --git a/original/projects/11/Pong/Ball.jack b/original/projects/11/Pong/Ball.jack
new file mode 100644
index 0000000..96ce029
--- /dev/null
+++ b/original/projects/11/Pong/Ball.jack
@@ -0,0 +1,203 @@
+// 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/11/Pong/Ball.jack
+// (Same as projects/9/Pong/Ball.jack)
+/**
+ * A graphical ball in a Pong game. Characterized by a screen location and
+ * distance of last destination. Has methods for drawing, erasing and moving
+ * on the screen. The ball is displayed as a filled, 6-by-6 pixles rectangle.
+ */
+class Ball {
+
+ field int x, y; // the ball's screen location (in pixels)
+ field int lengthx, lengthy; // distance of last destination (in pixels)
+
+ field int d, straightD, diagonalD; // used for straight line movement computation
+ field boolean invert, positivex, positivey; // (same)
+
+ field int leftWall, rightWall, topWall, bottomWall; // wall locations
+
+ field int wall; // last wall that the ball was bounced off of
+
+ /** Constructs a new ball with the given initial location and wall locations. */
+ constructor Ball new(int Ax, int Ay,
+ int AleftWall, int ArightWall, int AtopWall, int AbottomWall) {
+ let x = Ax;
+ let y = Ay;
+ let leftWall = AleftWall;
+ let rightWall = ArightWall - 6; // -6 for ball size
+ let topWall = AtopWall;
+ let bottomWall = AbottomWall - 6; // -6 for ball size
+ let wall = 0;
+ do show();
+ return this;
+ }
+
+ /** Deallocates the Ball's memory. */
+ method void dispose() {
+ do Memory.deAlloc(this);
+ return;
+ }
+
+ /** Shows the ball. */
+ method void show() {
+ do Screen.setColor(true);
+ do draw();
+ return;
+ }
+
+ /** Hides the ball. */
+ method void hide() {
+ do Screen.setColor(false);
+ do draw();
+ return;
+ }
+
+ /** Draws the ball. */
+ method void draw() {
+ do Screen.drawRectangle(x, y, x + 5, y + 5);
+ return;
+ }
+
+ /** Returns the ball's left edge. */
+ method int getLeft() {
+ return x;
+ }
+
+ /** Returns the ball's right edge. */
+ method int getRight() {
+ return x + 5;
+ }
+
+ /** Computes and sets the ball's destination. */
+ method void setDestination(int destx, int desty) {
+ var int dx, dy, temp;
+ let lengthx = destx - x;
+ let lengthy = desty - y;
+ let dx = Math.abs(lengthx);
+ let dy = Math.abs(lengthy);
+ let invert = (dx < dy);
+
+ if (invert) {
+ let temp = dx; // swap dx, dy
+ let dx = dy;
+ let dy = temp;
+ let positivex = (y < desty);
+ let positivey = (x < destx);
+ }
+ else {
+ let positivex = (x < destx);
+ let positivey = (y < desty);
+ }
+
+ let d = (2 * dy) - dx;
+ let straightD = 2 * dy;
+ let diagonalD = 2 * (dy - dx);
+
+ return;
+ }
+
+ /**
+ * Moves the ball one step towards its destination.
+ * If the ball has reached a wall, returns 0.
+ * Else, returns a value according to the wall:
+ * 1 (left wall), 2 (right wall), 3 (top wall), 4 (bottom wall).
+ */
+ method int move() {
+
+ do hide();
+
+ if (d < 0) { let d = d + straightD; }
+ else {
+ let d = d + diagonalD;
+
+ if (positivey) {
+ if (invert) { let x = x + 4; }
+ else { let y = y + 4; }
+ }
+ else {
+ if (invert) { let x = x - 4; }
+ else { let y = y - 4; }
+ }
+ }
+
+ if (positivex) {
+ if (invert) { let y = y + 4; }
+ else { let x = x + 4; }
+ }
+ else {
+ if (invert) { let y = y - 4; }
+ else { let x = x - 4; }
+ }
+
+ if (~(x > leftWall)) {
+ let wall = 1;
+ let x = leftWall;
+ }
+ if (~(x < rightWall)) {
+ let wall = 2;
+ let x = rightWall;
+ }
+ if (~(y > topWall)) {
+ let wall = 3;
+ let y = topWall;
+ }
+ if (~(y < bottomWall)) {
+ let wall = 4;
+ let y = bottomWall;
+ }
+
+ do show();
+
+ return wall;
+ }
+
+ /**
+ * Bounces off the current wall: sets the new destination
+ * of the ball according to the ball's angle and the given
+ * bouncing direction (-1/0/1=left/center/right or up/center/down).
+ */
+ method void bounce(int bouncingDirection) {
+ var int newx, newy, divLengthx, divLengthy, factor;
+
+ // Since results are too big, divides by 10
+ let divLengthx = lengthx / 10;
+ let divLengthy = lengthy / 10;
+ if (bouncingDirection = 0) { let factor = 10; }
+ else {
+ if (((~(lengthx < 0)) & (bouncingDirection = 1)) | ((lengthx < 0) & (bouncingDirection = (-1)))) {
+ let factor = 20; // bounce direction is in ball direction
+ }
+ else { let factor = 5; } // bounce direction is against ball direction
+ }
+
+ if (wall = 1) {
+ let newx = 506;
+ let newy = (divLengthy * (-50)) / divLengthx;
+ let newy = y + (newy * factor);
+ }
+ else {
+ if (wall = 2) {
+ let newx = 0;
+ let newy = (divLengthy * 50) / divLengthx;
+ let newy = y + (newy * factor);
+ }
+ else {
+ if (wall = 3) {
+ let newy = 250;
+ let newx = (divLengthx * (-25)) / divLengthy;
+ let newx = x + (newx * factor);
+ }
+ else { // assumes wall = 4
+ let newy = 0;
+ let newx = (divLengthx * 25) / divLengthy;
+ let newx = x + (newx * factor);
+ }
+ }
+ }
+
+ do setDestination(newx, newy);
+ return;
+ }
+}
diff --git a/original/projects/11/Pong/Bat.jack b/original/projects/11/Pong/Bat.jack
new file mode 100644
index 0000000..ebafe28
--- /dev/null
+++ b/original/projects/11/Pong/Bat.jack
@@ -0,0 +1,104 @@
+// 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/11/Pong/Bat.jack
+// (Same as projects/9/Pong/Bat.jack)
+/**
+ * A graphical bat in a Pong game.
+ * Displayed as a filled horizontal rectangle that has a screen location,
+ * a width and a height.
+ * Has methods for drawing, erasing, moving left and right, and changing
+ * its width (to make the hitting action more challenging).
+ * This class should have been called "Paddle", following the
+ * standard Pong terminology. Unaware of this terminology,
+ * we called it "bat", and the name stuck.
+ */
+class Bat {
+
+ field int x, y; // the bat's screen location
+ field int width, height; // the bat's width and height
+ field int direction; // direction of the bat's movement
+ // (1 = left, 2 = right)
+
+ /** Constructs a new bat with the given location and width. */
+ constructor Bat new(int Ax, int Ay, int Awidth, int Aheight) {
+ let x = Ax;
+ let y = Ay;
+ let width = Awidth;
+ let height = Aheight;
+ let direction = 2;
+ do show();
+ return this;
+ }
+
+ /** Deallocates the object's memory. */
+ method void dispose() {
+ do Memory.deAlloc(this);
+ return;
+ }
+
+ /** Shows the bat. */
+ method void show() {
+ do Screen.setColor(true);
+ do draw();
+ return;
+ }
+
+ /** Hides the bat. */
+ method void hide() {
+ do Screen.setColor(false);
+ do draw();
+ return;
+ }
+
+ /** Draws the bat. */
+ method void draw() {
+ do Screen.drawRectangle(x, y, x + width, y + height);
+ return;
+ }
+
+ /** Sets the bat's direction (0=stop, 1=left, 2=right). */
+ method void setDirection(int Adirection) {
+ let direction = Adirection;
+ return;
+ }
+
+ /** Returns the bat's left edge. */
+ method int getLeft() {
+ return x;
+ }
+
+ /** Returns the bat's right edge. */
+ method int getRight() {
+ return x + width;
+ }
+
+ /** Sets the bat's width. */
+ method void setWidth(int Awidth) {
+ do hide();
+ let width = Awidth;
+ do show();
+ return;
+ }
+
+ /** Moves the bat one step in the bat's direction. */
+ method void move() {
+ if (direction = 1) {
+ let x = x - 4;
+ if (x < 0) { let x = 0; }
+ do Screen.setColor(false);
+ do Screen.drawRectangle((x + width) + 1, y, (x + width) + 4, y + height);
+ do Screen.setColor(true);
+ do Screen.drawRectangle(x, y, x + 3, y + height);
+ }
+ else {
+ let x = x + 4;
+ if ((x + width) > 511) { let x = 511 - width; }
+ do Screen.setColor(false);
+ do Screen.drawRectangle(x - 4, y, x - 1, y + height);
+ do Screen.setColor(true);
+ do Screen.drawRectangle((x + width) - 3, y, x + width, y + height);
+ }
+ return;
+ }
+}
diff --git a/original/projects/11/Pong/Main.jack b/original/projects/11/Pong/Main.jack
new file mode 100644
index 0000000..50ad7e4
--- /dev/null
+++ b/original/projects/11/Pong/Main.jack
@@ -0,0 +1,20 @@
+// 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/11/Pong/Main.jack
+// (Same as projects/9/Pong/Main.jack)
+/**
+ * Main class of the Pong game.
+ */
+class Main {
+
+ /** Initializes a Pong game and starts running it. */
+ function void main() {
+ var PongGame game;
+ do PongGame.newInstance();
+ let game = PongGame.getInstance();
+ do game.run();
+ do game.dispose();
+ return;
+ }
+}
diff --git a/original/projects/11/Pong/PongGame.jack b/original/projects/11/Pong/PongGame.jack
new file mode 100644
index 0000000..b43d823
--- /dev/null
+++ b/original/projects/11/Pong/PongGame.jack
@@ -0,0 +1,137 @@
+// 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/11/Pong/PongGame.jack
+// (Same as projects/9/Pong/PongGame.jack)
+/**
+ * Represents a Pong game.
+ */
+class PongGame {
+
+ static PongGame instance; // A Pong game
+ field Bat bat; // bat
+ field Ball ball; // ball
+ field int wall; // current wall that the ball is bouncing off of
+ field boolean exit; // true when the game is over
+ field int score; // current score
+ field int lastWall; // last wall that the ball bounced off of
+
+ // The current width of the bat
+ field int batWidth;
+
+ /** Constructs a new Pong game. */
+ constructor PongGame new() {
+ do Screen.clearScreen();
+ let batWidth = 50; // initial bat size
+ let bat = Bat.new(230, 229, batWidth, 7);
+ let ball = Ball.new(253, 222, 0, 511, 0, 229);
+ do ball.setDestination(400,0);
+ do Screen.drawRectangle(0, 238, 511, 240);
+ do Output.moveCursor(22,0);
+ do Output.printString("Score: 0");
+
+ let exit = false;
+ let score = 0;
+ let wall = 0;
+ let lastWall = 0;
+
+ return this;
+ }
+
+ /** Deallocates the object's memory. */
+ method void dispose() {
+ do bat.dispose();
+ do ball.dispose();
+ do Memory.deAlloc(this);
+ return;
+ }
+
+ /** Creates an instance of a Pong game. */
+ function void newInstance() {
+ let instance = PongGame.new();
+ return;
+ }
+
+ /** Returns this Pong game. */
+ function PongGame getInstance() {
+ return instance;
+ }
+
+ /** Starts the game, and handles inputs from the user that control
+ * the bat's movement direction. */
+ method void run() {
+ var char key;
+
+ while (~exit) {
+ // waits for a key to be pressed.
+ while ((key = 0) & (~exit)) {
+ let key = Keyboard.keyPressed();
+ do bat.move();
+ do moveBall();
+ do Sys.wait(50);
+ }
+
+ if (key = 130) { do bat.setDirection(1); }
+ else {
+ if (key = 132) { do bat.setDirection(2); }
+ else {
+ if (key = 140) { let exit = true; }
+ }
+ }
+
+ // Waits for the key to be released.
+ while ((~(key = 0)) & (~exit)) {
+ let key = Keyboard.keyPressed();
+ do bat.move();
+ do moveBall();
+ do Sys.wait(50);
+ }
+ }
+
+ if (exit) {
+ do Output.moveCursor(10,27);
+ do Output.printString("Game Over");
+ }
+
+ return;
+ }
+
+ /**
+ * Handles ball movement, including bouncing.
+ * If the ball bounces off a wall, finds its new direction.
+ * If the ball bounces off the bat, increases the score by one
+ * and shrinks the bat's size, to make the game more challenging.
+ */
+ method void moveBall() {
+ var int bouncingDirection, batLeft, batRight, ballLeft, ballRight;
+
+ let wall = ball.move();
+
+ if ((wall > 0) & (~(wall = lastWall))) {
+ let lastWall = wall;
+ let bouncingDirection = 0;
+ let batLeft = bat.getLeft();
+ let batRight = bat.getRight();
+ let ballLeft = ball.getLeft();
+ let ballRight = ball.getRight();
+
+ if (wall = 4) {
+ let exit = (batLeft > ballRight) | (batRight < ballLeft);
+ if (~exit) {
+ if (ballRight < (batLeft + 10)) { let bouncingDirection = -1; }
+ else {
+ if (ballLeft > (batRight - 10)) { let bouncingDirection = 1; }
+ }
+
+ let batWidth = batWidth - 2;
+ do bat.setWidth(batWidth);
+ let score = score + 1;
+ do Output.moveCursor(22,7);
+ do Output.printInt(score);
+ }
+ }
+ do ball.bounce(bouncingDirection);
+ }
+ return;
+ }
+}
\ No newline at end of file
diff --git a/original/projects/11/Seven/Main.jack b/original/projects/11/Seven/Main.jack
new file mode 100644
index 0000000..e599b93
--- /dev/null
+++ b/original/projects/11/Seven/Main.jack
@@ -0,0 +1,16 @@
+// 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/11/Seven/Main.jack
+/**
+ * Computes the value of 1 + (2 * 3) and prints the result
+ * at the top-left of the screen.
+ */
+class Main {
+
+ function void main() {
+ do Output.printInt(1 + (2 * 3));
+ return;
+ }
+
+}
diff --git a/original/projects/11/Square/Main.jack b/original/projects/11/Square/Main.jack
new file mode 100644
index 0000000..16f2186
--- /dev/null
+++ b/original/projects/11/Square/Main.jack
@@ -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/11/Square/Main.jack
+
+/** Initializes a new Square game and starts running it. */
+class Main {
+ function void main() {
+ var SquareGame game;
+ let game = SquareGame.new();
+ do game.run();
+ do game.dispose();
+ return;
+ }
+}
diff --git a/original/projects/11/Square/Square.jack b/original/projects/11/Square/Square.jack
new file mode 100644
index 0000000..78b9400
--- /dev/null
+++ b/original/projects/11/Square/Square.jack
@@ -0,0 +1,113 @@
+// 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/11/Square/Square.jack
+
+/** Implements a graphical square.
+ The square has top-left x and y coordinates, and a size. */
+class Square {
+
+ field int x, y; // screen location of the top-left corner of this square
+ field int size; // length of this square, in pixels
+
+ /** Constructs and draws a new square with a given location and size. */
+ constructor Square new(int ax, int ay, int asize) {
+ let x = ax;
+ let y = ay;
+ let size = asize;
+ do draw();
+ return this;
+ }
+
+ /** Disposes this square. */
+ method void dispose() {
+ do Memory.deAlloc(this);
+ return;
+ }
+
+ /** Draws this square in its current (x,y) location */
+ method void draw() {
+ // Draws the square using the color black
+ do Screen.setColor(true);
+ do Screen.drawRectangle(x, y, x + size, y + size);
+ return;
+ }
+
+ /** Erases this square. */
+ method void erase() {
+ // Draws the square using the color white (background color)
+ do Screen.setColor(false);
+ do Screen.drawRectangle(x, y, x + size, y + size);
+ return;
+ }
+
+ /** Increments the square size by 2 pixels (if possible). */
+ method void incSize() {
+ if (((y + size) < 254) & ((x + size) < 510)) {
+ do erase();
+ let size = size + 2;
+ do draw();
+ }
+ return;
+ }
+
+ /** Decrements the square size by 2 pixels (if possible). */
+ method void decSize() {
+ if (size > 2) {
+ do erase();
+ let size = size - 2;
+ do draw();
+ }
+ return;
+ }
+
+ /** Moves this square up by 2 pixels (if possible). */
+ method void moveUp() {
+ if (y > 1) {
+ // Erases the bottom two rows of this square in its current location
+ do Screen.setColor(false);
+ do Screen.drawRectangle(x, (y + size) - 1, x + size, y + size);
+ let y = y - 2;
+ // Draws the top two rows of this square in its new location
+ do Screen.setColor(true);
+ do Screen.drawRectangle(x, y, x + size, y + 1);
+ }
+ return;
+ }
+
+ /** Moves the square down by 2 pixels (if possible). */
+ method void moveDown() {
+ if ((y + size) < 254) {
+ do Screen.setColor(false);
+ do Screen.drawRectangle(x, y, x + size, y + 1);
+ let y = y + 2;
+ do Screen.setColor(true);
+ do Screen.drawRectangle(x, (y + size) - 1, x + size, y + size);
+ }
+ return;
+ }
+
+ /** Moves the square left by 2 pixels (if possible). */
+ method void moveLeft() {
+ if (x > 1) {
+ do Screen.setColor(false);
+ do Screen.drawRectangle((x + size) - 1, y, x + size, y + size);
+ let x = x - 2;
+ do Screen.setColor(true);
+ do Screen.drawRectangle(x, y, x + 1, y + size);
+ }
+ return;
+ }
+
+ /** Moves the square right by 2 pixels (if possible). */
+ method void moveRight() {
+ if ((x + size) < 510) {
+ do Screen.setColor(false);
+ do Screen.drawRectangle(x, y, x + 1, y + size);
+ let x = x + 2;
+ do Screen.setColor(true);
+ do Screen.drawRectangle((x + size) - 1, y, x + size, y + size);
+ }
+ return;
+ }
+}
diff --git a/original/projects/11/Square/SquareGame.jack b/original/projects/11/Square/SquareGame.jack
new file mode 100644
index 0000000..0871063
--- /dev/null
+++ b/original/projects/11/Square/SquareGame.jack
@@ -0,0 +1,76 @@
+// 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/11/Square/SquareGame.jack
+/**
+ * Implements the Square game.
+ * This simple game allows the user to move a black square around
+ * the screen, and change the square's size during the movement.
+ * When the game starts, a square of 30 by 30 pixels is shown at the
+ * top-left corner of the screen. The user controls the square as follows.
+ * The 4 arrow keys are used to move the square up, down, left, and right.
+ * The 'z' and 'x' keys are used, respectively, to decrement and increment
+ * the square's size. The 'q' key is used to quit the game.
+ */
+class SquareGame {
+ field Square square; // the square of this game
+ field int direction; // the square's current direction:
+ // 0=none, 1=up, 2=down, 3=left, 4=right
+
+ /** Constructs a new square game. */
+ constructor SquareGame new() {
+ // The initial square is located in (0,0), has size 30, and is not moving.
+ let square = Square.new(0, 0, 30);
+ let direction = 0;
+ return this;
+ }
+
+ /** Disposes this game. */
+ method void dispose() {
+ do square.dispose();
+ do Memory.deAlloc(this);
+ return;
+ }
+
+ /** Moves the square in the current direction. */
+ method void moveSquare() {
+ if (direction = 1) { do square.moveUp(); }
+ if (direction = 2) { do square.moveDown(); }
+ if (direction = 3) { do square.moveLeft(); }
+ if (direction = 4) { do square.moveRight(); }
+ do Sys.wait(5); // delays the next movement
+ return;
+ }
+
+ /** Runs the game: handles the user's inputs and moves the square accordingly */
+ method void run() {
+ var char key; // the key currently pressed by the user
+ var boolean exit;
+ let exit = false;
+
+ while (~exit) {
+ // waits for a key to be pressed
+ while (key = 0) {
+ let key = Keyboard.keyPressed();
+ do moveSquare();
+ }
+ if (key = 81) { let exit = true; } // q key
+ if (key = 90) { do square.decSize(); } // z key
+ if (key = 88) { do square.incSize(); } // x key
+ if (key = 131) { let direction = 1; } // up arrow
+ if (key = 133) { let direction = 2; } // down arrow
+ if (key = 130) { let direction = 3; } // left arrow
+ if (key = 132) { let direction = 4; } // right arrow
+
+ // waits for the key to be released
+ while (~(key = 0)) {
+ let key = Keyboard.keyPressed();
+ do moveSquare();
+ }
+ } // while
+ return;
+ }
+}
+
+
+
diff --git a/original/projects/12/Array.jack b/original/projects/12/Array.jack
new file mode 100644
index 0000000..efc7e9c
--- /dev/null
+++ b/original/projects/12/Array.jack
@@ -0,0 +1,22 @@
+// 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/Array.jack
+/**
+ * Represents an array.
+ * In the Jack language, arrays are instances of the Array class.
+ * Once declared, the array entries can be accessed using the usual
+ * syntax arr[i]. Each array entry can hold a primitive data type as
+ * well as any object type. Different array entries can have different
+ * data types.
+ */
+class Array {
+
+ /** Constructs a new Array of the given size. */
+ function Array new(int size) {
+ }
+
+ /** Disposes this array. */
+ method void dispose() {
+ }
+}
diff --git a/original/projects/12/ArrayTest/ArrayTest.cmp b/original/projects/12/ArrayTest/ArrayTest.cmp
new file mode 100644
index 0000000..d1a9798
--- /dev/null
+++ b/original/projects/12/ArrayTest/ArrayTest.cmp
@@ -0,0 +1,2 @@
+|RAM[8000]|RAM[8001]|RAM[8002]|RAM[8003]|
+| 222 | 122 | 100 | 10 |
diff --git a/original/projects/12/ArrayTest/ArrayTest.tst b/original/projects/12/ArrayTest/ArrayTest.tst
new file mode 100644
index 0000000..89934b9
--- /dev/null
+++ b/original/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/original/projects/12/ArrayTest/Main.jack b/original/projects/12/ArrayTest/Main.jack
new file mode 100644
index 0000000..439770a
--- /dev/null
+++ b/original/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;
+ }
+}
diff --git a/original/projects/12/Keyboard.jack b/original/projects/12/Keyboard.jack
new file mode 100644
index 0000000..d90e547
--- /dev/null
+++ b/original/projects/12/Keyboard.jack
@@ -0,0 +1,55 @@
+// 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/Keyboard.jack
+/**
+ * A library for handling user input from the keyboard.
+ */
+class Keyboard {
+
+ /** Initializes the keyboard. */
+ function void init() {
+ }
+
+ /**
+ * Returns the character of the currently pressed key on the keyboard;
+ * if no key is currently pressed, returns 0.
+ *
+ * Recognizes all ASCII characters, as well as the following keys:
+ * new line = 128 = String.newline()
+ * backspace = 129 = String.backspace()
+ * left arrow = 130
+ * up arrow = 131
+ * right arrow = 132
+ * down arrow = 133
+ * home = 134
+ * End = 135
+ * page up = 136
+ * page down = 137
+ * insert = 138
+ * delete = 139
+ * ESC = 140
+ * F1 - F12 = 141 - 152
+ */
+ function char keyPressed() {
+ }
+
+ /** Waits until a key is pressed on the keyboard and released,
+ * then echoes the key to the screen, and returns the character
+ * of the pressed key. */
+ function char readChar() {
+ }
+
+ /** Displays the message on the screen, reads from the keyboard the entered
+ * text until a newline character is detected, echoes the text to the screen,
+ * and returns its value. Also handles user backspaces. */
+ function String readLine(String message) {
+ }
+
+ /** Displays the message on the screen, reads from the keyboard the entered
+ * text until a newline character is detected, echoes the text to the screen,
+ * and returns its integer value (until the first non-digit character in the
+ * entered text is detected). Also handles user backspaces. */
+ function int readInt(String message) {
+ }
+}
diff --git a/original/projects/12/KeyboardTest/KeyboardTestOutput.png b/original/projects/12/KeyboardTest/KeyboardTestOutput.png
new file mode 100644
index 0000000..ad7f798
Binary files /dev/null and b/original/projects/12/KeyboardTest/KeyboardTestOutput.png differ
diff --git a/original/projects/12/KeyboardTest/Main.jack b/original/projects/12/KeyboardTest/Main.jack
new file mode 100644
index 0000000..59ae501
--- /dev/null
+++ b/original/projects/12/KeyboardTest/Main.jack
@@ -0,0 +1,93 @@
+// 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/KeyboardTest/Main.jack
+
+/** Test program for the OS Keyboard class. */
+class Main {
+
+ /** Gets input from the user and verifies its contents. */
+ function void main() {
+ var char c, key;
+ var String s;
+ var int i;
+ var boolean ok;
+
+ let ok = false;
+ do Output.printString("keyPressed test:");
+ do Output.println();
+ while (~ok) {
+ do Output.printString("Please press the 'space' key");
+ while (key = 0) {
+ let key = Keyboard.keyPressed();
+ }
+ let c = key;
+ while (~(key = 0)) {
+ let key = Keyboard.keyPressed();
+ }
+
+ do Output.println();
+
+ if (c = 32) {
+ do Output.printString("ok");
+ do Output.println();
+ let ok = true;
+ }
+ }
+
+ let ok = false;
+ do Output.printString("readChar test:");
+ do Output.println();
+ do Output.printString("(Verify that the pressed character is echoed to the screen)");
+ do Output.println();
+ while (~ok) {
+ do Output.printString("Please press the number '3': ");
+ let c = Keyboard.readChar();
+
+ do Output.println();
+
+ if (c = 51) {
+ do Output.printString("ok");
+ do Output.println();
+ let ok = true;
+ }
+ }
+
+ let ok = false;
+ do Output.printString("readLine test:");
+ do Output.println();
+ do Output.printString("(Verify echo and usage of 'backspace')");
+ do Output.println();
+ while (~ok) {
+ let s = Keyboard.readLine("Please type 'JACK' and press enter: ");
+
+ if (s.length() = 4) {
+ if ((s.charAt(0) = 74) & (s.charAt(1) = 65) & (s.charAt(2) = 67) & (s.charAt(3) = 75)) {
+ do Output.printString("ok");
+ do Output.println();
+ let ok = true;
+ }
+ }
+ }
+
+ let ok = false;
+ do Output.printString("readInt test:");
+ do Output.println();
+ do Output.printString("(Verify echo and usage of 'backspace')");
+ do Output.println();
+ while (~ok) {
+ let i = Keyboard.readInt("Please type '-32123' and press enter: ");
+
+ if (i = (-32123)) {
+ do Output.printString("ok");
+ do Output.println();
+ let ok = true;
+ }
+ }
+
+ do Output.println();
+ do Output.printString("Test completed successfully");
+
+ return;
+ }
+}
diff --git a/original/projects/12/Math.jack b/original/projects/12/Math.jack
new file mode 100644
index 0000000..446df75
--- /dev/null
+++ b/original/projects/12/Math.jack
@@ -0,0 +1,49 @@
+// 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/Math.jack
+/**
+ * A library of commonly used mathematical functions.
+ * All functions runs in O(n), where n is the number of bits used
+ * for representing a two's complement integer value (16 in the Hack computer).
+ * Note: Jack compilers implement multiplication and division
+ * using calls to OS functions in this class.
+ */
+class Math {
+ static int n; // Number of bits used for representing a two's complement integer
+ static Array powersOfTwo; // Stores 2^0, 2^1, 2^2,..., 2^(n-1)
+
+ // Initializes the Math library.
+ function void init() {
+ }
+
+ /** Returns the product of x and y.
+ * When a Jack compiler detects the multiplication operator '*'
+ * in an expression, it handles it by invoking this method.
+ * Thus, in Jack, x * y and Math.multiply(x,y) return the same value. */
+ function int multiply(int x, int y) {
+ }
+
+ /** Returns the integer part of x / y.
+ * When a Jack compiler detects the division operator '/'
+ * an an expression, it handles it by invoking this method.
+ * Thus, x/y and Math.divide(x,y) return the same value. */
+ function int divide(int x, int y) {
+ }
+
+ /** Returns the integer part of the square root of x. */
+ function int sqrt(int x) {
+ }
+
+ /** Returns the greater value. */
+ function int max(int a, int b) {
+ }
+
+ /** Returns the smaller value. */
+ function int min(int a, int b) {
+ }
+
+ /** Returns the absolute value of x. */
+ function int abs(int x) {
+ }
+}
diff --git a/original/projects/12/MathTest/Main.jack b/original/projects/12/MathTest/Main.jack
new file mode 100644
index 0000000..a35c730
--- /dev/null
+++ b/original/projects/12/MathTest/Main.jack
@@ -0,0 +1,34 @@
+// 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/MathTest/Main.jack
+
+// Tests the OS Math class.
+class Main {
+
+ // Performs various mathematical operations, using calls to the Math class methods.
+ function void main() {
+ var Array r; // Stores the test results;
+ let r = 8000; // Base address
+
+ let r[0] = 2 * 3; // 6
+ let r[1] = r[0] * (-30); // 6 * (-30) = -180
+ let r[2] = r[1] * 100; // (-180) * 100 = -18000
+ let r[3] = 1 * r[2]; // 1 * (-18000) = -18000
+ let r[4] = r[3] * 0; // 0
+
+ let r[5] = 9 / 3; // 3
+ let r[6] = (-18000) / 6; // -3000
+ let r[7] = 32766 / (-32767); // (2^15 - 2) / (2^15 - 1) = 0
+
+ let r[8] = Math.sqrt(9); // 3
+ let r[9] = Math.sqrt(32767); // 181
+
+ let r[10] = Math.min(345, 123); // 123
+ let r[11] = Math.max(123, -345); // 123
+ let r[12] = Math.abs(27); // 27
+ let r[13] = Math.abs(-32767); // 32767
+
+ return;
+ }
+}
\ No newline at end of file
diff --git a/original/projects/12/MathTest/MathTest.cmp b/original/projects/12/MathTest/MathTest.cmp
new file mode 100644
index 0000000..703c1be
--- /dev/null
+++ b/original/projects/12/MathTest/MathTest.cmp
@@ -0,0 +1,2 @@
+|RAM[8000]|RAM[8001]|RAM[8002]|RAM[8003]|RAM[8004]|RAM[8005]|RAM[8006]|RAM[8007]|RAM[8008]|RAM[8009]|RAM[8010]|RAM[8011]|RAM[8012]|RAM[8013]|
+| 6 | -180 | -18000 | -18000 | 0 | 3 | -3000 | 0 | 3 | 181 | 123 | 123 | 27 | 32767 |
diff --git a/original/projects/12/MathTest/MathTest.tst b/original/projects/12/MathTest/MathTest.tst
new file mode 100644
index 0000000..127dbb4
--- /dev/null
+++ b/original/projects/12/MathTest/MathTest.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/MathTest/MathTest.tst
+
+load,
+output-file MathTest.out,
+compare-to MathTest.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 RAM[8006]%D2.6.1 RAM[8007]%D2.6.1 RAM[8008]%D2.6.1 RAM[8009]%D2.6.1 RAM[8010]%D2.6.1 RAM[8011]%D2.6.1 RAM[8012]%D2.6.1 RAM[8013]%D2.6.1;
+
+repeat 1000000 {
+ vmstep;
+}
+
+output;
diff --git a/original/projects/12/Memory.jack b/original/projects/12/Memory.jack
new file mode 100644
index 0000000..8a853fa
--- /dev/null
+++ b/original/projects/12/Memory.jack
@@ -0,0 +1,33 @@
+// 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/Memory.jack
+/**
+ * This library provides two services: direct access to the computer's main
+ * memory (RAM), and allocation and recycling of memory blocks. The Hack RAM
+ * consists of 32,768 words, each holding a 16-bit binary number.
+ */
+class Memory {
+
+ /** Initializes the class. */
+ function void init() {
+ }
+
+ /** Returns the RAM value at the given address. */
+ function int peek(int address) {
+ }
+
+ /** Sets the RAM value at the given address to the given value. */
+ function void poke(int address, int value) {
+ }
+
+ /** Finds an available RAM block of the given size and returns
+ * a reference to its base address. */
+ function int alloc(int size) {
+ }
+
+ /** De-allocates the given object (cast as an array) by making
+ * it available for future allocations. */
+ function void deAlloc(Array o) {
+ }
+}
diff --git a/original/projects/12/MemoryTest/Main.jack b/original/projects/12/MemoryTest/Main.jack
new file mode 100644
index 0000000..a9817f4
--- /dev/null
+++ b/original/projects/12/MemoryTest/Main.jack
@@ -0,0 +1,53 @@
+// 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, err;
+ 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 err = 0;
+ let b = Array.new(3);
+ let b[1] = a[2] - 100;
+ if (b = a) { // Fail compare if b = a
+ let err = 1; }
+ do Memory.poke(8003, b[1] + err); // RAM[8003] = 122
+
+ let err = 0;
+ let c = Array.new(500);
+ let c[499] = a[2] - b[1];
+ if (c = a) { // Fail compare if c = a
+ let err = 1; }
+ if (c = b) { // Fail compare if c = b
+ let err = err + 10; }
+ do Memory.poke(8004, c[499]+err); // RAM[8004] = 100
+
+ do a.dispose(); // uses Memory.deAlloc
+ do b.dispose();
+
+ let err = 0;
+ let b = Array.new(3);
+ let b[0] = c[499] - 90;
+ if (b = c) { // Fail compare if b = c
+ let err = 1; }
+ do Memory.poke(8005, b[0] + err); // RAM[8005] = 10
+
+ do c.dispose();
+ do b.dispose();
+
+ return;
+ }
+}
diff --git a/original/projects/12/MemoryTest/MemoryDiag/Main.jack b/original/projects/12/MemoryTest/MemoryDiag/Main.jack
new file mode 100644
index 0000000..de439d0
--- /dev/null
+++ b/original/projects/12/MemoryTest/MemoryDiag/Main.jack
@@ -0,0 +1,183 @@
+// 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 {
+
+ /** Test Memory.peek(), poke(), alloc() and deAlloc().
+ *
+ * This test is also a diagnostic. RAM[17000] is incremented before and
+ * after every call so that the failure point can be accurately determined
+ * when using command line testing. Return values from all alloc() calls
+ * are also stored in the test results to aid debugging.
+ */
+ function void main() {
+ var int temp;
+ var Array a, b, c, out;
+
+ let out = 17000; // Address where test results will be stored.
+
+ // Test poke() and peek().
+
+ let out[0] = 10; // poke test
+ do Memory.poke(out + 1, 333); // RAM[17001] = 333
+
+ let out[0] = 11; // peek test
+ let temp = Memory.peek(out + 1);
+ let out[2] = temp + 1; // RAM[17002] = 334
+ let out[0] = 12; // peek/poke test complete
+
+ // Allocate a memory block.
+ // Validate that the returned block is entirely within the heap,
+ // Test aborts if the block is not valid.
+
+ let out[0] = 20;
+ let a = Memory.alloc(20);
+ let out[3] = a; // RAM[17003] = block address
+
+ let out[0] = 21;
+ do Main.checkRange(a, 20);
+ let out[0] = 22;
+
+ // Allocate a SMALLER memory block.
+ // Validate that the returned block is entirely within the heap,
+ // and that it does not overlap block 'a'.
+ // Test aborts if the block is not valid or overlaps.
+ //
+ // Common failure: first block was not removed from free list so space
+ // for this block was found within the first block.
+
+ let out[0] = 30;
+ let b = Memory.alloc(3);
+ let out[4] = b; // RAM[17004] = block address
+
+ let out[0] = 31;
+ do Main.checkRange(b, 3);
+ let out[0] = 32;
+ do Main.checkOverlap(b, 3, a, 3);
+ let out[0] = 33;
+
+ // Allocate a memory block.
+ // Validate that the returned block is entirely within the heap,
+ // and that it does not overlap blocks 'a' or 'b'.
+ // Test aborts if the block is not valid or overlaps.
+
+ let out[0] = 40;
+ let c = Memory.alloc(500);
+ let out[5] = c; // RAM[17005] = block address
+
+ let out[0] = 41;
+ do Main.checkRange(c, 500);
+ let out[0] = 42;
+ do Main.checkOverlap(c, 500, a, 3);
+ let out[0] = 43;
+ do Main.checkOverlap(c, 500, b, 3);
+ let out[0] = 44;
+
+ // Deallocate blocks 'a' and 'b', retaining 'c'.
+ //
+ // Common failure: free list corrupted by deAlloc().
+
+ let out[0] = 50;
+ do Memory.deAlloc(a);
+
+ let out[0] = 51;
+ do Memory.deAlloc(b);
+ let out[0] = 52;
+
+ // Allocate a memory block.
+ // Validate that the returned block is entirely within the heap,
+ // and that it does not overlap blocks 'c'.
+ // Test aborts if the block is not valid or overlaps.
+ //
+ // Common failure: free list corrupted by deAlloc().
+
+ let out[0] = 60;
+ let b = Memory.alloc(3);
+ let out[6] = b; // RAM[17006] = block address
+
+ let out[0] = 61;
+ do Main.checkRange(b, 3);
+ let out[0] = 62;
+ do Main.checkOverlap(b, 3, c, 500);
+ let out[0] = 63;
+
+ // Deallocate blocks 'b' and 'c'.
+
+ let out[0] = 70;
+ do Memory.deAlloc(c);
+
+ let out[0] = 71;
+ do Memory.deAlloc(b);
+ let out[0] = 72;
+
+ // Test that deallocated blocks are placed on the free list and can
+ // be reused.
+
+ let out[0] = 70;
+ let a = Memory.alloc(8000);
+ let out[7] = a; // RAM[17007] = block address
+
+ let out[0] = 71;
+ do Main.checkRange(a, 8000);
+
+ let out[0] = 72;
+ do Memory.deAlloc(a);
+
+ let out[0] = 73;
+ let a = Memory.alloc(7000);
+
+ let out[0] = 74;
+ do Main.checkRange(a, 7000);
+
+ let out[0] = 75;
+ do Memory.deAlloc(a);
+ let out[8] = a; // RAM[17008] = block address
+
+ // Test complete.
+ let out[0] = 100;
+
+ // At this point all allocated blocks have been deallocated.
+ //
+ // You can inspect the free list and confirm that all of the heap is
+ // contained in the free segments.
+ //
+ // If you implemented defragmentation in dealloc(), the free list
+ // should contain only one segment, consisting of the entire heap.
+
+ return;
+ }
+
+
+ /** Check that block a(a_len) is in the heap.
+ *
+ * If the block begins or ends outside of the heap, calls Sys.halt()
+ */
+ function void checkRange(int a, int a_len) {
+ var int a_high;
+ let a_high = (a + a_len)-1;
+ if ((a < 2048) | ((a_high) > 16383)) {
+ // Block is not entirely within heap.
+ do Sys.halt();
+ }
+ return;
+ }
+
+ /** Check that block a(a_len) does not overlap block b(b_len).
+ * Assumes that both blocks have been range checked.
+ *
+ * If the blocks overlap, calls Sys.halt()
+ */
+ function void checkOverlap(int a, int a_len, int b, int b_len) {
+ var int a_high, b_high;
+ let a_high = (a + a_len)-1;
+ let b_high = (b + b_len)-1;
+ if ( ~ ((a > b_high) | (a_high < b))) {
+ // Block overlaps excluded range.
+ do Sys.halt();
+ }
+ return;
+ }
+}
diff --git a/original/projects/12/MemoryTest/MemoryDiag/MemoryDiag.cmp b/original/projects/12/MemoryTest/MemoryDiag/MemoryDiag.cmp
new file mode 100644
index 0000000..808e2ce
--- /dev/null
+++ b/original/projects/12/MemoryTest/MemoryDiag/MemoryDiag.cmp
@@ -0,0 +1,2 @@
+|RAM[17000|RAM[17001|RAM[17002|RAM[17003|RAM[17004|RAM[17005|RAM[17006|RAM[17007|RAM[17008|
+| 100 | 333 | 334 |*********|*********|*********|*********|*********|*********|
diff --git a/original/projects/12/MemoryTest/MemoryDiag/MemoryDiag.tst b/original/projects/12/MemoryTest/MemoryDiag/MemoryDiag.tst
new file mode 100644
index 0000000..94cd921
--- /dev/null
+++ b/original/projects/12/MemoryTest/MemoryDiag/MemoryDiag.tst
@@ -0,0 +1,18 @@
+// 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/MemoryDiag/MemoryDiag.tst
+
+echo "At the end of this test it is normal to see some pixels set on the screen";
+load,
+output-file MemoryDiag.out,
+compare-to MemoryDiag.cmp,
+output-list RAM[17000]%D2.6.1 RAM[17001]%D2.6.1 RAM[17002]%D2.6.1
+ RAM[17003]%D2.6.1 RAM[17004]%D2.6.1 RAM[17005]%D2.6.1 RAM[17006]%D2.6.1
+ RAM[17007]%D2.6.1 RAM[17008]%D2.6.1;
+
+repeat 1000000 {
+ vmstep;
+}
+
+output;
diff --git a/original/projects/12/MemoryTest/MemoryDiag/README.html b/original/projects/12/MemoryTest/MemoryDiag/README.html
new file mode 100644
index 0000000..587847e
--- /dev/null
+++ b/original/projects/12/MemoryTest/MemoryDiag/README.html
@@ -0,0 +1,55 @@
+
+
MemoryDiag is both a pass/fail test and a diagnostic.
+
+MemoryDiag tests the following:
+
+
Memory.peek() and Memory.poke() read from and write to the specified memory address.
+
Memory.alloc() returns RAM blocks that are fully contained within the heap address range 2048-16383.
+
Memory.alloc() does not return RAM blocks that overlap each other.
+
RAM blocks deallocated by Memory.deAlloc() are made available for Memory.alloc() to reuse.
+
+The block reuse test allocates and deallocates an 8000 word block. It then tries to allocates a 7000 word block which must be allocated from the deallocated 8000 word block. If the 8000 word block is not available for reuse, there will only be about 6300 words available in the heap so you will get an ERR6.
+
+At the end of this test it is normal to see some pixels set on the screen. This is because the results of the test are written to RAM[17000] – RAM[17008] which is in the Screen memory. MemoryDiag does not put its results in the first 16K of RAM because it must not interfere with the Memory.jack that is being tested.
+
+
+
Using MemoryDiag as a diagnostic
+
+RAM[17000] is set to a unique value before every system call and address validation. This allows the exact failure location in the test to be identified when automated testing is used. At the end of the test, RAM[17000] is set to 100.
+
+When the test fails to compare, look at the MemoryDiag.out file and note the RAM[17000] value. This is the test step that failed. Look through the Main.jack code and find the corresponding
+ let out[0] = step;
+statement. The function immediately following this statement is where the failure occurred.
+
+For example, if RAM[17000] is 51, the
+ do Memory.deAlloc(b);
+call did not return. Either there was a simulation error like a bad address or deAlloc() got stuck in a loop.
+
+
+
Sample MemoryDiag output files
+
+Note that RAM[17003] – RAM[17008] are "don't care" values in the MemoryDiag.cmp file.
+
+NestedCall.tst is an intermediate test (in terms of complexity) intended to be used between the SimpleFunction and
+FibonacciElement tests. It may be useful when SimpleFunction passes but FibonacciElement fails or crashes. NestedCall also
+tests several requirements of the Function Calling Protocol that are not verified by the other
+supplied tests. NestedCall can be used with or without the VM bootstrap code.
+
+NestedCallVME.tst runs the same test on the VM Emulator.
+
+The NestedCall tests and supporting documentation were written by Mark Armbrust.
+
+
+
Test Structure
+
Startup
+NestedCall is implemented entirely within the Sys.vm file. The first function in Sys.vm is
+Sys.init(). This allows it to be used before the bootstrap code has been added to the VM Translator
+since there will be no file processing order issues.
+
+NestedCall loads Sys.asm, sets up the stack to simulate the bootstrap's call to Sys.init(), then
+begins execution at the beginning of Sys.asm. If the bootstrap is not present, the program begins
+running with Sys.init() since it is the first function in Sys.vm.
+
+If Sys.asm includes the bootstrap, the bootstrap will (re)initialize the stack and call Sys.init(),
+so the test should see the same environment either way it gets to Sys.init().
+
+
Sys.init()
+
+THIS and THAT are set to known values so that context save and restore can be tested.
+
+Sys.init() calls Sys.main() and stores the return value in temp 1. This tests call to and
+return from a function with no arguments.
+
+
Sys.main()
+Sys.init() allocates 5 local variables. It sets local 1, local 2 and
+local 3. local 0 and local 4 are intentionally not set.
+
+THIS and THAT are changed so that context save and restore can be tested.
+
+Sys.main() calls Sys.add12(123) and stores the return value in temp 0. This tests call to and
+return from a function with arguments.
+
+After Sys.add12() returns, Sys.main() sums local 0 through local 4 and returns the
+result. This tests that the local segment was properly allocated on the stack and that the local
+variables were not overwritten by the call to Sys.main(). It also tests that local 0 and
+local 4 were properly initialized to 0.
+
+
Sys.add12()
+
+THIS and THAT are set to known values so that context save and restore can be tested.
+
+Returns argument 0 plus 12.
+
+
+
Test Coverage
+
+
+Functions with no arguments return to correct RIP (Return Instruction Point) with correct return value on stack.
+This can fail if the RIP is not correctly pushed on the stack by the calling code, or if the returning
+code does not store the RIP in a temporary register before overwriting it with the return value.
+
+
+Functions with arguments return to correct RIP with correct return value on stack.
+This can fail if it is assumed that ARG points to the RIP.
+
+
+Functions with local variables allocate space on the stack for the local variables.
+This can fail if the function prologue is not written or if the SP is not updated after zeroing
+the local variables.
+
+
+All local variables are initialized to 0.
+Common errors are to forget this completely, or for the zeroing loop to be off by one.
+
+
+THIS and THAT are correctly retained across function calls. Looking ahead, in Project 9 you will be asked to write a simple computer game in the high-level Jack language. You can run your game (following compilation) on the supplied VM Emulator. But, if you choose to translate the VM code that the compiler generates using your VM Translator, then code like
+"push THIS, push THAT ... pop THIS, pop THAT" can cause some interesting failures!
+
+
+
Debugging
+These comments assume that your VM translator has passed the SimpleFunction test.
+
+If RAM[0] is incorrect, you have a stack skew. More data was pushed onto the stack by
+call than was popped by return, or vice versa. See debugging with
+breakpoints later in this section.
+
+If one or more of RAM[1] through RAM[4] is incorrect, the LCL,
+ARG, THIS and THAT pointers are not being correctly saved or restored.
+Most likely problem is when they are being saved; the SimpleFunction test verified that
+return restored them correctly.
+
+If RAM[5] is incorrect there may be a problem with setting up the ARG pointer.
+
+If RAM[4] is incorrect and RAM[5] is correct, there may be a problem with
+allocation or initialization of local variables.
+
+
Debugging with breakpoints
+
+To find tough bugs you can use the "breakpoint" facility in the CPU Emulator (red flag button).
+You can use breakpoints to have you program stop when it gets to a particular RAM address. For
+example:
+ • load the NestedCall.tst file,
+ • set a PC breakpoint at the ROM address for (Sys.main),
+ • hit the run button.
+When the CPU Emulator stops at the breakpoint you can inspect the RAM to check the stack and pointers values.
+(If the breakpoint isn't hit, you will need to to single-step debug through
+your calling code to see why it didn't get there.)
+
+Other useful places to set breakpoints are the entry points to the other functions and at the
+first and final instructions generated for return commands.
+
+NestedCallStack.html shows the expected stack values at various points
+during the test.
+
+
Finding ROM address in your ASM code
+It is not easy to find the ROM locations where you want to set breakpoints, because there is no
+one-to-one correspondence between the ASM file line numbers and the ROM addresses. This is made even more
+difficult because the supplied CPU Emulator does not display the (LABELS) in its ROM panel.
+
+There are two things that you can do to make this easier.
+
+
Modify your assembler to generate a listing file.
+A listing file shows all the ASM source lines, including comments, as well as the ROM addresses and
+the values of the labels and the instructions. For example, here is a snippet of a listing file generated by an assembler written by Mark Armbrust:
+
+ 20 16 @i // i -= 1
+ 21 FC88 M=M-1
+
+ 22 FC10 D=M // if i > 0
+ 23 6 @LOOP
+ 24 E301 D;JGT // goto LOOP
+
+ 25 (STOP)
+ 25 25 @STOP
+ 26 EA87 0;JMP
+
+Data Symbols
+
+ 16 D i
+
+Code Symbols
+
+ 6 C LOOP
+ 17 C SKIP
+ 25 C STOP
+
+For the Nand2Tetris environment, it is most useful to list the ROM addresses and A-instruction
+values in decimal. In the above snippet, the C-instruction values are
+listed in hexadecimal.
+
+The list file is generated during pass 2 of the Assembler, parallel to generating the .hack file. To
+make it easier to handle blank and comment only lines, Mark has Parser.commandType() return
+NO_COMMAND for source lines with no command. Mark also added Parser.sourceLine() that returns the
+unmodified source line.
+
+
Have your VM Translator write the VM source lines as comments in the ASM output.
+For example:
+
+ // label LOOP
+(Sys.init$LOOP)
+ // goto LOOP
+@Sys.init$LOOP
+0;JMP
+ //
+ // // Sys.main()
+ //
+ // // Sets locals 1, 2 and 3, leaving locals 0 and 4 unchanged to test
+ // // default local initialization to 0. (RAM set to -1 by test setup.)
+ // // Calls Sys.add12(123) and stores return value (135) in temp 0.
+ // // Returns local 0 + local 1 + local 2 + local 3 + local 4 (456) to confirm
+ // // that locals were not mangled by function call.
+ //
+ // function Sys.main 5
+(Sys.main)
+@5
+D=-A
+($3)
+@SP
+
+Note that comments in the VM source become double comments. Looking ahead, in Project 11 you will be asked to write a compiler for the Jack language. If your compiler will write the Jack source lines as comments in the
+generated VM files, this convention will be quite useful.
+
+
+
\ No newline at end of file
diff --git a/original/projects/8/FunctionCalls/NestedCall/NestedCall.tst b/original/projects/8/FunctionCalls/NestedCall/NestedCall.tst
new file mode 100644
index 0000000..be9cf4f
--- /dev/null
+++ b/original/projects/8/FunctionCalls/NestedCall/NestedCall.tst
@@ -0,0 +1,69 @@
+// Tests how the VM implementation handles function-call-and-return,
+// by executing the functions in Sys.vm.
+// In particular, loads and runs NestedCall.asm, which results when
+// the VM translator is applied to the NestedCall folder, which
+// includes only one VM file: Sys.vm.
+
+load NestedCall.asm,
+output-file NestedCall.out,
+compare-to NestedCall.cmp,
+
+set RAM[0] 261,
+set RAM[1] 261,
+set RAM[2] 256,
+set RAM[3] -3,
+set RAM[4] -4,
+set RAM[5] -1, // test results
+set RAM[6] -1,
+set RAM[256] 1234, // fake stack frame from call Sys.init
+set RAM[257] -1,
+set RAM[258] -2,
+set RAM[259] -3,
+set RAM[260] -4,
+
+set RAM[261] -1, // Initializes the stack, to check that the local segment
+set RAM[262] -1, // is initialized to zeros by the 'function' VM command.
+set RAM[263] -1,
+set RAM[264] -1,
+set RAM[265] -1,
+set RAM[266] -1,
+set RAM[267] -1,
+set RAM[268] -1,
+set RAM[269] -1,
+set RAM[270] -1,
+set RAM[271] -1,
+set RAM[272] -1,
+set RAM[273] -1,
+set RAM[274] -1,
+set RAM[275] -1,
+set RAM[276] -1,
+set RAM[277] -1,
+set RAM[278] -1,
+set RAM[279] -1,
+set RAM[280] -1,
+set RAM[281] -1,
+set RAM[282] -1,
+set RAM[283] -1,
+set RAM[284] -1,
+set RAM[285] -1,
+set RAM[286] -1,
+set RAM[287] -1,
+set RAM[288] -1,
+set RAM[289] -1,
+set RAM[290] -1,
+set RAM[291] -1,
+set RAM[292] -1,
+set RAM[293] -1,
+set RAM[294] -1,
+set RAM[295] -1,
+set RAM[296] -1,
+set RAM[297] -1,
+set RAM[298] -1,
+set RAM[299] -1,
+
+repeat 4000 {
+ ticktock;
+}
+
+output-list RAM[0]%D1.6.1 RAM[1]%D1.6.1 RAM[2]%D1.6.1 RAM[3]%D1.6.1 RAM[4]%D1.6.1 RAM[5]%D1.6.1 RAM[6]%D1.6.1;
+output;
diff --git a/original/projects/8/FunctionCalls/NestedCall/NestedCallStack.html b/original/projects/8/FunctionCalls/NestedCall/NestedCallStack.html
new file mode 100644
index 0000000..70582b6
--- /dev/null
+++ b/original/projects/8/FunctionCalls/NestedCall/NestedCallStack.html
@@ -0,0 +1,306 @@
+
+
+
+
+ NestedCall.tst — Stack Frames
+
+
+
+
+
+
+
+
+
Bootstrap init
+
Pointers
+
0
256
SP
+
1
-1
LCL
+
2
-2
ARG
+
3
-3
THIS
+
4
-4
THAT
+
Stack
+
256
???
←SP
+
+ This is how my bootstrap code initializes the pointers before calling Sys.init().
+
+ Setting the LCL, ARG, THIS and THAT pointers to known illegal values helps identify
+ when a pointer is used before it is initialized.
+
+ (If you are running the NestedCall test without bootstrap code, you will not see this state.)
+
+
+
+
Entry to Sys.init()
+
Pointers
+
0
261
SP
+
1
261
LCL
+
2
256
ARG
+
3
-3
THIS
+
4
-4
THAT
+
Stack
+
256
*
Return IP
←ARG
+
257
-1
Saved LCL
+
258
-2
Saved ARG
Sys.init
+
259
-3
Saved THIS
frame
+
260
-4
Saved THAT
+
261
???
←LCL, SP
+
+ This is how NestedCall.tst initializes the pointers and stack. This is what RAM looks
+ like after my bootstrap calls Sys.init().
+
+ (If your VM translation includes the bootstrap, the -1 through -4 values may be
+ different if your bootstrap initializes them.)
+
+
+
+
Entry to Sys.main()
+
Pointers
+
0
266
SP
+
1
266
LCL
+
2
261
ARG
+
3
4000
THIS
+
4
5000
THAT
+
Stack
+
256
*
Return IP
+
257
-1
Saved LCL
+
258
-2
Saved ARG
Sys.init
+
259
-3
Saved THIS
frame
+
260
-4
Saved THAT
+
261
*
Return IP
←ARG
+
262
261
Saved LCL
+
263
256
Saved ARG
Sys.main
+
264
4000
Saved THIS
frame
+
265
5000
Saved THAT
+
266
???
←LCL, SP
+
+
+
+
After Sys.main() prologue
+
Pointers
+
0
271
SP
+
1
266
LCL
+
2
261
ARG
+
3
4000
THIS
+
4
5000
THAT
+
Stack
+
256
*
Return IP
+
257
-1
Saved LCL
+
258
-2
Saved ARG
Sys.init
+
259
-3
Saved THIS
frame
+
260
-4
Saved THAT
+
261
*
Return IP
←ARG
+
262
261
Saved LCL
+
263
256
Saved ARG
Sys.main
+
264
4000
Saved THIS
frame
+
265
5000
Saved THAT
+
266
0
local 0
←LCL
+
267
0
local 1
+
268
0
local 2
+
269
0
local 3
+
270
0
local 4
+
271
???
←SP
+
+ The function prologue is the assembly language code generated for the
+ "function" VM command.
+
+
+
+
Entry to Sys.add12(123)
+
Pointers
+
0
277
SP
+
1
277
LCL
+
2
271
ARG
+
3
4001
THIS
+
4
5001
THAT
+
Stack
+
256
*
Return IP
+
257
-1
Saved LCL
+
258
-2
Saved ARG
Sys.init
+
259
-3
Saved THIS
frame
+
260
-4
Saved THAT
+
261
*
Return IP
+
262
261
Saved LCL
+
263
256
Saved ARG
Sys.main
+
264
4000
Saved THIS
frame
+
265
5000
Saved THAT
+
266
0
local 0
+
267
200
local 1
+
268
40
local 2
+
269
6
local 3
+
270
0
local 4
+
271
123
argument 0
←ARG
+
272
*
Return IP
+
273
266
Saved LCL
Sys.add12
+
274
261
Saved ARG
frame
+
275
4001
Saved THIS
+
276
5001
Saved THAT
+
277
???
←LCL, SP
+
+
+
+
+
+
+
+
+
+
+
Before Sys.add12() return
+
Pointers
+
0
278
SP
+
1
277
LCL
+
2
271
ARG
+
3
4002
THIS
+
4
5002
THAT
+
Stack
+
256
*
Return IP
+
257
-1
Saved LCL
+
258
-2
Saved ARG
Sys.init
+
259
-3
Saved THIS
frame
+
260
-4
Saved THAT
+
261
*
Return IP
+
262
261
Saved LCL
+
263
256
Saved ARG
Sys.main
+
264
4000
Saved THIS
frame
+
265
5000
Saved THAT
+
266
0
local 0
+
267
200
local 1
+
268
40
local 2
+
269
6
local 3
+
270
0
local 4
+
271
123
argument 0
←ARG
+
272
*
Return IP
+
273
266
Saved LCL
Sys.add12
+
274
261
Saved ARG
frame
+
275
4001
Saved THIS
+
276
5001
Saved THAT
+
277
135
Return value
←LCL
+
278
???
←SP
+
+
+
+
After Sys.add12() return
+
Pointers
+
0
272
SP
+
1
266
LCL
+
2
261
ARG
+
3
4001
THIS
+
4
5001
THAT
+
Stack
+
256
*
Return IP
+
257
-1
Saved LCL
+
258
-2
Saved ARG
Sys.init
+
259
-3
Saved THIS
frame
+
260
-4
Saved THAT
+
261
*
Return IP
←ARG
+
262
261
Saved LCL
+
263
256
Saved ARG
Sys.main
+
264
4000
Saved THIS
frame
+
265
5000
Saved THAT
+
266
0
local 0
←LCL
+
267
200
local 1
+
268
40
local 2
+
269
6
local 3
+
270
0
local 4
+
271
135
Return value
+
272
???
←SP
+
+
+
+
Before Sys.main() return
+
Pointers
+
0
272
SP
+
1
266
LCL
+
2
261
ARG
+
3
4001
THIS
+
4
5001
THAT
+
Stack
+
256
*
Return IP
+
257
-1
Saved LCL
+
258
-2
Saved ARG
Sys.init
+
259
-3
Saved THIS
frame
+
260
-4
Saved THAT
+
261
*
Return IP
←ARG
+
262
261
Saved LCL
+
263
256
Saved ARG
Sys.main
+
264
4000
Saved THIS
frame
+
265
5000
Saved THAT
+
266
0
local 0
←LCL
+
267
200
local 1
+
268
40
local 2
+
269
6
local 3
+
270
0
local 4
+
271
246
Return value
+
272
???
←SP
+
+
+
+
After Sys.main() return
+
Pointers
+
0
262
SP
+
1
261
LCL
+
2
256
ARG
+
3
4000
THIS
+
4
5000
THAT
+
Stack
+
256
*
Return IP
←ARG
+
257
-1
Saved LCL
+
258
-2
Saved ARG
Sys.init
+
259
-3
Saved THIS
frame
+
260
-4
Saved THAT
+
261
246
Return value
←LCL
+
262
???
←SP
+
+
+
+
In Sys.init() halt loop
+
Pointers
+
0
261
SP
+
1
261
LCL
+
2
256
ARG
+
3
4000
THIS
+
4
5000
THAT
+
Stack
+
256
*
Return IP
←ARG
+
257
-1
Saved LCL
+
258
-2
Saved ARG
Sys.init
+
259
-3
Saved THIS
frame
+
260
-4
Saved THAT
+
261
???
←LCL, SP
+
+
+
+
+
+
\ No newline at end of file
diff --git a/original/projects/8/FunctionCalls/NestedCall/NestedCallVME.tst b/original/projects/8/FunctionCalls/NestedCall/NestedCallVME.tst
new file mode 100644
index 0000000..05bea48
--- /dev/null
+++ b/original/projects/8/FunctionCalls/NestedCall/NestedCallVME.tst
@@ -0,0 +1,72 @@
+// Tests and illustrates how the VM implementation handles function-call-and-return,
+// by executing the functions in Sys.vm in the VM emulator.
+// In particular, loads and runs the functions in Sys.vm.
+
+load Sys.vm,
+output-file NestedCall.out,
+compare-to NestedCall.cmp,
+output-list RAM[0]%D1.6.1 RAM[1]%D1.6.1 RAM[2]%D1.6.1 RAM[3]%D1.6.1 RAM[4]%D1.6.1 RAM[5]%D1.6.1 RAM[6]%D1.6.1;
+
+set RAM[0] 261,
+set RAM[1] 261,
+set RAM[2] 256,
+set RAM[3] -3,
+set RAM[4] -4,
+set RAM[5] -1, // test results
+set RAM[6] -1,
+set RAM[256] 1234, // fake stack frame from call Sys.init
+set RAM[257] -1,
+set RAM[258] -2,
+set RAM[259] -3,
+set RAM[260] -4,
+
+set RAM[261] -1, // Initialize stack to check for local segment
+set RAM[262] -1, // being cleared to zero.
+set RAM[263] -1,
+set RAM[264] -1,
+set RAM[265] -1,
+set RAM[266] -1,
+set RAM[267] -1,
+set RAM[268] -1,
+set RAM[269] -1,
+set RAM[270] -1,
+set RAM[271] -1,
+set RAM[272] -1,
+set RAM[273] -1,
+set RAM[274] -1,
+set RAM[275] -1,
+set RAM[276] -1,
+set RAM[277] -1,
+set RAM[278] -1,
+set RAM[279] -1,
+set RAM[280] -1,
+set RAM[281] -1,
+set RAM[282] -1,
+set RAM[283] -1,
+set RAM[284] -1,
+set RAM[285] -1,
+set RAM[286] -1,
+set RAM[287] -1,
+set RAM[288] -1,
+set RAM[289] -1,
+set RAM[290] -1,
+set RAM[291] -1,
+set RAM[292] -1,
+set RAM[293] -1,
+set RAM[294] -1,
+set RAM[295] -1,
+set RAM[296] -1,
+set RAM[297] -1,
+set RAM[298] -1,
+set RAM[299] -1,
+
+set sp 261,
+set local 261,
+set argument 256,
+set this 3000,
+set that 4000;
+
+repeat 50 {
+ vmstep;
+}
+output;
diff --git a/original/projects/8/FunctionCalls/NestedCall/Sys.vm b/original/projects/8/FunctionCalls/NestedCall/Sys.vm
new file mode 100644
index 0000000..99325cf
--- /dev/null
+++ b/original/projects/8/FunctionCalls/NestedCall/Sys.vm
@@ -0,0 +1,57 @@
+// Sys.vm. Tested by the NestedCall test script.
+// Consists of three functions: Sys.init, Sys.main, and Sys.add12.
+
+// Calls Sys.main() and stores a return value in temp 1.
+// Does not return (enters infinite loop).
+// The VM implementation starts running the Sys.init function, by default.
+function Sys.init 0
+ push constant 4000 // tests that THIS and THAT are handled correctly
+ pop pointer 0
+ push constant 5000
+ pop pointer 1
+ call Sys.main 0
+ pop temp 1
+ label LOOP
+ goto LOOP
+
+// Sets locals 1, 2 and 3 to some values. Leaves locals 0 and 4 unchanged,
+// to test that the 'function' VM command initliazes them to 0 (the test
+// script sets them to -1 before this code starts running).
+// Calls Sys.add12(123) and stores the return value (should be 135) in temp 0.
+// Returns local 0 + local 1 + local 2 + local 3 + local 4 (should be 456), to
+// confirm that locals were not mangled by the function call.
+function Sys.main 5
+ push constant 4001
+ pop pointer 0
+ push constant 5001
+ pop pointer 1
+ push constant 200
+ pop local 1
+ push constant 40
+ pop local 2
+ push constant 6
+ pop local 3
+ push constant 123
+ call Sys.add12 1
+ pop temp 0
+ push local 0
+ push local 1
+ push local 2
+ push local 3
+ push local 4
+ add
+ add
+ add
+ add
+ return
+
+// Returns (argument 0) + 12.
+function Sys.add12 0
+ push constant 4002
+ pop pointer 0
+ push constant 5002
+ pop pointer 1
+ push argument 0
+ push constant 12
+ add
+ return
diff --git a/original/projects/8/FunctionCalls/SimpleFunction/SimpleFunction.cmp b/original/projects/8/FunctionCalls/SimpleFunction/SimpleFunction.cmp
new file mode 100644
index 0000000..c3ea911
--- /dev/null
+++ b/original/projects/8/FunctionCalls/SimpleFunction/SimpleFunction.cmp
@@ -0,0 +1,2 @@
+| RAM[0] | RAM[1] | RAM[2] | RAM[3] | RAM[4] |RAM[310]|
+| 311 | 305 | 300 | 3010 | 4010 | 1196 |
diff --git a/original/projects/8/FunctionCalls/SimpleFunction/SimpleFunction.tst b/original/projects/8/FunctionCalls/SimpleFunction/SimpleFunction.tst
new file mode 100644
index 0000000..a8b3430
--- /dev/null
+++ b/original/projects/8/FunctionCalls/SimpleFunction/SimpleFunction.tst
@@ -0,0 +1,37 @@
+// 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/8/FunctionCalls/SimpleFunction/SimpleFunction.tst
+
+// Tests SimpleFunction.asm in the CPU emulator.
+// In particular, tests how the assembly implementation of the 'function'
+// VM command initializes local variables, and how the assembly implementation
+// of the 'return' VM command handles the return value, SP, LCL, ARG, THIS, and THAT.
+// Before executing the code, initializes the stack pointer and the pointers of some
+// of the memory segments, and sets some values in the argument segment.
+
+load SimpleFunction.asm,
+output-file SimpleFunction.out,
+compare-to SimpleFunction.cmp,
+
+set RAM[0] 317, // SP
+set RAM[1] 317, // LCL
+set RAM[2] 310, // ARG
+set RAM[3] 3000, // THIS
+set RAM[4] 4000, // THAT
+set RAM[310] 1234,
+set RAM[311] 37,
+set RAM[312] 1000,
+set RAM[313] 305,
+set RAM[314] 300,
+set RAM[315] 3010,
+set RAM[316] 4010,
+
+repeat 300 {
+ ticktock;
+}
+
+// Outputs SP, LCL, ARG, THIS, THAT, and the return value.
+output-list RAM[0]%D1.6.1 RAM[1]%D1.6.1 RAM[2]%D1.6.1
+ RAM[3]%D1.6.1 RAM[4]%D1.6.1 RAM[310]%D1.6.1;
+output;
diff --git a/original/projects/8/FunctionCalls/SimpleFunction/SimpleFunction.vm b/original/projects/8/FunctionCalls/SimpleFunction/SimpleFunction.vm
new file mode 100644
index 0000000..8ef922f
--- /dev/null
+++ b/original/projects/8/FunctionCalls/SimpleFunction/SimpleFunction.vm
@@ -0,0 +1,18 @@
+// 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/8/FunctionCalls/SimpleFunction/SimpleFunction.vm
+
+// Performs a simple calculation and returns the result.
+// argument[0] and argument[1] must be set by the caller.
+
+function SimpleFunction.test 2
+ push local 0
+ push local 1
+ add
+ not
+ push argument 0
+ add
+ push argument 1
+ sub
+ return
\ No newline at end of file
diff --git a/original/projects/8/FunctionCalls/SimpleFunction/SimpleFunctionVME.tst b/original/projects/8/FunctionCalls/SimpleFunction/SimpleFunctionVME.tst
new file mode 100644
index 0000000..aa64892
--- /dev/null
+++ b/original/projects/8/FunctionCalls/SimpleFunction/SimpleFunctionVME.tst
@@ -0,0 +1,35 @@
+// 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/8/FunctionCalls/SimpleFunction/SimpleFunctionVME.tst
+
+// Tests and illustrates SimpleFunction.vm in the VM emulator.
+// Before executing the code, initializes the stack pointer
+// and the base addresses of some of the memory segments,
+// and sets some values in the argument segment.
+
+load SimpleFunction.vm,
+output-file SimpleFunction.out,
+compare-to SimpleFunction.cmp,
+
+set sp 317,
+set local 317,
+set argument 310,
+set this 3000,
+set that 4000,
+set argument[0] 1234,
+set argument[1] 37,
+set argument[2] 9,
+set argument[3] 305,
+set argument[4] 300,
+set argument[5] 3010,
+set argument[6] 4010,
+
+repeat 10 {
+ vmstep;
+}
+
+// Outputs SP, LCL, ARG, THIS, THAT, and the return value.
+output-list RAM[0]%D1.6.1 RAM[1]%D1.6.1 RAM[2]%D1.6.1
+ RAM[3]%D1.6.1 RAM[4]%D1.6.1 RAM[310]%D1.6.1;
+output;
diff --git a/original/projects/8/FunctionCalls/StaticsTest/Class1.vm b/original/projects/8/FunctionCalls/StaticsTest/Class1.vm
new file mode 100644
index 0000000..24826e6
--- /dev/null
+++ b/original/projects/8/FunctionCalls/StaticsTest/Class1.vm
@@ -0,0 +1,20 @@
+// 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/8/FunctionCalls/StaticsTest/Class1.vm
+
+// Stores two supplied arguments in static[0] and static[1].
+function Class1.set 0
+ push argument 0
+ pop static 0
+ push argument 1
+ pop static 1
+ push constant 0
+ return
+
+// Returns static[0] - static[1].
+function Class1.get 0
+ push static 0
+ push static 1
+ sub
+ return
diff --git a/original/projects/8/FunctionCalls/StaticsTest/Class2.vm b/original/projects/8/FunctionCalls/StaticsTest/Class2.vm
new file mode 100644
index 0000000..daa3622
--- /dev/null
+++ b/original/projects/8/FunctionCalls/StaticsTest/Class2.vm
@@ -0,0 +1,20 @@
+// 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/8/FunctionCalls/StaticsTest/Class2.vm
+
+// Stores two supplied arguments in static[0] and static[1].
+function Class2.set 0
+ push argument 0
+ pop static 0
+ push argument 1
+ pop static 1
+ push constant 0
+ return
+
+// Returns static[0] - static[1].
+function Class2.get 0
+ push static 0
+ push static 1
+ sub
+ return
diff --git a/original/projects/8/FunctionCalls/StaticsTest/StaticsTest.cmp b/original/projects/8/FunctionCalls/StaticsTest/StaticsTest.cmp
new file mode 100644
index 0000000..5589f1e
--- /dev/null
+++ b/original/projects/8/FunctionCalls/StaticsTest/StaticsTest.cmp
@@ -0,0 +1,2 @@
+| RAM[0] |RAM[261]|RAM[262]|
+| 263 | -2 | 8 |
diff --git a/original/projects/8/FunctionCalls/StaticsTest/StaticsTest.tst b/original/projects/8/FunctionCalls/StaticsTest/StaticsTest.tst
new file mode 100644
index 0000000..52af382
--- /dev/null
+++ b/original/projects/8/FunctionCalls/StaticsTest/StaticsTest.tst
@@ -0,0 +1,20 @@
+// 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/8/FunctionCalls/StaticsTest/StaticsTest.tst
+
+// Tests StaticTest.asm in the CPU emulator.
+// This assembly file results from translating the staticsTest folder.
+
+load StaticsTest.asm,
+output-file StaticsTest.out,
+compare-to StaticsTest.cmp,
+
+set RAM[0] 256,
+
+repeat 2500 {
+ ticktock;
+}
+
+output-list RAM[0]%D1.6.1 RAM[261]%D1.6.1 RAM[262]%D1.6.1;
+output;
diff --git a/original/projects/8/FunctionCalls/StaticsTest/StaticsTestVME.tst b/original/projects/8/FunctionCalls/StaticsTest/StaticsTestVME.tst
new file mode 100644
index 0000000..f9b70fb
--- /dev/null
+++ b/original/projects/8/FunctionCalls/StaticsTest/StaticsTestVME.tst
@@ -0,0 +1,19 @@
+// 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/8/FunctionCalls/StaticsTest/StaticsTestVME.tst
+
+// Tests and illustrates the statics test on the VM emulator.
+
+load, // loads all the VM files from the current folder
+output-file StaticsTest.out,
+compare-to StaticsTest.cmp,
+
+set sp 261,
+
+repeat 36 {
+ vmstep;
+}
+
+output-list RAM[0]%D1.6.1 RAM[261]%D1.6.1 RAM[262]%D1.6.1;
+output;
diff --git a/original/projects/8/FunctionCalls/StaticsTest/Sys.vm b/original/projects/8/FunctionCalls/StaticsTest/Sys.vm
new file mode 100644
index 0000000..00052da
--- /dev/null
+++ b/original/projects/8/FunctionCalls/StaticsTest/Sys.vm
@@ -0,0 +1,21 @@
+// 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/8/FunctionCalls/StaticsTest/Sys.vm
+
+// Tests that different functions, stored in two different
+// class files, manipulate the static segment correctly.
+
+function Sys.init 0
+ push constant 6
+ push constant 8
+ call Class1.set 2
+ pop temp 0 // dumps the return value
+ push constant 23
+ push constant 15
+ call Class2.set 2
+ pop temp 0 // dumps the return value
+ call Class1.get 0
+ call Class2.get 0
+label END
+ goto END
diff --git a/original/projects/8/ProgramFlow/BasicLoop/BasicLoop.cmp b/original/projects/8/ProgramFlow/BasicLoop/BasicLoop.cmp
new file mode 100644
index 0000000..00d35d2
--- /dev/null
+++ b/original/projects/8/ProgramFlow/BasicLoop/BasicLoop.cmp
@@ -0,0 +1,2 @@
+| RAM[0] |RAM[256]|
+| 257 | 6 |
diff --git a/original/projects/8/ProgramFlow/BasicLoop/BasicLoop.out b/original/projects/8/ProgramFlow/BasicLoop/BasicLoop.out
new file mode 100644
index 0000000..e69de29
diff --git a/original/projects/8/ProgramFlow/BasicLoop/BasicLoop.tst b/original/projects/8/ProgramFlow/BasicLoop/BasicLoop.tst
new file mode 100644
index 0000000..b0ac1c6
--- /dev/null
+++ b/original/projects/8/ProgramFlow/BasicLoop/BasicLoop.tst
@@ -0,0 +1,26 @@
+// 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/8/ProgramFlow/BasicLoop/BasicLoop.tst
+
+// Tests BasicLoop.asm on the CPU emulator.
+// Before executing the code, initializes the stack pointer
+// and the base addresses of the local and argument segments,
+// and sets argument[0].
+
+load BasicLoop.asm,
+output-file BasicLoop.out,
+compare-to BasicLoop.cmp,
+
+set RAM[0] 256, // SP
+set RAM[1] 300, // LCL
+set RAM[2] 400, // ARG
+set RAM[400] 3, // argument 0
+
+repeat 600 {
+ ticktock;
+}
+
+// Outputs the stack pointer and the value at the stack's base
+output-list RAM[0]%D1.6.1 RAM[256]%D1.6.1;
+output;
diff --git a/original/projects/8/ProgramFlow/BasicLoop/BasicLoop.vm b/original/projects/8/ProgramFlow/BasicLoop/BasicLoop.vm
new file mode 100644
index 0000000..834ea52
--- /dev/null
+++ b/original/projects/8/ProgramFlow/BasicLoop/BasicLoop.vm
@@ -0,0 +1,23 @@
+// 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/8/ProgramFlow/BasicLoop/BasicLoop.vm
+
+// Computes the sum 1 + 2 + ... + n and pushes the result onto
+// the stack. The value n is given in argument[0], which must be
+// initialized by the caller of this code.
+
+ push constant 0
+ pop local 0 // sum = 0
+label LOOP
+ push argument 0
+ push local 0
+ add
+ pop local 0 // sum = sum + n
+ push argument 0
+ push constant 1
+ sub
+ pop argument 0 // n--
+ push argument 0
+ if-goto LOOP // if n > 0, goto LOOP
+ push local 0 // else, pushes sum to the stack's top
diff --git a/original/projects/8/ProgramFlow/BasicLoop/BasicLoopVME.tst b/original/projects/8/ProgramFlow/BasicLoop/BasicLoopVME.tst
new file mode 100644
index 0000000..554348c
--- /dev/null
+++ b/original/projects/8/ProgramFlow/BasicLoop/BasicLoopVME.tst
@@ -0,0 +1,26 @@
+// 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/8/ProgramFlow/BasicLoop/BasicLoopVME.tst
+
+// Tests and illustrates BasicLoop.vm on the VM emulator.
+// Before executing the code, initializes the stack pointer
+// and the base addresses of the local and argument segments,
+// and sets argument[0].
+
+load BasicLoop.vm,
+output-file BasicLoop.out,
+compare-to BasicLoop.cmp,
+
+set sp 256,
+set local 300,
+set argument 400,
+set argument[0] 3,
+
+repeat 33 {
+ vmstep;
+}
+
+// Outputs the stack pointer and the value at the stack's base
+output-list RAM[0]%D1.6.1 RAM[256]%D1.6.1;
+output;
diff --git a/original/projects/8/ProgramFlow/FibonacciSeries/FibonacciSeries.cmp b/original/projects/8/ProgramFlow/FibonacciSeries/FibonacciSeries.cmp
new file mode 100644
index 0000000..c262a4b
--- /dev/null
+++ b/original/projects/8/ProgramFlow/FibonacciSeries/FibonacciSeries.cmp
@@ -0,0 +1,2 @@
+|RAM[3000]|RAM[3001]|RAM[3002]|RAM[3003]|RAM[3004]|RAM[3005]|
+| 0 | 1 | 1 | 2 | 3 | 5 |
diff --git a/original/projects/8/ProgramFlow/FibonacciSeries/FibonacciSeries.tst b/original/projects/8/ProgramFlow/FibonacciSeries/FibonacciSeries.tst
new file mode 100644
index 0000000..4cab397
--- /dev/null
+++ b/original/projects/8/ProgramFlow/FibonacciSeries/FibonacciSeries.tst
@@ -0,0 +1,28 @@
+// 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/8/ProgramFlow/FibonacciSeries/FibonacciSeries.tst
+
+// Tests FibonacciSeries.asm on the CPU emulator.
+// Before executing the code, initializes the stack pointer
+// and the base addresses of the local and argument segments,
+// and sets argument[0] and argument [1].
+
+load FibonacciSeries.asm,
+output-file FibonacciSeries.out,
+compare-to FibonacciSeries.cmp,
+
+set RAM[0] 256, // SP
+set RAM[1] 300, // LCL
+set RAM[2] 400, // ARG
+set RAM[400] 6, // argument[0], n
+set RAM[401] 3000, // argument[1], base address of the generated series
+
+repeat 1100 {
+ ticktock;
+}
+
+// Outputs the series of values generated and written by the code.
+output-list RAM[3000]%D1.6.2 RAM[3001]%D1.6.2 RAM[3002]%D1.6.2
+ RAM[3003]%D1.6.2 RAM[3004]%D1.6.2 RAM[3005]%D1.6.2;
+output;
diff --git a/original/projects/8/ProgramFlow/FibonacciSeries/FibonacciSeries.vm b/original/projects/8/ProgramFlow/FibonacciSeries/FibonacciSeries.vm
new file mode 100644
index 0000000..4463ab5
--- /dev/null
+++ b/original/projects/8/ProgramFlow/FibonacciSeries/FibonacciSeries.vm
@@ -0,0 +1,44 @@
+// 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/8/ProgramFlow/FibonacciSeries/FibonacciSeries.vm
+
+// Puts the first n elements of the Fibonacci series in the memory,
+// starting at address addr. n and addr are given in argument[0] and
+// argument[1], which must be initialized by the caller of this code.
+
+ push argument 1 // sets THAT, the base address of the
+ pop pointer 1 // that segment, to argument[1]
+ push constant 0 // sets the series' first and second
+ pop that 0 // elements to 0 and 1, respectively
+ push constant 1
+ pop that 1
+ push argument 0 // sets n, the number of remaining elements
+ push constant 2 // to be computed, to argument[0] minus 2,
+ sub // since 2 elements were already computed.
+ pop argument 0
+
+label LOOP
+ push argument 0
+ if-goto COMPUTE_ELEMENT // if n > 0, goto COMPUTE_ELEMENT
+ goto END // otherwise, goto END
+
+label COMPUTE_ELEMENT
+ // that[2] = that[0] + that[1]
+ push that 0
+ push that 1
+ add
+ pop that 2
+ // THAT += 1 (updates the base address of that)
+ push pointer 1
+ push constant 1
+ add
+ pop pointer 1
+ // updates n-- and loops
+ push argument 0
+ push constant 1
+ sub
+ pop argument 0
+ goto LOOP
+
+label END
diff --git a/original/projects/8/ProgramFlow/FibonacciSeries/FibonacciSeriesVME.tst b/original/projects/8/ProgramFlow/FibonacciSeries/FibonacciSeriesVME.tst
new file mode 100644
index 0000000..945c2e5
--- /dev/null
+++ b/original/projects/8/ProgramFlow/FibonacciSeries/FibonacciSeriesVME.tst
@@ -0,0 +1,29 @@
+// 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/8/ProgramFlow/FibonacciSeries/FibonacciSeriesVME.tst
+
+// Tests and illustrates FibonacciSeries.vm on the VM emulator.
+// Before executing the code, initializes the stack pointer
+// and the base addresses of the local and argument segments,
+// and sets argument[0] to n and argument [1] to the base address
+// of the generated series.
+
+load FibonacciSeries.vm,
+output-file FibonacciSeries.out,
+compare-to FibonacciSeries.cmp,
+
+set sp 256,
+set local 300,
+set argument 400,
+set argument[0] 6,
+set argument[1] 3000,
+
+repeat 73 {
+ vmstep;
+}
+
+// Outputs the series of values generated and written by the code.
+output-list RAM[3000]%D1.6.2 RAM[3001]%D1.6.2 RAM[3002]%D1.6.2
+ RAM[3003]%D1.6.2 RAM[3004]%D1.6.2 RAM[3005]%D1.6.2;
+output;
diff --git a/original/projects/9/Average/Main.jack b/original/projects/9/Average/Main.jack
new file mode 100644
index 0000000..d53093a
--- /dev/null
+++ b/original/projects/9/Average/Main.jack
@@ -0,0 +1,27 @@
+// 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/9/Average/Main.jack
+
+// Inputs some numbers and computes their average
+class Main {
+ function void main() {
+ var Array a;
+ var int length;
+ var int i, sum;
+
+ let length = Keyboard.readInt("How many numbers? ");
+ let a = Array.new(length); // constructs the array
+
+ let i = 0;
+ while (i < length) {
+ let a[i] = Keyboard.readInt("Enter a number: ");
+ let sum = sum + a[i];
+ let i = i + 1;
+ }
+
+ do Output.printString("The average is ");
+ do Output.printInt(sum / length);
+ return;
+ }
+}
diff --git a/original/projects/9/ComplexArrays/Main.jack b/original/projects/9/ComplexArrays/Main.jack
new file mode 100644
index 0000000..6579fa2
--- /dev/null
+++ b/original/projects/9/ComplexArrays/Main.jack
@@ -0,0 +1,69 @@
+// 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/9/ComplexArrays/Main.jack
+/**
+ * Performs several complex array processing tests.
+ * For each test, the expected result is printed, along with the
+ * actual result. In each test, the two results should be equal.
+ */
+class Main {
+
+ function void main() {
+ var Array a, b, c;
+
+ let a = Array.new(10);
+ let b = Array.new(5);
+ let c = Array.new(1);
+
+ let a[3] = 2;
+ let a[4] = 8;
+ let a[5] = 4;
+ let b[a[3]] = a[3] + 3; // b[2] = 5
+ let a[b[a[3]]] = a[a[5]] * b[((7 - a[3]) - Main.double(2)) + 1]; // a[5] = 8 * 5 = 40
+ let c[0] = null;
+ let c = c[0];
+
+ do Output.printString("Test 1: expected result: 5; actual result: ");
+ do Output.printInt(b[2]);
+ do Output.println();
+ do Output.printString("Test 2: expected result: 40; actual result: ");
+ do Output.printInt(a[5]);
+ do Output.println();
+ do Output.printString("Test 3: expected result: 0; actual result: ");
+ do Output.printInt(c);
+ do Output.println();
+
+ let c = null;
+
+ if (c = null) {
+ do Main.fill(a, 10);
+ let c = a[3];
+ let c[1] = 33;
+ let c = a[7];
+ let c[1] = 77;
+ let b = a[3];
+ let b[1] = b[1] + c[1]; // b[1] = 33 + 77 = 110;
+ }
+
+ do Output.printString("Test 4: expected result: 77; actual result: ");
+ do Output.printInt(c[1]);
+ do Output.println();
+ do Output.printString("Test 5: expected result: 110; actual result: ");
+ do Output.printInt(b[1]);
+ do Output.println();
+ return;
+ }
+
+ function int double(int a) {
+ return a * 2;
+ }
+
+ function void fill(Array a, int size) {
+ while (size > 0) {
+ let size = size - 1;
+ let a[size] = Array.new(3);
+ }
+ return;
+ }
+}
diff --git a/original/projects/9/ConvertToBin/Main.jack b/original/projects/9/ConvertToBin/Main.jack
new file mode 100644
index 0000000..8298c7c
--- /dev/null
+++ b/original/projects/9/ConvertToBin/Main.jack
@@ -0,0 +1,78 @@
+// 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/9/ConvertToBin/Main.jack
+/**
+ * Unpacks a 16-bit number into its binary representation:
+ * Takes the 16-bit number stored in RAM[8000] and stores its individual
+ * bits in RAM[8001]..RAM[8016] (each location will contain 0 or 1).
+ * Before the conversion, RAM[8001]..RAM[8016] are initialized to -1.
+ *
+ * The program should be tested as follows:
+ * 1) Load the compiled program into the supplied VM emulator
+ * 2) Put some value in RAM[8000]
+ * 3) Switch to "no animation"
+ * 4) Run the program (give it enough time to run)
+ * 5) Stop the program
+ * 6) Check that RAM[8001]..RAM[8016] contains the correct binary result, and
+ * that none of these memory locations contains -1.
+ */
+class Main {
+ /** Initializes RAM[8001]..RAM[8016] to -1,
+ * and converts the value in RAM[8000] to binary. */
+ function void main() {
+ var int value;
+ do Main.fillMemory(8001, 16, -1); // sets RAM[8001]..RAM[8016] to -1
+ let value = Memory.peek(8000); // reads a value from RAM[8000]
+ do Main.convert(value); // performs the conversion
+ return;
+ }
+
+ /** Converts the given decimal value to binary, and puts
+ * the resulting bits in RAM[8001]..RAM[8016]. */
+ function void convert(int value) {
+ var int mask, position;
+ var boolean loop;
+
+ let loop = true;
+ while (loop) {
+ let position = position + 1;
+ let mask = Main.nextMask(mask);
+
+ if (~(position > 16)) {
+
+ if (~((value & mask) = 0)) {
+ do Memory.poke(8000 + position, 1);
+ }
+ else {
+ do Memory.poke(8000 + position, 0);
+ }
+ }
+ else {
+ let loop = false;
+ }
+ }
+ return;
+ }
+
+ /** Returns the next mask (the mask that should follow the given mask). */
+ function int nextMask(int mask) {
+ if (mask = 0) {
+ return 1;
+ }
+ else {
+ return mask * 2;
+ }
+ }
+
+ /** Fills 'length' consecutive memory locations with 'value',
+ * starting at 'startAddress'. */
+ function void fillMemory(int startAddress, int length, int value) {
+ while (length > 0) {
+ do Memory.poke(startAddress, value);
+ let length = length - 1;
+ let startAddress = startAddress + 1;
+ }
+ return;
+ }
+}
diff --git a/original/projects/9/Fraction/Fraction.jack b/original/projects/9/Fraction/Fraction.jack
new file mode 100644
index 0000000..939df83
--- /dev/null
+++ b/original/projects/9/Fraction/Fraction.jack
@@ -0,0 +1,65 @@
+// 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/9/Fraction/Fraction.jack
+
+/** Represents the Fraction type and related operations. */
+class Fraction {
+ field int numerator, denominator; // field = property = member variable.
+
+ /** Constructs a (reduced) fraction from the given numerator and denominator. */
+ constructor Fraction new(int x, int y) {
+ let numerator = x;
+ let denominator = y;
+ do reduce(); // reduces the fraction
+ return this; // a constructor is expected to return a reference to the new object
+ }
+
+ // Reduces this fraction.
+ method void reduce() {
+ var int g;
+ let g = Fraction.gcd(numerator, denominator);
+ if (g > 1) {
+ let numerator = numerator / g;
+ let denominator = denominator / g;
+ }
+ return;
+ }
+
+ /** Accessors. */
+ method int getNumerator() { return numerator; }
+ method int getDenominator() { return denominator; }
+
+ /** Returns the sum of this fraction and the other one. */
+ method Fraction plus(Fraction other) {
+ var int sum;
+ let sum = (numerator * other.getDenominator()) + (other.getNumerator() * denominator);
+ return Fraction.new(sum, denominator * other.getDenominator());
+ }
+
+ // More fraction-related methods (minus, times, div, invert, etc.) can be added here.
+
+ /** Disposes this fraction. */
+ method void dispose() {
+ do Memory.deAlloc(this); // uses an OS routine to recycle the memory held by the object
+ return;
+ }
+
+ /** Prints this fraction in the format x/y. */
+ method void print() {
+ do Output.printInt(numerator);
+ do Output.printString("/");
+ do Output.printInt(denominator);
+ return;
+ }
+
+ // Computes the greatest common divisor of the given integers.
+ function int gcd(int a, int b) {
+ var int r;
+ while (~(b = 0)) { // applies Euclid's algorithm
+ let r = a - (b * (a / b)); // r = remainder of the integer division a/b
+ let a = b; let b = r;
+ }
+ return a;
+ }
+}
diff --git a/original/projects/9/Fraction/Main.jack b/original/projects/9/Fraction/Main.jack
new file mode 100644
index 0000000..293bc91
--- /dev/null
+++ b/original/projects/9/Fraction/Main.jack
@@ -0,0 +1,16 @@
+// 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/9/Fraction/Main.jack
+
+// Computes and prints the sum of 2/3 and 1/5.
+class Main {
+ function void main() {
+ var Fraction a, b, c;
+ let a = Fraction.new(2,3);
+ let b = Fraction.new(1,5);
+ let c = a.plus(b); // Computes c = a + b
+ do c.print(); // Prints "13/15"
+ return;
+ }
+}
diff --git a/original/projects/9/HelloWorld/Main.jack b/original/projects/9/HelloWorld/Main.jack
new file mode 100644
index 0000000..6cb47f4
--- /dev/null
+++ b/original/projects/9/HelloWorld/Main.jack
@@ -0,0 +1,14 @@
+// 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/9/HelloWorld/Main.jack
+
+/** Hello World program. */
+class Main {
+ function void main() {
+ /* Prints some text using the standard library. */
+ do Output.printString("Hello world!");
+ do Output.println(); // New line
+ return;
+ }
+}
diff --git a/original/projects/9/List/List.jack b/original/projects/9/List/List.jack
new file mode 100644
index 0000000..49bc54a
--- /dev/null
+++ b/original/projects/9/List/List.jack
@@ -0,0 +1,48 @@
+// 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/9/List/List.jack
+
+/** Represents a linked list of integers. */
+class List {
+ field int data; // an int value,
+ field List next; // followed by a list of int values
+
+ /* Creates a List. */
+ constructor List new(int car, List cdr) {
+ let data = car; // the identifiers car and cdr are used in
+ let next = cdr; // memory of the Lisp programming language
+ return this;
+ }
+
+ /** Accessors. */
+ method int getData() { return data; }
+ method int getNext() { return next; }
+
+ /** Prints this list. */
+ method void print() {
+ // Sets current to the first element of this list
+ var List current;
+ let current = this;
+ while (~(current = null)) {
+ do Output.printInt(current.getData());
+ do Output.printChar(32); // prints a space
+ let current = current.getNext();
+ }
+ return;
+ }
+
+ /** Disposes this List. */
+ // By recursively disposing its tail.
+ method void dispose() {
+ if (~(next = null)) {
+ do next.dispose();
+ }
+ // Calls an OS routine to free the memory of this object.
+ do Memory.deAlloc(this);
+ return;
+ }
+
+ // More list processing methods can come here.
+
+}
diff --git a/original/projects/9/List/Main.jack b/original/projects/9/List/Main.jack
new file mode 100644
index 0000000..54a39a9
--- /dev/null
+++ b/original/projects/9/List/Main.jack
@@ -0,0 +1,17 @@
+// 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/9/List/Main.jack
+
+/** An example of creating and using List objects. */
+class Main {
+ function void main() {
+ // Creates and uses the list (2,3,5).
+ var List v;
+ let v = List.new(5,null);
+ let v = List.new(2,List.new(3,v));
+ do v.print(); // prints 2 3 5
+ do v.dispose(); // disposes the list
+ return;
+ }
+}
diff --git a/original/projects/9/Pong/Ball.jack b/original/projects/9/Pong/Ball.jack
new file mode 100644
index 0000000..e32f8ee
--- /dev/null
+++ b/original/projects/9/Pong/Ball.jack
@@ -0,0 +1,202 @@
+// 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/9/Pong/Ball.jack
+/**
+ * A graphical ball in a Pong game. Characterized by a screen location and
+ * distance of last destination. Has methods for drawing, erasing and moving
+ * on the screen. The ball is displayed as a filled, 6-by-6 pixles rectangle.
+ */
+class Ball {
+
+ field int x, y; // the ball's screen location (in pixels)
+ field int lengthx, lengthy; // distance of last destination (in pixels)
+
+ field int d, straightD, diagonalD; // used for straight line movement computation
+ field boolean invert, positivex, positivey; // (same)
+
+ field int leftWall, rightWall, topWall, bottomWall; // wall locations
+
+ field int wall; // last wall that the ball was bounced off of
+
+ /** Constructs a new ball with the given initial location and wall locations. */
+ constructor Ball new(int Ax, int Ay,
+ int AleftWall, int ArightWall, int AtopWall, int AbottomWall) {
+ let x = Ax;
+ let y = Ay;
+ let leftWall = AleftWall;
+ let rightWall = ArightWall - 6; // -6 for ball size
+ let topWall = AtopWall;
+ let bottomWall = AbottomWall - 6; // -6 for ball size
+ let wall = 0;
+ do show();
+ return this;
+ }
+
+ /** Deallocates the Ball's memory. */
+ method void dispose() {
+ do Memory.deAlloc(this);
+ return;
+ }
+
+ /** Shows the ball. */
+ method void show() {
+ do Screen.setColor(true);
+ do draw();
+ return;
+ }
+
+ /** Hides the ball. */
+ method void hide() {
+ do Screen.setColor(false);
+ do draw();
+ return;
+ }
+
+ /** Draws the ball. */
+ method void draw() {
+ do Screen.drawRectangle(x, y, x + 5, y + 5);
+ return;
+ }
+
+ /** Returns the ball's left edge. */
+ method int getLeft() {
+ return x;
+ }
+
+ /** Returns the ball's right edge. */
+ method int getRight() {
+ return x + 5;
+ }
+
+ /** Computes and sets the ball's destination. */
+ method void setDestination(int destx, int desty) {
+ var int dx, dy, temp;
+ let lengthx = destx - x;
+ let lengthy = desty - y;
+ let dx = Math.abs(lengthx);
+ let dy = Math.abs(lengthy);
+ let invert = (dx < dy);
+
+ if (invert) {
+ let temp = dx; // swap dx, dy
+ let dx = dy;
+ let dy = temp;
+ let positivex = (y < desty);
+ let positivey = (x < destx);
+ }
+ else {
+ let positivex = (x < destx);
+ let positivey = (y < desty);
+ }
+
+ let d = (2 * dy) - dx;
+ let straightD = 2 * dy;
+ let diagonalD = 2 * (dy - dx);
+
+ return;
+ }
+
+ /**
+ * Moves the ball one step towards its destination.
+ * If the ball has reached a wall, returns 0.
+ * Else, returns a value according to the wall:
+ * 1 (left wall), 2 (right wall), 3 (top wall), 4 (bottom wall).
+ */
+ method int move() {
+
+ do hide();
+
+ if (d < 0) { let d = d + straightD; }
+ else {
+ let d = d + diagonalD;
+
+ if (positivey) {
+ if (invert) { let x = x + 4; }
+ else { let y = y + 4; }
+ }
+ else {
+ if (invert) { let x = x - 4; }
+ else { let y = y - 4; }
+ }
+ }
+
+ if (positivex) {
+ if (invert) { let y = y + 4; }
+ else { let x = x + 4; }
+ }
+ else {
+ if (invert) { let y = y - 4; }
+ else { let x = x - 4; }
+ }
+
+ if (~(x > leftWall)) {
+ let wall = 1;
+ let x = leftWall;
+ }
+ if (~(x < rightWall)) {
+ let wall = 2;
+ let x = rightWall;
+ }
+ if (~(y > topWall)) {
+ let wall = 3;
+ let y = topWall;
+ }
+ if (~(y < bottomWall)) {
+ let wall = 4;
+ let y = bottomWall;
+ }
+
+ do show();
+
+ return wall;
+ }
+
+ /**
+ * Bounces off the current wall: sets the new destination
+ * of the ball according to the ball's angle and the given
+ * bouncing direction (-1/0/1=left/center/right or up/center/down).
+ */
+ method void bounce(int bouncingDirection) {
+ var int newx, newy, divLengthx, divLengthy, factor;
+
+ // Since results are too big, divides by 10
+ let divLengthx = lengthx / 10;
+ let divLengthy = lengthy / 10;
+ if (bouncingDirection = 0) { let factor = 10; }
+ else {
+ if (((~(lengthx < 0)) & (bouncingDirection = 1)) | ((lengthx < 0) & (bouncingDirection = (-1)))) {
+ let factor = 20; // bounce direction is in ball direction
+ }
+ else { let factor = 5; } // bounce direction is against ball direction
+ }
+
+ if (wall = 1) {
+ let newx = 506;
+ let newy = (divLengthy * (-50)) / divLengthx;
+ let newy = y + (newy * factor);
+ }
+ else {
+ if (wall = 2) {
+ let newx = 0;
+ let newy = (divLengthy * 50) / divLengthx;
+ let newy = y + (newy * factor);
+ }
+ else {
+ if (wall = 3) {
+ let newy = 250;
+ let newx = (divLengthx * (-25)) / divLengthy;
+ let newx = x + (newx * factor);
+ }
+ else { // assumes wall = 4
+ let newy = 0;
+ let newx = (divLengthx * 25) / divLengthy;
+ let newx = x + (newx * factor);
+ }
+ }
+ }
+
+ do setDestination(newx, newy);
+ return;
+ }
+}
diff --git a/original/projects/9/Pong/Bat.jack b/original/projects/9/Pong/Bat.jack
new file mode 100644
index 0000000..dbe828e
--- /dev/null
+++ b/original/projects/9/Pong/Bat.jack
@@ -0,0 +1,103 @@
+// 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/9/Pong/Bat.jack
+/**
+ * A graphical bat in a Pong game.
+ * Displayed as a filled horizontal rectangle that has a screen location,
+ * a width and a height.
+ * Has methods for drawing, erasing, moving left and right, and changing
+ * its width (to make the hitting action more challenging).
+ * This class should have been called "Paddle", following the
+ * standard Pong terminology. Unaware of this terminology,
+ * we called it "bat", and the name stuck.
+ */
+class Bat {
+
+ field int x, y; // the bat's screen location
+ field int width, height; // the bat's width and height
+ field int direction; // direction of the bat's movement
+ // (1 = left, 2 = right)
+
+ /** Constructs a new bat with the given location and width. */
+ constructor Bat new(int Ax, int Ay, int Awidth, int Aheight) {
+ let x = Ax;
+ let y = Ay;
+ let width = Awidth;
+ let height = Aheight;
+ let direction = 2;
+ do show();
+ return this;
+ }
+
+ /** Deallocates the object's memory. */
+ method void dispose() {
+ do Memory.deAlloc(this);
+ return;
+ }
+
+ /** Shows the bat. */
+ method void show() {
+ do Screen.setColor(true);
+ do draw();
+ return;
+ }
+
+ /** Hides the bat. */
+ method void hide() {
+ do Screen.setColor(false);
+ do draw();
+ return;
+ }
+
+ /** Draws the bat. */
+ method void draw() {
+ do Screen.drawRectangle(x, y, x + width, y + height);
+ return;
+ }
+
+ /** Sets the bat's direction (0=stop, 1=left, 2=right). */
+ method void setDirection(int Adirection) {
+ let direction = Adirection;
+ return;
+ }
+
+ /** Returns the bat's left edge. */
+ method int getLeft() {
+ return x;
+ }
+
+ /** Returns the bat's right edge. */
+ method int getRight() {
+ return x + width;
+ }
+
+ /** Sets the bat's width. */
+ method void setWidth(int Awidth) {
+ do hide();
+ let width = Awidth;
+ do show();
+ return;
+ }
+
+ /** Moves the bat one step in the bat's direction. */
+ method void move() {
+ if (direction = 1) {
+ let x = x - 4;
+ if (x < 0) { let x = 0; }
+ do Screen.setColor(false);
+ do Screen.drawRectangle((x + width) + 1, y, (x + width) + 4, y + height);
+ do Screen.setColor(true);
+ do Screen.drawRectangle(x, y, x + 3, y + height);
+ }
+ else {
+ let x = x + 4;
+ if ((x + width) > 511) { let x = 511 - width; }
+ do Screen.setColor(false);
+ do Screen.drawRectangle(x - 4, y, x - 1, y + height);
+ do Screen.setColor(true);
+ do Screen.drawRectangle((x + width) - 3, y, x + width, y + height);
+ }
+ return;
+ }
+}
diff --git a/original/projects/9/Pong/Main.jack b/original/projects/9/Pong/Main.jack
new file mode 100644
index 0000000..e3f95a0
--- /dev/null
+++ b/original/projects/9/Pong/Main.jack
@@ -0,0 +1,18 @@
+// 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/9/Pong/Main.jack
+/**
+ * Main class of the Pong game.
+ */
+class Main {
+ /** Initializes a Pong game and starts running it. */
+ function void main() {
+ var PongGame game;
+ do PongGame.newInstance();
+ let game = PongGame.getInstance();
+ do game.run();
+ do game.dispose();
+ return;
+ }
+}
diff --git a/original/projects/9/Pong/PongGame.jack b/original/projects/9/Pong/PongGame.jack
new file mode 100644
index 0000000..7a875fd
--- /dev/null
+++ b/original/projects/9/Pong/PongGame.jack
@@ -0,0 +1,136 @@
+// 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/9/Pong/PongGame.jack
+/**
+ * Represents a Pong game.
+ */
+class PongGame {
+
+ static PongGame instance; // A Pong game
+ field Bat bat; // bat
+ field Ball ball; // ball
+ field int wall; // current wall that the ball is bouncing off of
+ field boolean exit; // true when the game is over
+ field int score; // current score
+ field int lastWall; // last wall that the ball bounced off of
+
+ // The current width of the bat
+ field int batWidth;
+
+ /** Constructs a new Pong game. */
+ constructor PongGame new() {
+ do Screen.clearScreen();
+ let batWidth = 50; // initial bat size
+ let bat = Bat.new(230, 229, batWidth, 7);
+ let ball = Ball.new(253, 222, 0, 511, 0, 229);
+ do ball.setDestination(400,0);
+ do Screen.drawRectangle(0, 238, 511, 240);
+ do Output.moveCursor(22,0);
+ do Output.printString("Score: 0");
+
+ let exit = false;
+ let score = 0;
+ let wall = 0;
+ let lastWall = 0;
+
+ return this;
+ }
+
+ /** Deallocates the object's memory. */
+ method void dispose() {
+ do bat.dispose();
+ do ball.dispose();
+ do Memory.deAlloc(this);
+ return;
+ }
+
+ /** Creates an instance of a Pong game. */
+ function void newInstance() {
+ let instance = PongGame.new();
+ return;
+ }
+
+ /** Returns this Pong game. */
+ function PongGame getInstance() {
+ return instance;
+ }
+
+ /** Starts the game, and handles inputs from the user that control
+ * the bat's movement direction. */
+ method void run() {
+ var char key;
+
+ while (~exit) {
+ // waits for a key to be pressed.
+ while ((key = 0) & (~exit)) {
+ let key = Keyboard.keyPressed();
+ do bat.move();
+ do moveBall();
+ do Sys.wait(50);
+ }
+
+ if (key = 130) { do bat.setDirection(1); }
+ else {
+ if (key = 132) { do bat.setDirection(2); }
+ else {
+ if (key = 140) { let exit = true; }
+ }
+ }
+
+ // Waits for the key to be released.
+ while ((~(key = 0)) & (~exit)) {
+ let key = Keyboard.keyPressed();
+ do bat.move();
+ do moveBall();
+ do Sys.wait(50);
+ }
+ }
+
+ if (exit) {
+ do Output.moveCursor(10,27);
+ do Output.printString("Game Over");
+ }
+
+ return;
+ }
+
+ /**
+ * Handles ball movement, including bouncing.
+ * If the ball bounces off a wall, finds its new direction.
+ * If the ball bounces off the bat, increases the score by one
+ * and shrinks the bat's size, to make the game more challenging.
+ */
+ method void moveBall() {
+ var int bouncingDirection, batLeft, batRight, ballLeft, ballRight;
+
+ let wall = ball.move();
+
+ if ((wall > 0) & (~(wall = lastWall))) {
+ let lastWall = wall;
+ let bouncingDirection = 0;
+ let batLeft = bat.getLeft();
+ let batRight = bat.getRight();
+ let ballLeft = ball.getLeft();
+ let ballRight = ball.getRight();
+
+ if (wall = 4) {
+ let exit = (batLeft > ballRight) | (batRight < ballLeft);
+ if (~exit) {
+ if (ballRight < (batLeft + 10)) { let bouncingDirection = -1; }
+ else {
+ if (ballLeft > (batRight - 10)) { let bouncingDirection = 1; }
+ }
+
+ let batWidth = batWidth - 2;
+ do bat.setWidth(batWidth);
+ let score = score + 1;
+ do Output.moveCursor(22,7);
+ do Output.printInt(score);
+ }
+ }
+ do ball.bounce(bouncingDirection);
+ }
+ return;
+ }
+}
\ No newline at end of file
diff --git a/original/projects/9/Square/Main.jack b/original/projects/9/Square/Main.jack
new file mode 100644
index 0000000..d19201a
--- /dev/null
+++ b/original/projects/9/Square/Main.jack
@@ -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/9/Square/Main.jack
+
+/** Initializes a new Square game and starts running it. */
+class Main {
+ function void main() {
+ var SquareGame game;
+ let game = SquareGame.new();
+ do game.run();
+ do game.dispose();
+ return;
+ }
+}
diff --git a/original/projects/9/Square/Square.jack b/original/projects/9/Square/Square.jack
new file mode 100644
index 0000000..e4a6590
--- /dev/null
+++ b/original/projects/9/Square/Square.jack
@@ -0,0 +1,113 @@
+// 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/9/Square/Square.jack
+
+/** Implements a graphical square.
+ The square has top-left x and y coordinates, and a size. */
+class Square {
+
+ field int x, y; // screen location of the top-left corner of this square
+ field int size; // length of this square, in pixels
+
+ /** Constructs and draws a new square with a given location and size. */
+ constructor Square new(int ax, int ay, int asize) {
+ let x = ax;
+ let y = ay;
+ let size = asize;
+ do draw();
+ return this;
+ }
+
+ /** Disposes this square. */
+ method void dispose() {
+ do Memory.deAlloc(this);
+ return;
+ }
+
+ /** Draws this square in its current (x,y) location */
+ method void draw() {
+ // Draws the square using the color black
+ do Screen.setColor(true);
+ do Screen.drawRectangle(x, y, x + size, y + size);
+ return;
+ }
+
+ /** Erases this square. */
+ method void erase() {
+ // Draws the square using the color white (background color)
+ do Screen.setColor(false);
+ do Screen.drawRectangle(x, y, x + size, y + size);
+ return;
+ }
+
+ /** Increments the square size by 2 pixels (if possible). */
+ method void incSize() {
+ if (((y + size) < 254) & ((x + size) < 510)) {
+ do erase();
+ let size = size + 2;
+ do draw();
+ }
+ return;
+ }
+
+ /** Decrements the square size by 2 pixels (if possible). */
+ method void decSize() {
+ if (size > 2) {
+ do erase();
+ let size = size - 2;
+ do draw();
+ }
+ return;
+ }
+
+ /** Moves this square up by 2 pixels (if possible). */
+ method void moveUp() {
+ if (y > 1) {
+ // Erases the bottom two rows of this square in its current location
+ do Screen.setColor(false);
+ do Screen.drawRectangle(x, (y + size) - 1, x + size, y + size);
+ let y = y - 2;
+ // Draws the top two rows of this square in its new location
+ do Screen.setColor(true);
+ do Screen.drawRectangle(x, y, x + size, y + 1);
+ }
+ return;
+ }
+
+ /** Moves the square down by 2 pixels (if possible). */
+ method void moveDown() {
+ if ((y + size) < 254) {
+ do Screen.setColor(false);
+ do Screen.drawRectangle(x, y, x + size, y + 1);
+ let y = y + 2;
+ do Screen.setColor(true);
+ do Screen.drawRectangle(x, (y + size) - 1, x + size, y + size);
+ }
+ return;
+ }
+
+ /** Moves the square left by 2 pixels (if possible). */
+ method void moveLeft() {
+ if (x > 1) {
+ do Screen.setColor(false);
+ do Screen.drawRectangle((x + size) - 1, y, x + size, y + size);
+ let x = x - 2;
+ do Screen.setColor(true);
+ do Screen.drawRectangle(x, y, x + 1, y + size);
+ }
+ return;
+ }
+
+ /** Moves the square right by 2 pixels (if possible). */
+ method void moveRight() {
+ if ((x + size) < 510) {
+ do Screen.setColor(false);
+ do Screen.drawRectangle(x, y, x + 1, y + size);
+ let x = x + 2;
+ do Screen.setColor(true);
+ do Screen.drawRectangle((x + size) - 1, y, x + size, y + size);
+ }
+ return;
+ }
+}
diff --git a/original/projects/9/Square/SquareGame.jack b/original/projects/9/Square/SquareGame.jack
new file mode 100644
index 0000000..ddbff4d
--- /dev/null
+++ b/original/projects/9/Square/SquareGame.jack
@@ -0,0 +1,76 @@
+// 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/09/Square/SquareGame.jack
+/**
+ * Implements the Square game.
+ * This simple game allows the user to move a black square around
+ * the screen, and change the square's size during the movement.
+ * When the game starts, a square of 30 by 30 pixels is shown at the
+ * top-left corner of the screen. The user controls the square as follows.
+ * The 4 arrow keys are used to move the square up, down, left, and right.
+ * The 'z' and 'x' keys are used, respectively, to decrement and increment
+ * the square's size. The 'q' key is used to quit the game.
+ */
+class SquareGame {
+ field Square square; // the square of this game
+ field int direction; // the square's current direction:
+ // 0=none, 1=up, 2=down, 3=left, 4=right
+
+ /** Constructs a new square game. */
+ constructor SquareGame new() {
+ // The initial square is located in (0,0), has size 30, and is not moving.
+ let square = Square.new(0, 0, 30);
+ let direction = 0;
+ return this;
+ }
+
+ /** Disposes this game. */
+ method void dispose() {
+ do square.dispose();
+ do Memory.deAlloc(this);
+ return;
+ }
+
+ /** Moves the square in the current direction. */
+ method void moveSquare() {
+ if (direction = 1) { do square.moveUp(); }
+ if (direction = 2) { do square.moveDown(); }
+ if (direction = 3) { do square.moveLeft(); }
+ if (direction = 4) { do square.moveRight(); }
+ do Sys.wait(5); // delays the next movement
+ return;
+ }
+
+ /** Runs the game: handles the user's inputs and moves the square accordingly */
+ method void run() {
+ var char key; // the key currently pressed by the user
+ var boolean exit;
+ let exit = false;
+
+ while (~exit) {
+ // waits for a key to be pressed
+ while (key = 0) {
+ let key = Keyboard.keyPressed();
+ do moveSquare();
+ }
+ if (key = 81) { let exit = true; } // q key
+ if (key = 90) { do square.decSize(); } // z key
+ if (key = 88) { do square.incSize(); } // x key
+ if (key = 131) { let direction = 1; } // up arrow
+ if (key = 133) { let direction = 2; } // down arrow
+ if (key = 130) { let direction = 3; } // left arrow
+ if (key = 132) { let direction = 4; } // right arrow
+
+ // waits for the key to be released
+ while (~(key = 0)) {
+ let key = Keyboard.keyPressed();
+ do moveSquare();
+ }
+ } // while
+ return;
+ }
+}
+
+
+
diff --git a/original/tools/Assembler.bat b/original/tools/Assembler.bat
new file mode 100644
index 0000000..93260ec
--- /dev/null
+++ b/original/tools/Assembler.bat
@@ -0,0 +1,27 @@
+@echo off
+
+rem $Id: Assembler.bat,v 1.2 2014/05/10 00:52:43 marka Exp $
+rem mark.armbrust@pobox.com
+
+setlocal
+if not "%2"=="" goto :USAGE
+if "%~1"=="/?" (
+:USAGE
+ echo Usage:
+ echo Assembler Starts the assembler in interactive mode.
+ echo Assembler FILE[.asm] Assembles FILE.asm to FILE.hack.
+ exit -b
+)
+if not "%~1"=="" (
+ set "_arg1=%~f1"
+)
+pushd "%~dp0"
+if "%~1"=="" (
+ start javaw -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Compilers.jar;bin/lib/AssemblerGUI.jar;bin/lib/TranslatorsGUI.jar" ^
+ HackAssemblerMain
+) else (
+ echo Assembling "%_arg1%"
+ java -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Compilers.jar;bin/lib/AssemblerGUI.jar;bin/lib/TranslatorsGUI.jar" ^
+ HackAssemblerMain "%_arg1%"
+)
+popd
diff --git a/original/tools/Assembler.sh b/original/tools/Assembler.sh
new file mode 100644
index 0000000..70db569
--- /dev/null
+++ b/original/tools/Assembler.sh
@@ -0,0 +1,32 @@
+#!/usr/bin/env sh
+
+# $Id: Assembler.sh,v 1.1 2014/06/17 21:14:01 marka Exp $
+# mark.armbrust@pobox.com
+
+# User's CDPATH can interfere with cd in this script
+unset CDPATH
+# Get the true name of this script
+script="`test -L "$0" && readlink -n "$0" || echo "$0"`"
+dir="$PWD"
+cd "`dirname "$script"`"
+if [ \( $# -gt 1 \) -o \( "$1" = "-h" \) -o \( "$1" = "--help" \) ]
+then
+ echo "Usage:"
+ echo " `basename "$0"` Starts the assembler in interactive mode."
+ echo " `basename "$0"` FILE[.asm] Assembles FILE.asm to FILE.hack."
+elif [ $# -eq 0 ]
+then
+ # Run assembler in interactive mode
+ java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Compilers.jar:bin/lib/AssemblerGUI.jar:bin/lib/TranslatorsGUI.jar" HackAssemblerMain &
+else
+ # Convert arg1 to an absolute path and run assembler with arg1.
+ if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ]
+ then
+ arg1="$1"
+ else
+ arg1="${dir}/$1"
+ fi
+ echo Assembling "$arg1"
+ java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Compilers.jar:bin/lib/AssemblerGUI.jar:bin/lib/TranslatorsGUI.jar" HackAssemblerMain "$arg1"
+fi
+
diff --git a/original/tools/CPUEmulator.bat b/original/tools/CPUEmulator.bat
new file mode 100644
index 0000000..f92cf40
--- /dev/null
+++ b/original/tools/CPUEmulator.bat
@@ -0,0 +1,29 @@
+@echo off
+
+rem $Id: CPUEmulator.bat,v 1.3 2014/05/10 00:52:43 marka Exp $
+rem mark.armbrust@pobox.com
+
+setlocal
+if not "%2"=="" goto :USAGE
+if "%~1"=="/?" (
+:USAGE
+ echo Usage:
+ echo CPUEmulator Starts the CPU Emulator in interactive mode.
+ echo CPUEmulator FILE.tst Starts the CPU Emulator and runs the FILE.tst
+ echo test script. The success/failure message
+ echo is printed to the command console.
+ exit -b
+)
+if not "%~1"=="" (
+ set "_arg1=%~f1"
+)
+pushd "%~dp0"
+if "%~1"=="" (
+ start javaw -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^
+ CPUEmulatorMain
+) else (
+rem echo Running "%_arg1%"
+ java -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^
+ CPUEmulatorMain "%_arg1%"
+)
+popd
diff --git a/original/tools/CPUEmulator.sh b/original/tools/CPUEmulator.sh
new file mode 100644
index 0000000..033d9d7
--- /dev/null
+++ b/original/tools/CPUEmulator.sh
@@ -0,0 +1,33 @@
+#!/usr/bin/env sh
+
+# $Id: CPUEmulator.sh,v 1.1 2014/06/17 21:14:01 marka Exp $
+# mark.armbrust@pobox.com
+
+# User's CDPATH can interfere with cd in this script
+unset CDPATH
+# Get the true name of this script
+script="`test -L "$0" && readlink -n "$0" || echo "$0"`"
+dir="$PWD"
+cd "`dirname "$script"`"
+if [ \( $# -gt 1 \) -o \( "$1" = "-h" \) -o \( "$1" = "--help" \) ]
+then
+ echo "Usage:"
+ echo " `basename "$0"` Starts the CPU Emulator in interactive mode."
+ echo " `basename "$0"` FILE.tst Starts the CPU Emulator and runs the File.tst"
+ echo " test script. The success/failure message"
+ echo " is printed to the command console."
+elif [ $# -eq 0 ]
+then
+ # Run CPU emulator in interactive mode
+ java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Simulators.jar:bin/lib/SimulatorsGUI.jar:bin/lib/Compilers.jar" CPUEmulatorMain &
+else
+ # Convert arg1 to an absolute path and run CPU emulator with arg1
+ if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ]
+ then
+ arg1="$1"
+ else
+ arg1="${dir}/$1"
+ fi
+# echo Running "$arg1"
+ java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Simulators.jar:bin/lib/SimulatorsGUI.jar:bin/lib/Compilers.jar" CPUEmulatorMain "$arg1"
+fi
diff --git a/original/tools/HardwareSimulator.bat b/original/tools/HardwareSimulator.bat
new file mode 100644
index 0000000..76baa31
--- /dev/null
+++ b/original/tools/HardwareSimulator.bat
@@ -0,0 +1,30 @@
+@echo off
+
+rem $Id: HardwareSimulator.bat,v 1.3 2014/05/10 00:52:43 marka Exp $
+rem mark.armbrust@pobox.com
+
+setlocal
+if not "%2"=="" goto :USAGE
+if "%~1"=="/?" (
+:USAGE
+ echo Usage:
+ echo HardwareSimulator Starts the Hardware Simulator in
+ echo interactive mode.
+ echo HardwareSimulator FILE.tst Starts the Hardware Simulator and runs the
+ echo FILE.tst test script. The success/failure
+ echo message is printed to the command console.
+ exit -b
+)
+if not "%~1"=="" (
+ set "_arg1=%~f1"
+)
+pushd "%~dp0"
+if "%~1"=="" (
+ start javaw -classpath "%CLASSPATH%;.;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^
+ HardwareSimulatorMain
+) else (
+rem echo Running "%_arg1%"
+ java -classpath "%CLASSPATH%;.;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^
+ HardwareSimulatorMain "%_arg1%"
+)
+popd
diff --git a/original/tools/HardwareSimulator.sh b/original/tools/HardwareSimulator.sh
new file mode 100644
index 0000000..47e7482
--- /dev/null
+++ b/original/tools/HardwareSimulator.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env sh
+
+# $Id: HardwareSimulator.sh,v 1.1 2014/06/17 21:14:01 marka Exp $
+# mark.armbrust@pobox.com
+
+# User's CDPATH can interfere with cd in this script
+unset CDPATH
+# Get the true name of this script
+script="`test -L "$0" && readlink -n "$0" || echo "$0"`"
+dir="$PWD"
+cd "`dirname "$script"`"
+if [ \( $# -gt 1 \) -o \( "$1" = "-h" \) -o \( "$1" = "--help" \) ]
+then
+ echo "Usage:"
+ echo " `basename "$0"` Starts the Hardware Simulator in"
+ echo " interactive mode."
+ echo " `basename "$0"` FILE.tst Starts the Hardware Simulator and runs the"
+ echo " FILE.tst test script. The success/failure"
+ echo " message is printed to the command console."
+elif [ $# -eq 0 ]
+then
+ # Run hardware simulator in interactive mode
+ java -classpath "${CLASSPATH}:bin/classes:BuiltIn:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Simulators.jar:bin/lib/SimulatorsGUI.jar:bin/lib/Compilers.jar" HardwareSimulatorMain &
+else
+ # Convert arg1 to an absolute path and run hardware simulator with arg1
+ if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ]
+ then
+ arg1="$1"
+ else
+ arg1="${dir}/$1"
+ fi
+# echo Running "$arg1"
+ java -classpath "${CLASSPATH}:bin/classes:BuiltIn:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Simulators.jar:bin/lib/SimulatorsGUI.jar:bin/lib/Compilers.jar" HardwareSimulatorMain "$arg1"
+fi
diff --git a/original/tools/JackCompiler.bat b/original/tools/JackCompiler.bat
new file mode 100644
index 0000000..9399b94
--- /dev/null
+++ b/original/tools/JackCompiler.bat
@@ -0,0 +1,26 @@
+@echo off
+
+rem $Id: JackCompiler.bat,v 1.2 2014/05/10 00:52:43 marka Exp $
+rem mark.armbrust@pobox.com
+
+setlocal
+if not "%2"=="" goto :USAGE
+if "%~1"=="/?" (
+:USAGE
+ echo Usage:
+ echo JackCompiler Compiles all .jack files in the current
+ echo working directory.
+ echo JackCompiler DIRECTORY Compiles all .jack files in DIRECTORY.
+ echo JackCompiler FILE.jack Compiles FILE.jack to FILE.vm.
+ exit -b
+)
+if not "%~1"=="" (
+ set "_arg1=%~f1"
+) else (
+ set "_arg1=%CD%"
+)
+pushd "%~dp0"
+echo Compiling "%_arg1%"
+java -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/Compilers.jar" ^
+ Hack.Compiler.JackCompiler "%_arg1%"
+popd
diff --git a/original/tools/JackCompiler.sh b/original/tools/JackCompiler.sh
new file mode 100644
index 0000000..699dfb8
--- /dev/null
+++ b/original/tools/JackCompiler.sh
@@ -0,0 +1,35 @@
+#!/usr/bin/env sh
+
+# $Id: JackCompiler.sh,v 1.1 2014/06/17 21:14:01 marka Exp $
+# mark.armbrust@pobox.com
+
+# User's CDPATH can interfere with cd in this script
+unset CDPATH
+# Get the true name of this script
+script="`test -L "$0" && readlink -n "$0" || echo "$0"`"
+dir="$PWD"
+cd "`dirname "$script"`"
+if [ \( $# -gt 1 \) -o \( "$1" = "-h" \) -o \( "$1" = "--help" \) ]
+then
+ echo "Usage:"
+ echo " `basename "$0"` Compiles all .jack files in the current"
+ echo " working directory."
+ echo " `basename "$0"` DIRECTORY Compiles all .jack files in DIRECTORY."
+ echo " `basename "$0"` FILE.jack Compiles FILE.jack to FILE.vm."
+else
+ if [ $# -eq 0 ]
+ then
+ # Use current directory as arg1
+ arg1="$dir"
+ else
+ # Convert arg1 to an absolute path
+ if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ]
+ then
+ arg1="$1"
+ else
+ arg1="$dir/$1"
+ fi
+ fi
+ echo Compiling "$arg1"
+ java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/Compilers.jar" Hack.Compiler.JackCompiler "$arg1"
+fi
diff --git a/original/tools/OS/Array.vm b/original/tools/OS/Array.vm
new file mode 100644
index 0000000..aa4c9e8
--- /dev/null
+++ b/original/tools/OS/Array.vm
@@ -0,0 +1,23 @@
+function Array.new 0
+push argument 0
+push constant 0
+gt
+not
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 2
+call Sys.error 1
+pop temp 0
+label IF_FALSE0
+push argument 0
+call Memory.alloc 1
+return
+function Array.dispose 0
+push argument 0
+pop pointer 0
+push pointer 0
+call Memory.deAlloc 1
+pop temp 0
+push constant 0
+return
diff --git a/original/tools/OS/Keyboard.vm b/original/tools/OS/Keyboard.vm
new file mode 100644
index 0000000..a806c4e
--- /dev/null
+++ b/original/tools/OS/Keyboard.vm
@@ -0,0 +1,102 @@
+function Keyboard.init 0
+push constant 0
+return
+function Keyboard.keyPressed 0
+push constant 24576
+call Memory.peek 1
+return
+function Keyboard.readChar 2
+push constant 0
+call Output.printChar 1
+pop temp 0
+label WHILE_EXP0
+push local 1
+push constant 0
+eq
+push local 0
+push constant 0
+gt
+or
+not
+if-goto WHILE_END0
+call Keyboard.keyPressed 0
+pop local 0
+push local 0
+push constant 0
+gt
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push local 0
+pop local 1
+label IF_FALSE0
+goto WHILE_EXP0
+label WHILE_END0
+call String.backSpace 0
+call Output.printChar 1
+pop temp 0
+push local 1
+call Output.printChar 1
+pop temp 0
+push local 1
+return
+function Keyboard.readLine 5
+push constant 80
+call String.new 1
+pop local 3
+push argument 0
+call Output.printString 1
+pop temp 0
+call String.newLine 0
+pop local 1
+call String.backSpace 0
+pop local 2
+label WHILE_EXP0
+push local 4
+not
+not
+if-goto WHILE_END0
+call Keyboard.readChar 0
+pop local 0
+push local 0
+push local 1
+eq
+pop local 4
+push local 4
+not
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push local 0
+push local 2
+eq
+if-goto IF_TRUE1
+goto IF_FALSE1
+label IF_TRUE1
+push local 3
+call String.eraseLastChar 1
+pop temp 0
+goto IF_END1
+label IF_FALSE1
+push local 3
+push local 0
+call String.appendChar 2
+pop local 3
+label IF_END1
+label IF_FALSE0
+goto WHILE_EXP0
+label WHILE_END0
+push local 3
+return
+function Keyboard.readInt 2
+push argument 0
+call Keyboard.readLine 1
+pop local 0
+push local 0
+call String.intValue 1
+pop local 1
+push local 0
+call String.dispose 1
+pop temp 0
+push local 1
+return
diff --git a/original/tools/OS/Math.vm b/original/tools/OS/Math.vm
new file mode 100644
index 0000000..b660688
--- /dev/null
+++ b/original/tools/OS/Math.vm
@@ -0,0 +1,408 @@
+function Math.init 1
+push constant 16
+call Array.new 1
+pop static 1
+push constant 16
+call Array.new 1
+pop static 0
+push constant 0
+push static 0
+add
+push constant 1
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+label WHILE_EXP0
+push local 0
+push constant 15
+lt
+not
+if-goto WHILE_END0
+push local 0
+push constant 1
+add
+pop local 0
+push local 0
+push static 0
+add
+push local 0
+push constant 1
+sub
+push static 0
+add
+pop pointer 1
+push that 0
+push local 0
+push constant 1
+sub
+push static 0
+add
+pop pointer 1
+push that 0
+add
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+goto WHILE_EXP0
+label WHILE_END0
+push constant 0
+return
+function Math.abs 0
+push argument 0
+push constant 0
+lt
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push argument 0
+neg
+pop argument 0
+label IF_FALSE0
+push argument 0
+return
+function Math.multiply 5
+push argument 0
+push constant 0
+lt
+push argument 1
+push constant 0
+gt
+and
+push argument 0
+push constant 0
+gt
+push argument 1
+push constant 0
+lt
+and
+or
+pop local 4
+push argument 0
+call Math.abs 1
+pop argument 0
+push argument 1
+call Math.abs 1
+pop argument 1
+push argument 0
+push argument 1
+lt
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push argument 0
+pop local 1
+push argument 1
+pop argument 0
+push local 1
+pop argument 1
+label IF_FALSE0
+label WHILE_EXP0
+push local 2
+push constant 1
+sub
+push argument 1
+push constant 1
+sub
+lt
+not
+if-goto WHILE_END0
+push local 3
+push static 0
+add
+pop pointer 1
+push that 0
+push argument 1
+and
+push constant 0
+eq
+not
+if-goto IF_TRUE1
+goto IF_FALSE1
+label IF_TRUE1
+push local 0
+push argument 0
+add
+pop local 0
+push local 2
+push local 3
+push static 0
+add
+pop pointer 1
+push that 0
+add
+pop local 2
+label IF_FALSE1
+push argument 0
+push argument 0
+add
+pop argument 0
+push local 3
+push constant 1
+add
+pop local 3
+goto WHILE_EXP0
+label WHILE_END0
+push local 4
+if-goto IF_TRUE2
+goto IF_FALSE2
+label IF_TRUE2
+push local 0
+neg
+pop local 0
+label IF_FALSE2
+push local 0
+return
+function Math.divide 4
+push argument 1
+push constant 0
+eq
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 3
+call Sys.error 1
+pop temp 0
+label IF_FALSE0
+push argument 0
+push constant 0
+lt
+push argument 1
+push constant 0
+gt
+and
+push argument 0
+push constant 0
+gt
+push argument 1
+push constant 0
+lt
+and
+or
+pop local 2
+push constant 0
+push static 1
+add
+push argument 1
+call Math.abs 1
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push argument 0
+call Math.abs 1
+pop argument 0
+label WHILE_EXP0
+push local 0
+push constant 15
+lt
+push local 3
+not
+and
+not
+if-goto WHILE_END0
+push constant 32767
+push local 0
+push static 1
+add
+pop pointer 1
+push that 0
+push constant 1
+sub
+sub
+push local 0
+push static 1
+add
+pop pointer 1
+push that 0
+push constant 1
+sub
+lt
+pop local 3
+push local 3
+not
+if-goto IF_TRUE1
+goto IF_FALSE1
+label IF_TRUE1
+push local 0
+push constant 1
+add
+push static 1
+add
+push local 0
+push static 1
+add
+pop pointer 1
+push that 0
+push local 0
+push static 1
+add
+pop pointer 1
+push that 0
+add
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push local 0
+push constant 1
+add
+push static 1
+add
+pop pointer 1
+push that 0
+push constant 1
+sub
+push argument 0
+push constant 1
+sub
+gt
+pop local 3
+push local 3
+not
+if-goto IF_TRUE2
+goto IF_FALSE2
+label IF_TRUE2
+push local 0
+push constant 1
+add
+pop local 0
+label IF_FALSE2
+label IF_FALSE1
+goto WHILE_EXP0
+label WHILE_END0
+label WHILE_EXP1
+push local 0
+push constant 1
+neg
+gt
+not
+if-goto WHILE_END1
+push local 0
+push static 1
+add
+pop pointer 1
+push that 0
+push constant 1
+sub
+push argument 0
+push constant 1
+sub
+gt
+not
+if-goto IF_TRUE3
+goto IF_FALSE3
+label IF_TRUE3
+push local 1
+push local 0
+push static 0
+add
+pop pointer 1
+push that 0
+add
+pop local 1
+push argument 0
+push local 0
+push static 1
+add
+pop pointer 1
+push that 0
+sub
+pop argument 0
+label IF_FALSE3
+push local 0
+push constant 1
+sub
+pop local 0
+goto WHILE_EXP1
+label WHILE_END1
+push local 2
+if-goto IF_TRUE4
+goto IF_FALSE4
+label IF_TRUE4
+push local 1
+neg
+pop local 1
+label IF_FALSE4
+push local 1
+return
+function Math.sqrt 4
+push argument 0
+push constant 0
+lt
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 4
+call Sys.error 1
+pop temp 0
+label IF_FALSE0
+push constant 7
+pop local 0
+label WHILE_EXP0
+push local 0
+push constant 1
+neg
+gt
+not
+if-goto WHILE_END0
+push local 3
+push local 0
+push static 0
+add
+pop pointer 1
+push that 0
+add
+pop local 1
+push local 1
+push local 1
+call Math.multiply 2
+pop local 2
+push local 2
+push argument 0
+gt
+not
+push local 2
+push constant 0
+lt
+not
+and
+if-goto IF_TRUE1
+goto IF_FALSE1
+label IF_TRUE1
+push local 1
+pop local 3
+label IF_FALSE1
+push local 0
+push constant 1
+sub
+pop local 0
+goto WHILE_EXP0
+label WHILE_END0
+push local 3
+return
+function Math.max 0
+push argument 0
+push argument 1
+gt
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push argument 0
+pop argument 1
+label IF_FALSE0
+push argument 1
+return
+function Math.min 0
+push argument 0
+push argument 1
+lt
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push argument 0
+pop argument 1
+label IF_FALSE0
+push argument 1
+return
diff --git a/original/tools/OS/Memory.vm b/original/tools/OS/Memory.vm
new file mode 100644
index 0000000..8c74b87
--- /dev/null
+++ b/original/tools/OS/Memory.vm
@@ -0,0 +1,376 @@
+function Memory.init 0
+push constant 0
+pop static 0
+push constant 2048
+push static 0
+add
+push constant 14334
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 2049
+push static 0
+add
+push constant 2050
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 0
+return
+function Memory.peek 0
+push argument 0
+push static 0
+add
+pop pointer 1
+push that 0
+return
+function Memory.poke 0
+push argument 0
+push static 0
+add
+push argument 1
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 0
+return
+function Memory.alloc 2
+push argument 0
+push constant 0
+lt
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 5
+call Sys.error 1
+pop temp 0
+label IF_FALSE0
+push argument 0
+push constant 0
+eq
+if-goto IF_TRUE1
+goto IF_FALSE1
+label IF_TRUE1
+push constant 1
+pop argument 0
+label IF_FALSE1
+push constant 2048
+pop local 0
+label WHILE_EXP0
+push local 0
+push constant 16383
+lt
+push constant 0
+push local 0
+add
+pop pointer 1
+push that 0
+push argument 0
+lt
+and
+not
+if-goto WHILE_END0
+push constant 1
+push local 0
+add
+pop pointer 1
+push that 0
+pop local 1
+push constant 0
+push local 0
+add
+pop pointer 1
+push that 0
+push constant 0
+eq
+push local 1
+push constant 16382
+gt
+or
+push constant 0
+push local 1
+add
+pop pointer 1
+push that 0
+push constant 0
+eq
+or
+if-goto IF_TRUE2
+goto IF_FALSE2
+label IF_TRUE2
+push local 1
+pop local 0
+goto IF_END2
+label IF_FALSE2
+push constant 0
+push local 0
+add
+push constant 1
+push local 0
+add
+pop pointer 1
+push that 0
+push local 0
+sub
+push constant 0
+push local 1
+add
+pop pointer 1
+push that 0
+add
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 1
+push local 1
+add
+pop pointer 1
+push that 0
+push local 1
+push constant 2
+add
+eq
+if-goto IF_TRUE3
+goto IF_FALSE3
+label IF_TRUE3
+push constant 1
+push local 0
+add
+push local 0
+push constant 2
+add
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+goto IF_END3
+label IF_FALSE3
+push constant 1
+push local 0
+add
+push constant 1
+push local 1
+add
+pop pointer 1
+push that 0
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+label IF_END3
+label IF_END2
+goto WHILE_EXP0
+label WHILE_END0
+push local 0
+push argument 0
+add
+push constant 16379
+gt
+if-goto IF_TRUE4
+goto IF_FALSE4
+label IF_TRUE4
+push constant 6
+call Sys.error 1
+pop temp 0
+label IF_FALSE4
+push constant 0
+push local 0
+add
+pop pointer 1
+push that 0
+push argument 0
+push constant 2
+add
+gt
+if-goto IF_TRUE5
+goto IF_FALSE5
+label IF_TRUE5
+push argument 0
+push constant 2
+add
+push local 0
+add
+push constant 0
+push local 0
+add
+pop pointer 1
+push that 0
+push argument 0
+sub
+push constant 2
+sub
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 1
+push local 0
+add
+pop pointer 1
+push that 0
+push local 0
+push constant 2
+add
+eq
+if-goto IF_TRUE6
+goto IF_FALSE6
+label IF_TRUE6
+push argument 0
+push constant 3
+add
+push local 0
+add
+push local 0
+push argument 0
+add
+push constant 4
+add
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+goto IF_END6
+label IF_FALSE6
+push argument 0
+push constant 3
+add
+push local 0
+add
+push constant 1
+push local 0
+add
+pop pointer 1
+push that 0
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+label IF_END6
+push constant 1
+push local 0
+add
+push local 0
+push argument 0
+add
+push constant 2
+add
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+label IF_FALSE5
+push constant 0
+push local 0
+add
+push constant 0
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push local 0
+push constant 2
+add
+return
+function Memory.deAlloc 2
+push argument 0
+push constant 2
+sub
+pop local 0
+push constant 1
+push local 0
+add
+pop pointer 1
+push that 0
+pop local 1
+push constant 0
+push local 1
+add
+pop pointer 1
+push that 0
+push constant 0
+eq
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 0
+push local 0
+add
+push constant 1
+push local 0
+add
+pop pointer 1
+push that 0
+push local 0
+sub
+push constant 2
+sub
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+goto IF_END0
+label IF_FALSE0
+push constant 0
+push local 0
+add
+push constant 1
+push local 0
+add
+pop pointer 1
+push that 0
+push local 0
+sub
+push constant 0
+push local 1
+add
+pop pointer 1
+push that 0
+add
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 1
+push local 1
+add
+pop pointer 1
+push that 0
+push local 1
+push constant 2
+add
+eq
+if-goto IF_TRUE1
+goto IF_FALSE1
+label IF_TRUE1
+push constant 1
+push local 0
+add
+push local 0
+push constant 2
+add
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+goto IF_END1
+label IF_FALSE1
+push constant 1
+push local 0
+add
+push constant 1
+push local 1
+add
+pop pointer 1
+push that 0
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+label IF_END1
+label IF_END0
+push constant 0
+return
diff --git a/original/tools/OS/Output.vm b/original/tools/OS/Output.vm
new file mode 100644
index 0000000..b8addd7
--- /dev/null
+++ b/original/tools/OS/Output.vm
@@ -0,0 +1,1852 @@
+function Output.init 0
+push constant 16384
+pop static 4
+push constant 0
+not
+pop static 2
+push constant 32
+pop static 1
+push constant 0
+pop static 0
+push constant 6
+call String.new 1
+pop static 3
+call Output.initMap 0
+pop temp 0
+call Output.createShiftedMap 0
+pop temp 0
+push constant 0
+return
+function Output.initMap 0
+push constant 127
+call Array.new 1
+pop static 5
+push constant 0
+push constant 63
+push constant 63
+push constant 63
+push constant 63
+push constant 63
+push constant 63
+push constant 63
+push constant 63
+push constant 63
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 32
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 33
+push constant 12
+push constant 30
+push constant 30
+push constant 30
+push constant 12
+push constant 12
+push constant 0
+push constant 12
+push constant 12
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 34
+push constant 54
+push constant 54
+push constant 20
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 35
+push constant 0
+push constant 18
+push constant 18
+push constant 63
+push constant 18
+push constant 18
+push constant 63
+push constant 18
+push constant 18
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 36
+push constant 12
+push constant 30
+push constant 51
+push constant 3
+push constant 30
+push constant 48
+push constant 51
+push constant 30
+push constant 12
+push constant 12
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 37
+push constant 0
+push constant 0
+push constant 35
+push constant 51
+push constant 24
+push constant 12
+push constant 6
+push constant 51
+push constant 49
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 38
+push constant 12
+push constant 30
+push constant 30
+push constant 12
+push constant 54
+push constant 27
+push constant 27
+push constant 27
+push constant 54
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 39
+push constant 12
+push constant 12
+push constant 6
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 40
+push constant 24
+push constant 12
+push constant 6
+push constant 6
+push constant 6
+push constant 6
+push constant 6
+push constant 12
+push constant 24
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 41
+push constant 6
+push constant 12
+push constant 24
+push constant 24
+push constant 24
+push constant 24
+push constant 24
+push constant 12
+push constant 6
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 42
+push constant 0
+push constant 0
+push constant 0
+push constant 51
+push constant 30
+push constant 63
+push constant 30
+push constant 51
+push constant 0
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 43
+push constant 0
+push constant 0
+push constant 0
+push constant 12
+push constant 12
+push constant 63
+push constant 12
+push constant 12
+push constant 0
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 44
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 12
+push constant 12
+push constant 6
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 45
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 63
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 46
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 12
+push constant 12
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 47
+push constant 0
+push constant 0
+push constant 32
+push constant 48
+push constant 24
+push constant 12
+push constant 6
+push constant 3
+push constant 1
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 48
+push constant 12
+push constant 30
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 30
+push constant 12
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 49
+push constant 12
+push constant 14
+push constant 15
+push constant 12
+push constant 12
+push constant 12
+push constant 12
+push constant 12
+push constant 63
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 50
+push constant 30
+push constant 51
+push constant 48
+push constant 24
+push constant 12
+push constant 6
+push constant 3
+push constant 51
+push constant 63
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 51
+push constant 30
+push constant 51
+push constant 48
+push constant 48
+push constant 28
+push constant 48
+push constant 48
+push constant 51
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 52
+push constant 16
+push constant 24
+push constant 28
+push constant 26
+push constant 25
+push constant 63
+push constant 24
+push constant 24
+push constant 60
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 53
+push constant 63
+push constant 3
+push constant 3
+push constant 31
+push constant 48
+push constant 48
+push constant 48
+push constant 51
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 54
+push constant 28
+push constant 6
+push constant 3
+push constant 3
+push constant 31
+push constant 51
+push constant 51
+push constant 51
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 55
+push constant 63
+push constant 49
+push constant 48
+push constant 48
+push constant 24
+push constant 12
+push constant 12
+push constant 12
+push constant 12
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 56
+push constant 30
+push constant 51
+push constant 51
+push constant 51
+push constant 30
+push constant 51
+push constant 51
+push constant 51
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 57
+push constant 30
+push constant 51
+push constant 51
+push constant 51
+push constant 62
+push constant 48
+push constant 48
+push constant 24
+push constant 14
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 58
+push constant 0
+push constant 0
+push constant 12
+push constant 12
+push constant 0
+push constant 0
+push constant 12
+push constant 12
+push constant 0
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 59
+push constant 0
+push constant 0
+push constant 12
+push constant 12
+push constant 0
+push constant 0
+push constant 12
+push constant 12
+push constant 6
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 60
+push constant 0
+push constant 0
+push constant 24
+push constant 12
+push constant 6
+push constant 3
+push constant 6
+push constant 12
+push constant 24
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 61
+push constant 0
+push constant 0
+push constant 0
+push constant 63
+push constant 0
+push constant 0
+push constant 63
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 62
+push constant 0
+push constant 0
+push constant 3
+push constant 6
+push constant 12
+push constant 24
+push constant 12
+push constant 6
+push constant 3
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 64
+push constant 30
+push constant 51
+push constant 51
+push constant 59
+push constant 59
+push constant 59
+push constant 27
+push constant 3
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 63
+push constant 30
+push constant 51
+push constant 51
+push constant 24
+push constant 12
+push constant 12
+push constant 0
+push constant 12
+push constant 12
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 65
+push constant 12
+push constant 30
+push constant 51
+push constant 51
+push constant 63
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 66
+push constant 31
+push constant 51
+push constant 51
+push constant 51
+push constant 31
+push constant 51
+push constant 51
+push constant 51
+push constant 31
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 67
+push constant 28
+push constant 54
+push constant 35
+push constant 3
+push constant 3
+push constant 3
+push constant 35
+push constant 54
+push constant 28
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 68
+push constant 15
+push constant 27
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 27
+push constant 15
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 69
+push constant 63
+push constant 51
+push constant 35
+push constant 11
+push constant 15
+push constant 11
+push constant 35
+push constant 51
+push constant 63
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 70
+push constant 63
+push constant 51
+push constant 35
+push constant 11
+push constant 15
+push constant 11
+push constant 3
+push constant 3
+push constant 3
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 71
+push constant 28
+push constant 54
+push constant 35
+push constant 3
+push constant 59
+push constant 51
+push constant 51
+push constant 54
+push constant 44
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 72
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 63
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 73
+push constant 30
+push constant 12
+push constant 12
+push constant 12
+push constant 12
+push constant 12
+push constant 12
+push constant 12
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 74
+push constant 60
+push constant 24
+push constant 24
+push constant 24
+push constant 24
+push constant 24
+push constant 27
+push constant 27
+push constant 14
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 75
+push constant 51
+push constant 51
+push constant 51
+push constant 27
+push constant 15
+push constant 27
+push constant 51
+push constant 51
+push constant 51
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 76
+push constant 3
+push constant 3
+push constant 3
+push constant 3
+push constant 3
+push constant 3
+push constant 35
+push constant 51
+push constant 63
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 77
+push constant 33
+push constant 51
+push constant 63
+push constant 63
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 78
+push constant 51
+push constant 51
+push constant 55
+push constant 55
+push constant 63
+push constant 59
+push constant 59
+push constant 51
+push constant 51
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 79
+push constant 30
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 80
+push constant 31
+push constant 51
+push constant 51
+push constant 51
+push constant 31
+push constant 3
+push constant 3
+push constant 3
+push constant 3
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 81
+push constant 30
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 63
+push constant 59
+push constant 30
+push constant 48
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 82
+push constant 31
+push constant 51
+push constant 51
+push constant 51
+push constant 31
+push constant 27
+push constant 51
+push constant 51
+push constant 51
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 83
+push constant 30
+push constant 51
+push constant 51
+push constant 6
+push constant 28
+push constant 48
+push constant 51
+push constant 51
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 84
+push constant 63
+push constant 63
+push constant 45
+push constant 12
+push constant 12
+push constant 12
+push constant 12
+push constant 12
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 85
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 86
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 30
+push constant 30
+push constant 12
+push constant 12
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 87
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 63
+push constant 63
+push constant 63
+push constant 18
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 88
+push constant 51
+push constant 51
+push constant 30
+push constant 30
+push constant 12
+push constant 30
+push constant 30
+push constant 51
+push constant 51
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 89
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 30
+push constant 12
+push constant 12
+push constant 12
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 90
+push constant 63
+push constant 51
+push constant 49
+push constant 24
+push constant 12
+push constant 6
+push constant 35
+push constant 51
+push constant 63
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 91
+push constant 30
+push constant 6
+push constant 6
+push constant 6
+push constant 6
+push constant 6
+push constant 6
+push constant 6
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 92
+push constant 0
+push constant 0
+push constant 1
+push constant 3
+push constant 6
+push constant 12
+push constant 24
+push constant 48
+push constant 32
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 93
+push constant 30
+push constant 24
+push constant 24
+push constant 24
+push constant 24
+push constant 24
+push constant 24
+push constant 24
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 94
+push constant 8
+push constant 28
+push constant 54
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 95
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 63
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 96
+push constant 6
+push constant 12
+push constant 24
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 97
+push constant 0
+push constant 0
+push constant 0
+push constant 14
+push constant 24
+push constant 30
+push constant 27
+push constant 27
+push constant 54
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 98
+push constant 3
+push constant 3
+push constant 3
+push constant 15
+push constant 27
+push constant 51
+push constant 51
+push constant 51
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 99
+push constant 0
+push constant 0
+push constant 0
+push constant 30
+push constant 51
+push constant 3
+push constant 3
+push constant 51
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 100
+push constant 48
+push constant 48
+push constant 48
+push constant 60
+push constant 54
+push constant 51
+push constant 51
+push constant 51
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 101
+push constant 0
+push constant 0
+push constant 0
+push constant 30
+push constant 51
+push constant 63
+push constant 3
+push constant 51
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 102
+push constant 28
+push constant 54
+push constant 38
+push constant 6
+push constant 15
+push constant 6
+push constant 6
+push constant 6
+push constant 15
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 103
+push constant 0
+push constant 0
+push constant 30
+push constant 51
+push constant 51
+push constant 51
+push constant 62
+push constant 48
+push constant 51
+push constant 30
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 104
+push constant 3
+push constant 3
+push constant 3
+push constant 27
+push constant 55
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 105
+push constant 12
+push constant 12
+push constant 0
+push constant 14
+push constant 12
+push constant 12
+push constant 12
+push constant 12
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 106
+push constant 48
+push constant 48
+push constant 0
+push constant 56
+push constant 48
+push constant 48
+push constant 48
+push constant 48
+push constant 51
+push constant 30
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 107
+push constant 3
+push constant 3
+push constant 3
+push constant 51
+push constant 27
+push constant 15
+push constant 15
+push constant 27
+push constant 51
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 108
+push constant 14
+push constant 12
+push constant 12
+push constant 12
+push constant 12
+push constant 12
+push constant 12
+push constant 12
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 109
+push constant 0
+push constant 0
+push constant 0
+push constant 29
+push constant 63
+push constant 43
+push constant 43
+push constant 43
+push constant 43
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 110
+push constant 0
+push constant 0
+push constant 0
+push constant 29
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 111
+push constant 0
+push constant 0
+push constant 0
+push constant 30
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 112
+push constant 0
+push constant 0
+push constant 0
+push constant 30
+push constant 51
+push constant 51
+push constant 51
+push constant 31
+push constant 3
+push constant 3
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 113
+push constant 0
+push constant 0
+push constant 0
+push constant 30
+push constant 51
+push constant 51
+push constant 51
+push constant 62
+push constant 48
+push constant 48
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 114
+push constant 0
+push constant 0
+push constant 0
+push constant 29
+push constant 55
+push constant 51
+push constant 3
+push constant 3
+push constant 7
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 115
+push constant 0
+push constant 0
+push constant 0
+push constant 30
+push constant 51
+push constant 6
+push constant 24
+push constant 51
+push constant 30
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 116
+push constant 4
+push constant 6
+push constant 6
+push constant 15
+push constant 6
+push constant 6
+push constant 6
+push constant 54
+push constant 28
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 117
+push constant 0
+push constant 0
+push constant 0
+push constant 27
+push constant 27
+push constant 27
+push constant 27
+push constant 27
+push constant 54
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 118
+push constant 0
+push constant 0
+push constant 0
+push constant 51
+push constant 51
+push constant 51
+push constant 51
+push constant 30
+push constant 12
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 119
+push constant 0
+push constant 0
+push constant 0
+push constant 51
+push constant 51
+push constant 51
+push constant 63
+push constant 63
+push constant 18
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 120
+push constant 0
+push constant 0
+push constant 0
+push constant 51
+push constant 30
+push constant 12
+push constant 12
+push constant 30
+push constant 51
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 121
+push constant 0
+push constant 0
+push constant 0
+push constant 51
+push constant 51
+push constant 51
+push constant 62
+push constant 48
+push constant 24
+push constant 15
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 122
+push constant 0
+push constant 0
+push constant 0
+push constant 63
+push constant 27
+push constant 12
+push constant 6
+push constant 51
+push constant 63
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 123
+push constant 56
+push constant 12
+push constant 12
+push constant 12
+push constant 7
+push constant 12
+push constant 12
+push constant 12
+push constant 56
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 124
+push constant 12
+push constant 12
+push constant 12
+push constant 12
+push constant 12
+push constant 12
+push constant 12
+push constant 12
+push constant 12
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 125
+push constant 7
+push constant 12
+push constant 12
+push constant 12
+push constant 56
+push constant 12
+push constant 12
+push constant 12
+push constant 7
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 126
+push constant 38
+push constant 45
+push constant 25
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+push constant 0
+call Output.create 12
+pop temp 0
+push constant 0
+return
+function Output.create 1
+push constant 11
+call Array.new 1
+pop local 0
+push argument 0
+push static 5
+add
+push local 0
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 0
+push local 0
+add
+push argument 1
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 1
+push local 0
+add
+push argument 2
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 2
+push local 0
+add
+push argument 3
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 3
+push local 0
+add
+push argument 4
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 4
+push local 0
+add
+push argument 5
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 5
+push local 0
+add
+push argument 6
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 6
+push local 0
+add
+push argument 7
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 7
+push local 0
+add
+push argument 8
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 8
+push local 0
+add
+push argument 9
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 9
+push local 0
+add
+push argument 10
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 10
+push local 0
+add
+push argument 11
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 0
+return
+function Output.createShiftedMap 4
+push constant 127
+call Array.new 1
+pop static 6
+push constant 0
+pop local 2
+label WHILE_EXP0
+push local 2
+push constant 127
+lt
+not
+if-goto WHILE_END0
+push local 2
+push static 5
+add
+pop pointer 1
+push that 0
+pop local 0
+push constant 11
+call Array.new 1
+pop local 1
+push local 2
+push static 6
+add
+push local 1
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 0
+pop local 3
+label WHILE_EXP1
+push local 3
+push constant 11
+lt
+not
+if-goto WHILE_END1
+push local 3
+push local 1
+add
+push local 3
+push local 0
+add
+pop pointer 1
+push that 0
+push constant 256
+call Math.multiply 2
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push local 3
+push constant 1
+add
+pop local 3
+goto WHILE_EXP1
+label WHILE_END1
+push local 2
+push constant 0
+eq
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 32
+pop local 2
+goto IF_END0
+label IF_FALSE0
+push local 2
+push constant 1
+add
+pop local 2
+label IF_END0
+goto WHILE_EXP0
+label WHILE_END0
+push constant 0
+return
+function Output.getMap 1
+push argument 0
+push constant 32
+lt
+push argument 0
+push constant 126
+gt
+or
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 0
+pop argument 0
+label IF_FALSE0
+push static 2
+if-goto IF_TRUE1
+goto IF_FALSE1
+label IF_TRUE1
+push argument 0
+push static 5
+add
+pop pointer 1
+push that 0
+pop local 0
+goto IF_END1
+label IF_FALSE1
+push argument 0
+push static 6
+add
+pop pointer 1
+push that 0
+pop local 0
+label IF_END1
+push local 0
+return
+function Output.drawChar 4
+push argument 0
+call Output.getMap 1
+pop local 2
+push static 1
+pop local 0
+label WHILE_EXP0
+push local 1
+push constant 11
+lt
+not
+if-goto WHILE_END0
+push static 2
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push local 0
+push static 4
+add
+pop pointer 1
+push that 0
+push constant 256
+neg
+and
+pop local 3
+goto IF_END0
+label IF_FALSE0
+push local 0
+push static 4
+add
+pop pointer 1
+push that 0
+push constant 255
+and
+pop local 3
+label IF_END0
+push local 0
+push static 4
+add
+push local 1
+push local 2
+add
+pop pointer 1
+push that 0
+push local 3
+or
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push local 0
+push constant 32
+add
+pop local 0
+push local 1
+push constant 1
+add
+pop local 1
+goto WHILE_EXP0
+label WHILE_END0
+push constant 0
+return
+function Output.moveCursor 0
+push argument 0
+push constant 0
+lt
+push argument 0
+push constant 22
+gt
+or
+push argument 1
+push constant 0
+lt
+or
+push argument 1
+push constant 63
+gt
+or
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 20
+call Sys.error 1
+pop temp 0
+label IF_FALSE0
+push argument 1
+push constant 2
+call Math.divide 2
+pop static 0
+push constant 32
+push argument 0
+push constant 352
+call Math.multiply 2
+add
+push static 0
+add
+pop static 1
+push argument 1
+push static 0
+push constant 2
+call Math.multiply 2
+eq
+pop static 2
+push constant 32
+call Output.drawChar 1
+pop temp 0
+push constant 0
+return
+function Output.printChar 0
+push argument 0
+call String.newLine 0
+eq
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+call Output.println 0
+pop temp 0
+goto IF_END0
+label IF_FALSE0
+push argument 0
+call String.backSpace 0
+eq
+if-goto IF_TRUE1
+goto IF_FALSE1
+label IF_TRUE1
+call Output.backSpace 0
+pop temp 0
+goto IF_END1
+label IF_FALSE1
+push argument 0
+call Output.drawChar 1
+pop temp 0
+push static 2
+not
+if-goto IF_TRUE2
+goto IF_FALSE2
+label IF_TRUE2
+push static 0
+push constant 1
+add
+pop static 0
+push static 1
+push constant 1
+add
+pop static 1
+label IF_FALSE2
+push static 0
+push constant 32
+eq
+if-goto IF_TRUE3
+goto IF_FALSE3
+label IF_TRUE3
+call Output.println 0
+pop temp 0
+goto IF_END3
+label IF_FALSE3
+push static 2
+not
+pop static 2
+label IF_END3
+label IF_END1
+label IF_END0
+push constant 0
+return
+function Output.printString 2
+push argument 0
+call String.length 1
+pop local 1
+label WHILE_EXP0
+push local 0
+push local 1
+lt
+not
+if-goto WHILE_END0
+push argument 0
+push local 0
+call String.charAt 2
+call Output.printChar 1
+pop temp 0
+push local 0
+push constant 1
+add
+pop local 0
+goto WHILE_EXP0
+label WHILE_END0
+push constant 0
+return
+function Output.printInt 0
+push static 3
+push argument 0
+call String.setInt 2
+pop temp 0
+push static 3
+call Output.printString 1
+pop temp 0
+push constant 0
+return
+function Output.println 0
+push static 1
+push constant 352
+add
+push static 0
+sub
+pop static 1
+push constant 0
+pop static 0
+push constant 0
+not
+pop static 2
+push static 1
+push constant 8128
+eq
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 32
+pop static 1
+label IF_FALSE0
+push constant 0
+return
+function Output.backSpace 0
+push static 2
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push static 0
+push constant 0
+gt
+if-goto IF_TRUE1
+goto IF_FALSE1
+label IF_TRUE1
+push static 0
+push constant 1
+sub
+pop static 0
+push static 1
+push constant 1
+sub
+pop static 1
+goto IF_END1
+label IF_FALSE1
+push constant 31
+pop static 0
+push static 1
+push constant 32
+eq
+if-goto IF_TRUE2
+goto IF_FALSE2
+label IF_TRUE2
+push constant 8128
+pop static 1
+label IF_FALSE2
+push static 1
+push constant 321
+sub
+pop static 1
+label IF_END1
+push constant 0
+pop static 2
+goto IF_END0
+label IF_FALSE0
+push constant 0
+not
+pop static 2
+label IF_END0
+push constant 32
+call Output.drawChar 1
+pop temp 0
+push constant 0
+return
diff --git a/original/tools/OS/Screen.vm b/original/tools/OS/Screen.vm
new file mode 100644
index 0000000..fccafb5
--- /dev/null
+++ b/original/tools/OS/Screen.vm
@@ -0,0 +1,806 @@
+function Screen.init 1
+push constant 16384
+pop static 1
+push constant 0
+not
+pop static 2
+push constant 17
+call Array.new 1
+pop static 0
+push constant 0
+push static 0
+add
+push constant 1
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+label WHILE_EXP0
+push local 0
+push constant 16
+lt
+not
+if-goto WHILE_END0
+push local 0
+push constant 1
+add
+pop local 0
+push local 0
+push static 0
+add
+push local 0
+push constant 1
+sub
+push static 0
+add
+pop pointer 1
+push that 0
+push local 0
+push constant 1
+sub
+push static 0
+add
+pop pointer 1
+push that 0
+add
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+goto WHILE_EXP0
+label WHILE_END0
+push constant 0
+return
+function Screen.clearScreen 1
+label WHILE_EXP0
+push local 0
+push constant 8192
+lt
+not
+if-goto WHILE_END0
+push local 0
+push static 1
+add
+push constant 0
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push local 0
+push constant 1
+add
+pop local 0
+goto WHILE_EXP0
+label WHILE_END0
+push constant 0
+return
+function Screen.updateLocation 0
+push static 2
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push argument 0
+push static 1
+add
+push argument 0
+push static 1
+add
+pop pointer 1
+push that 0
+push argument 1
+or
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+goto IF_END0
+label IF_FALSE0
+push argument 0
+push static 1
+add
+push argument 0
+push static 1
+add
+pop pointer 1
+push that 0
+push argument 1
+not
+and
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+label IF_END0
+push constant 0
+return
+function Screen.setColor 0
+push argument 0
+pop static 2
+push constant 0
+return
+function Screen.drawPixel 3
+push argument 0
+push constant 0
+lt
+push argument 0
+push constant 511
+gt
+or
+push argument 1
+push constant 0
+lt
+or
+push argument 1
+push constant 255
+gt
+or
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 7
+call Sys.error 1
+pop temp 0
+label IF_FALSE0
+push argument 0
+push constant 16
+call Math.divide 2
+pop local 0
+push argument 0
+push local 0
+push constant 16
+call Math.multiply 2
+sub
+pop local 1
+push argument 1
+push constant 32
+call Math.multiply 2
+push local 0
+add
+pop local 2
+push local 2
+push local 1
+push static 0
+add
+pop pointer 1
+push that 0
+call Screen.updateLocation 2
+pop temp 0
+push constant 0
+return
+function Screen.drawConditional 0
+push argument 2
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push argument 1
+push argument 0
+call Screen.drawPixel 2
+pop temp 0
+goto IF_END0
+label IF_FALSE0
+push argument 0
+push argument 1
+call Screen.drawPixel 2
+pop temp 0
+label IF_END0
+push constant 0
+return
+function Screen.drawLine 11
+push argument 0
+push constant 0
+lt
+push argument 2
+push constant 511
+gt
+or
+push argument 1
+push constant 0
+lt
+or
+push argument 3
+push constant 255
+gt
+or
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 8
+call Sys.error 1
+pop temp 0
+label IF_FALSE0
+push argument 2
+push argument 0
+sub
+call Math.abs 1
+pop local 3
+push argument 3
+push argument 1
+sub
+call Math.abs 1
+pop local 2
+push local 3
+push local 2
+lt
+pop local 6
+push local 6
+push argument 3
+push argument 1
+lt
+and
+push local 6
+not
+push argument 2
+push argument 0
+lt
+and
+or
+if-goto IF_TRUE1
+goto IF_FALSE1
+label IF_TRUE1
+push argument 0
+pop local 4
+push argument 2
+pop argument 0
+push local 4
+pop argument 2
+push argument 1
+pop local 4
+push argument 3
+pop argument 1
+push local 4
+pop argument 3
+label IF_FALSE1
+push local 6
+if-goto IF_TRUE2
+goto IF_FALSE2
+label IF_TRUE2
+push local 3
+pop local 4
+push local 2
+pop local 3
+push local 4
+pop local 2
+push argument 1
+pop local 1
+push argument 0
+pop local 0
+push argument 3
+pop local 8
+push argument 0
+push argument 2
+gt
+pop local 7
+goto IF_END2
+label IF_FALSE2
+push argument 0
+pop local 1
+push argument 1
+pop local 0
+push argument 2
+pop local 8
+push argument 1
+push argument 3
+gt
+pop local 7
+label IF_END2
+push constant 2
+push local 2
+call Math.multiply 2
+push local 3
+sub
+pop local 5
+push constant 2
+push local 2
+call Math.multiply 2
+pop local 9
+push constant 2
+push local 2
+push local 3
+sub
+call Math.multiply 2
+pop local 10
+push local 1
+push local 0
+push local 6
+call Screen.drawConditional 3
+pop temp 0
+label WHILE_EXP0
+push local 1
+push local 8
+lt
+not
+if-goto WHILE_END0
+push local 5
+push constant 0
+lt
+if-goto IF_TRUE3
+goto IF_FALSE3
+label IF_TRUE3
+push local 5
+push local 9
+add
+pop local 5
+goto IF_END3
+label IF_FALSE3
+push local 5
+push local 10
+add
+pop local 5
+push local 7
+if-goto IF_TRUE4
+goto IF_FALSE4
+label IF_TRUE4
+push local 0
+push constant 1
+sub
+pop local 0
+goto IF_END4
+label IF_FALSE4
+push local 0
+push constant 1
+add
+pop local 0
+label IF_END4
+label IF_END3
+push local 1
+push constant 1
+add
+pop local 1
+push local 1
+push local 0
+push local 6
+call Screen.drawConditional 3
+pop temp 0
+goto WHILE_EXP0
+label WHILE_END0
+push constant 0
+return
+function Screen.drawRectangle 9
+push argument 0
+push argument 2
+gt
+push argument 1
+push argument 3
+gt
+or
+push argument 0
+push constant 0
+lt
+or
+push argument 2
+push constant 511
+gt
+or
+push argument 1
+push constant 0
+lt
+or
+push argument 3
+push constant 255
+gt
+or
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 9
+call Sys.error 1
+pop temp 0
+label IF_FALSE0
+push argument 0
+push constant 16
+call Math.divide 2
+pop local 3
+push argument 0
+push local 3
+push constant 16
+call Math.multiply 2
+sub
+pop local 7
+push argument 2
+push constant 16
+call Math.divide 2
+pop local 4
+push argument 2
+push local 4
+push constant 16
+call Math.multiply 2
+sub
+pop local 8
+push local 7
+push static 0
+add
+pop pointer 1
+push that 0
+push constant 1
+sub
+not
+pop local 6
+push local 8
+push constant 1
+add
+push static 0
+add
+pop pointer 1
+push that 0
+push constant 1
+sub
+pop local 5
+push argument 1
+push constant 32
+call Math.multiply 2
+push local 3
+add
+pop local 0
+push local 4
+push local 3
+sub
+pop local 2
+label WHILE_EXP0
+push argument 1
+push argument 3
+gt
+not
+not
+if-goto WHILE_END0
+push local 0
+push local 2
+add
+pop local 1
+push local 2
+push constant 0
+eq
+if-goto IF_TRUE1
+goto IF_FALSE1
+label IF_TRUE1
+push local 0
+push local 5
+push local 6
+and
+call Screen.updateLocation 2
+pop temp 0
+goto IF_END1
+label IF_FALSE1
+push local 0
+push local 6
+call Screen.updateLocation 2
+pop temp 0
+push local 0
+push constant 1
+add
+pop local 0
+label WHILE_EXP1
+push local 0
+push local 1
+lt
+not
+if-goto WHILE_END1
+push local 0
+push constant 1
+neg
+call Screen.updateLocation 2
+pop temp 0
+push local 0
+push constant 1
+add
+pop local 0
+goto WHILE_EXP1
+label WHILE_END1
+push local 1
+push local 5
+call Screen.updateLocation 2
+pop temp 0
+label IF_END1
+push argument 1
+push constant 1
+add
+pop argument 1
+push local 1
+push constant 32
+add
+push local 2
+sub
+pop local 0
+goto WHILE_EXP0
+label WHILE_END0
+push constant 0
+return
+function Screen.drawHorizontal 11
+push argument 1
+push argument 2
+call Math.min 2
+pop local 7
+push argument 1
+push argument 2
+call Math.max 2
+pop local 8
+push argument 0
+push constant 1
+neg
+gt
+push argument 0
+push constant 256
+lt
+and
+push local 7
+push constant 512
+lt
+and
+push local 8
+push constant 1
+neg
+gt
+and
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push local 7
+push constant 0
+call Math.max 2
+pop local 7
+push local 8
+push constant 511
+call Math.min 2
+pop local 8
+push local 7
+push constant 16
+call Math.divide 2
+pop local 1
+push local 7
+push local 1
+push constant 16
+call Math.multiply 2
+sub
+pop local 9
+push local 8
+push constant 16
+call Math.divide 2
+pop local 2
+push local 8
+push local 2
+push constant 16
+call Math.multiply 2
+sub
+pop local 10
+push local 9
+push static 0
+add
+pop pointer 1
+push that 0
+push constant 1
+sub
+not
+pop local 5
+push local 10
+push constant 1
+add
+push static 0
+add
+pop pointer 1
+push that 0
+push constant 1
+sub
+pop local 4
+push argument 0
+push constant 32
+call Math.multiply 2
+push local 1
+add
+pop local 0
+push local 2
+push local 1
+sub
+pop local 6
+push local 0
+push local 6
+add
+pop local 3
+push local 6
+push constant 0
+eq
+if-goto IF_TRUE1
+goto IF_FALSE1
+label IF_TRUE1
+push local 0
+push local 4
+push local 5
+and
+call Screen.updateLocation 2
+pop temp 0
+goto IF_END1
+label IF_FALSE1
+push local 0
+push local 5
+call Screen.updateLocation 2
+pop temp 0
+push local 0
+push constant 1
+add
+pop local 0
+label WHILE_EXP0
+push local 0
+push local 3
+lt
+not
+if-goto WHILE_END0
+push local 0
+push constant 1
+neg
+call Screen.updateLocation 2
+pop temp 0
+push local 0
+push constant 1
+add
+pop local 0
+goto WHILE_EXP0
+label WHILE_END0
+push local 3
+push local 4
+call Screen.updateLocation 2
+pop temp 0
+label IF_END1
+label IF_FALSE0
+push constant 0
+return
+function Screen.drawSymetric 0
+push argument 1
+push argument 3
+sub
+push argument 0
+push argument 2
+add
+push argument 0
+push argument 2
+sub
+call Screen.drawHorizontal 3
+pop temp 0
+push argument 1
+push argument 3
+add
+push argument 0
+push argument 2
+add
+push argument 0
+push argument 2
+sub
+call Screen.drawHorizontal 3
+pop temp 0
+push argument 1
+push argument 2
+sub
+push argument 0
+push argument 3
+sub
+push argument 0
+push argument 3
+add
+call Screen.drawHorizontal 3
+pop temp 0
+push argument 1
+push argument 2
+add
+push argument 0
+push argument 3
+sub
+push argument 0
+push argument 3
+add
+call Screen.drawHorizontal 3
+pop temp 0
+push constant 0
+return
+function Screen.drawCircle 3
+push argument 0
+push constant 0
+lt
+push argument 0
+push constant 511
+gt
+or
+push argument 1
+push constant 0
+lt
+or
+push argument 1
+push constant 255
+gt
+or
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 12
+call Sys.error 1
+pop temp 0
+label IF_FALSE0
+push argument 0
+push argument 2
+sub
+push constant 0
+lt
+push argument 0
+push argument 2
+add
+push constant 511
+gt
+or
+push argument 1
+push argument 2
+sub
+push constant 0
+lt
+or
+push argument 1
+push argument 2
+add
+push constant 255
+gt
+or
+if-goto IF_TRUE1
+goto IF_FALSE1
+label IF_TRUE1
+push constant 13
+call Sys.error 1
+pop temp 0
+label IF_FALSE1
+push argument 2
+pop local 1
+push constant 1
+push argument 2
+sub
+pop local 2
+push argument 0
+push argument 1
+push local 0
+push local 1
+call Screen.drawSymetric 4
+pop temp 0
+label WHILE_EXP0
+push local 1
+push local 0
+gt
+not
+if-goto WHILE_END0
+push local 2
+push constant 0
+lt
+if-goto IF_TRUE2
+goto IF_FALSE2
+label IF_TRUE2
+push local 2
+push constant 2
+push local 0
+call Math.multiply 2
+add
+push constant 3
+add
+pop local 2
+goto IF_END2
+label IF_FALSE2
+push local 2
+push constant 2
+push local 0
+push local 1
+sub
+call Math.multiply 2
+add
+push constant 5
+add
+pop local 2
+push local 1
+push constant 1
+sub
+pop local 1
+label IF_END2
+push local 0
+push constant 1
+add
+pop local 0
+push argument 0
+push argument 1
+push local 0
+push local 1
+call Screen.drawSymetric 4
+pop temp 0
+goto WHILE_EXP0
+label WHILE_END0
+push constant 0
+return
diff --git a/original/tools/OS/String.vm b/original/tools/OS/String.vm
new file mode 100644
index 0000000..9b7577e
--- /dev/null
+++ b/original/tools/OS/String.vm
@@ -0,0 +1,393 @@
+function String.new 0
+push constant 3
+call Memory.alloc 1
+pop pointer 0
+push argument 0
+push constant 0
+lt
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 14
+call Sys.error 1
+pop temp 0
+label IF_FALSE0
+push argument 0
+push constant 0
+gt
+if-goto IF_TRUE1
+goto IF_FALSE1
+label IF_TRUE1
+push argument 0
+call Array.new 1
+pop this 1
+label IF_FALSE1
+push argument 0
+pop this 0
+push constant 0
+pop this 2
+push pointer 0
+return
+function String.dispose 0
+push argument 0
+pop pointer 0
+push this 0
+push constant 0
+gt
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push this 1
+call Array.dispose 1
+pop temp 0
+label IF_FALSE0
+push pointer 0
+call Memory.deAlloc 1
+pop temp 0
+push constant 0
+return
+function String.length 0
+push argument 0
+pop pointer 0
+push this 2
+return
+function String.charAt 0
+push argument 0
+pop pointer 0
+push argument 1
+push constant 0
+lt
+push argument 1
+push this 2
+gt
+or
+push argument 1
+push this 2
+eq
+or
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 15
+call Sys.error 1
+pop temp 0
+label IF_FALSE0
+push argument 1
+push this 1
+add
+pop pointer 1
+push that 0
+return
+function String.setCharAt 0
+push argument 0
+pop pointer 0
+push argument 1
+push constant 0
+lt
+push argument 1
+push this 2
+gt
+or
+push argument 1
+push this 2
+eq
+or
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 16
+call Sys.error 1
+pop temp 0
+label IF_FALSE0
+push argument 1
+push this 1
+add
+push argument 2
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 0
+return
+function String.appendChar 0
+push argument 0
+pop pointer 0
+push this 2
+push this 0
+eq
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 17
+call Sys.error 1
+pop temp 0
+label IF_FALSE0
+push this 2
+push this 1
+add
+push argument 1
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push this 2
+push constant 1
+add
+pop this 2
+push pointer 0
+return
+function String.eraseLastChar 0
+push argument 0
+pop pointer 0
+push this 2
+push constant 0
+eq
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 18
+call Sys.error 1
+pop temp 0
+label IF_FALSE0
+push this 2
+push constant 1
+sub
+pop this 2
+push constant 0
+return
+function String.intValue 5
+push argument 0
+pop pointer 0
+push this 2
+push constant 0
+eq
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 0
+return
+label IF_FALSE0
+push constant 0
+not
+pop local 3
+push constant 0
+push this 1
+add
+pop pointer 1
+push that 0
+push constant 45
+eq
+if-goto IF_TRUE1
+goto IF_FALSE1
+label IF_TRUE1
+push constant 0
+not
+pop local 4
+push constant 1
+pop local 0
+label IF_FALSE1
+label WHILE_EXP0
+push local 0
+push this 2
+lt
+push local 3
+and
+not
+if-goto WHILE_END0
+push local 0
+push this 1
+add
+pop pointer 1
+push that 0
+push constant 48
+sub
+pop local 2
+push local 2
+push constant 0
+lt
+push local 2
+push constant 9
+gt
+or
+not
+pop local 3
+push local 3
+if-goto IF_TRUE2
+goto IF_FALSE2
+label IF_TRUE2
+push local 1
+push constant 10
+call Math.multiply 2
+push local 2
+add
+pop local 1
+push local 0
+push constant 1
+add
+pop local 0
+label IF_FALSE2
+goto WHILE_EXP0
+label WHILE_END0
+push local 4
+if-goto IF_TRUE3
+goto IF_FALSE3
+label IF_TRUE3
+push local 1
+neg
+pop local 1
+label IF_FALSE3
+push local 1
+return
+function String.setInt 4
+push argument 0
+pop pointer 0
+push this 0
+push constant 0
+eq
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 19
+call Sys.error 1
+pop temp 0
+label IF_FALSE0
+push constant 6
+call Array.new 1
+pop local 2
+push argument 1
+push constant 0
+lt
+if-goto IF_TRUE1
+goto IF_FALSE1
+label IF_TRUE1
+push constant 0
+not
+pop local 3
+push argument 1
+neg
+pop argument 1
+label IF_FALSE1
+push argument 1
+pop local 1
+label WHILE_EXP0
+push local 1
+push constant 0
+gt
+not
+if-goto WHILE_END0
+push argument 1
+push constant 10
+call Math.divide 2
+pop local 1
+push local 0
+push local 2
+add
+push constant 48
+push argument 1
+push local 1
+push constant 10
+call Math.multiply 2
+sub
+add
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push local 0
+push constant 1
+add
+pop local 0
+push local 1
+pop argument 1
+goto WHILE_EXP0
+label WHILE_END0
+push local 3
+if-goto IF_TRUE2
+goto IF_FALSE2
+label IF_TRUE2
+push local 0
+push local 2
+add
+push constant 45
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push local 0
+push constant 1
+add
+pop local 0
+label IF_FALSE2
+push this 0
+push local 0
+lt
+if-goto IF_TRUE3
+goto IF_FALSE3
+label IF_TRUE3
+push constant 19
+call Sys.error 1
+pop temp 0
+label IF_FALSE3
+push local 0
+push constant 0
+eq
+if-goto IF_TRUE4
+goto IF_FALSE4
+label IF_TRUE4
+push constant 0
+push this 1
+add
+push constant 48
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push constant 1
+pop this 2
+goto IF_END4
+label IF_FALSE4
+push constant 0
+pop this 2
+label WHILE_EXP1
+push this 2
+push local 0
+lt
+not
+if-goto WHILE_END1
+push this 2
+push this 1
+add
+push local 0
+push this 2
+push constant 1
+add
+sub
+push local 2
+add
+pop pointer 1
+push that 0
+pop temp 0
+pop pointer 1
+push temp 0
+pop that 0
+push this 2
+push constant 1
+add
+pop this 2
+goto WHILE_EXP1
+label WHILE_END1
+label IF_END4
+push local 2
+call Array.dispose 1
+pop temp 0
+push constant 0
+return
+function String.newLine 0
+push constant 128
+return
+function String.backSpace 0
+push constant 129
+return
+function String.doubleQuote 0
+push constant 34
+return
diff --git a/original/tools/OS/Sys.vm b/original/tools/OS/Sys.vm
new file mode 100644
index 0000000..c186dad
--- /dev/null
+++ b/original/tools/OS/Sys.vm
@@ -0,0 +1,83 @@
+function Sys.init 0
+call Memory.init 0
+pop temp 0
+call Math.init 0
+pop temp 0
+call Screen.init 0
+pop temp 0
+call Output.init 0
+pop temp 0
+call Keyboard.init 0
+pop temp 0
+call Main.main 0
+pop temp 0
+call Sys.halt 0
+pop temp 0
+push constant 0
+return
+function Sys.halt 0
+label WHILE_EXP0
+push constant 0
+not
+not
+if-goto WHILE_END0
+goto WHILE_EXP0
+label WHILE_END0
+push constant 0
+return
+function Sys.wait 1
+push argument 0
+push constant 0
+lt
+if-goto IF_TRUE0
+goto IF_FALSE0
+label IF_TRUE0
+push constant 1
+call Sys.error 1
+pop temp 0
+label IF_FALSE0
+label WHILE_EXP0
+push argument 0
+push constant 0
+gt
+not
+if-goto WHILE_END0
+push constant 50
+pop local 0
+label WHILE_EXP1
+push local 0
+push constant 0
+gt
+not
+if-goto WHILE_END1
+push local 0
+push constant 1
+sub
+pop local 0
+goto WHILE_EXP1
+label WHILE_END1
+push argument 0
+push constant 1
+sub
+pop argument 0
+goto WHILE_EXP0
+label WHILE_END0
+push constant 0
+return
+function Sys.error 0
+push constant 69
+call Output.printChar 1
+pop temp 0
+push constant 82
+call Output.printChar 1
+pop temp 0
+push constant 82
+call Output.printChar 1
+pop temp 0
+push argument 0
+call Output.printInt 1
+pop temp 0
+call Sys.halt 0
+pop temp 0
+push constant 0
+return
diff --git a/original/tools/TextComparer.bat b/original/tools/TextComparer.bat
new file mode 100644
index 0000000..a036d00
--- /dev/null
+++ b/original/tools/TextComparer.bat
@@ -0,0 +1,29 @@
+@echo off
+
+rem $Id: TextComparer.bat,v 1.2 2014/05/10 00:52:43 marka Exp $
+rem mark.armbrust@pobox.com
+
+setlocal
+if not "%3"=="" goto :USAGE
+if "%1"=="/?" goto :USAGE
+if not "%~1"=="" (
+ set "_arg1=%~f1"
+)
+if not "%~2"=="" (
+ set "_arg2=%~f2"
+)
+pushd "%~dp0"
+if NOT "%~1"=="" (
+ if NOT "%~2"=="" (
+ java -classpath "%CLASSPATH%;bin/classes" TextComparer ^
+ "%_arg1%" "%_arg2%"
+ popd
+ exit /B
+ )
+)
+:USAGE
+echo Usage:
+echo TextComparer FILE1 FILE2 Compares FILE1 and FILE2. The success
+echo message or the first miscompared line
+echo is printed to the command console.
+popd
diff --git a/original/tools/TextComparer.sh b/original/tools/TextComparer.sh
new file mode 100644
index 0000000..c8b08af
--- /dev/null
+++ b/original/tools/TextComparer.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env sh
+
+# $Id: TextComparer.sh,v 1.1 2014/06/17 21:14:01 marka Exp $
+# mark.armbrust@pobox.com
+
+# User's CDPATH can interfere with cd in this script
+unset CDPATH
+# Get the true name of this script
+script="`test -L "$0" && readlink -n "$0" || echo "$0"`"
+dir="$PWD"
+cd "`dirname "$script"`"
+if [ \( $# -ne 2 \) -o \( "$1" = "-h" \) -o \( "$1" = "--help" \) ]
+then
+ # print usage
+ echo "Usage:"
+ echo " `basename "$0"` FILE1 FILE2 Compares FILE1 and FILE2. The success"
+ echo " message or the first miscompared line"
+ echo " is printed to the command console."
+else
+ # Convert arg1 to an absolute path
+ if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ]
+ then
+ arg1="$1"
+ else
+ arg1="$dir/$1"
+ fi
+ # Convert arg2 to an absolute path
+ if [ `echo "$2" | sed -e "s/\(.\).*/\1/"` = / ]
+ then
+ arg2="$2"
+ else
+ arg2="$dir/$2"
+ fi
+# echo Comparing "$arg1" "$arg2"
+ java -classpath "${CLASSPATH}:bin/classes" TextComparer "$arg1" "$arg2"
+fi
diff --git a/original/tools/VMEmulator.bat b/original/tools/VMEmulator.bat
new file mode 100644
index 0000000..1b15b72
--- /dev/null
+++ b/original/tools/VMEmulator.bat
@@ -0,0 +1,29 @@
+@echo off
+
+rem $Id: VMEmulator.bat,v 1.3 2014/05/10 00:51:55 marka Exp $
+rem mark.armbrust@pobox.com
+
+setlocal
+if not "%2"=="" goto :USAGE
+if "%~1"=="/?" (
+:USAGE
+ echo Usage:
+ echo VMEmulator Starts the VM Emulator in interactive mode.
+ echo VMEmulator FILE.tst Starts the VM Emulator and runs the FILE.tst test
+ echo script. The success/failure message is
+ echo printed to the command console.
+ exit -b
+)
+if not "%~1"=="" (
+ set "_arg1=%~f1"
+)
+pushd "%~dp0"
+if "%~1"=="" (
+ start javaw -classpath "%CLASSPATH%;.;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^
+ VMEmulatorMain
+) else (
+rem echo Running "%_arg1%"
+ java -classpath "%CLASSPATH%;.;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^
+ VMEmulatorMain "%_arg1%"
+)
+popd
diff --git a/original/tools/VMEmulator.sh b/original/tools/VMEmulator.sh
new file mode 100644
index 0000000..48f4f0f
--- /dev/null
+++ b/original/tools/VMEmulator.sh
@@ -0,0 +1,33 @@
+#!/usr/bin/env sh
+
+# $Id: VMEmulator.sh,v 1.1 2014/06/17 21:14:01 marka Exp $
+# mark.armbrust@pobox.com
+
+# User's CDPATH can interfere with cd in this script
+unset CDPATH
+# Get the true name of this script
+script="`test -L "$0" && readlink -n "$0" || echo "$0"`"
+dir="$PWD"
+cd "`dirname "$script"`"
+if [ \( $# -gt 1 \) -o \( "$1" = "-h" \) -o \( "$1" = "--help" \) ]
+then
+ echo "Usage:"
+ echo " `basename "$0"` Starts the VM Emulator in interactive mode."
+ echo " `basename "$0"` FILE.tst Starts the VM Emulator and runs the FILE.tst test"
+ echo " script. The success/failure message is"
+ echo " printed to the command console."
+elif [ $# -eq 0 ]
+then
+ # Run VM emulator in interactive mode
+ java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Simulators.jar:bin/lib/SimulatorsGUI.jar:bin/lib/Compilers.jar" VMEmulatorMain &
+else
+ # Convert arg1 to an absolute path and run VM emulator with arg1
+ if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ]
+ then
+ arg1="$1"
+ else
+ arg1="${dir}/$1"
+ fi
+# echo Running "$arg1"
+ java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Simulators.jar:bin/lib/SimulatorsGUI.jar:bin/lib/Compilers.jar" VMEmulatorMain "$arg1"
+fi
diff --git a/original/tools/bin/Assembler.dat b/original/tools/bin/Assembler.dat
new file mode 100644
index 0000000..a88f0bc
--- /dev/null
+++ b/original/tools/bin/Assembler.dat
@@ -0,0 +1 @@
+/Users/shimonschocken/Downloads/Add.asm
diff --git a/original/tools/bin/CPU Emulator.dat b/original/tools/bin/CPU Emulator.dat
new file mode 100644
index 0000000..12f980a
--- /dev/null
+++ b/original/tools/bin/CPU Emulator.dat
@@ -0,0 +1 @@
+/Users/shimonschocken/Downloads
diff --git a/original/tools/bin/Hardware Simulator.dat b/original/tools/bin/Hardware Simulator.dat
new file mode 100644
index 0000000..a79d1e7
--- /dev/null
+++ b/original/tools/bin/Hardware Simulator.dat
@@ -0,0 +1 @@
+/home/netalondon/Downloads/nand2tetris_new/projects/5
diff --git a/original/tools/bin/Virtual Machine Emulator.dat b/original/tools/bin/Virtual Machine Emulator.dat
new file mode 100644
index 0000000..019ad7c
--- /dev/null
+++ b/original/tools/bin/Virtual Machine Emulator.dat
@@ -0,0 +1 @@
+/home/netalondon/Downloads/nand2tetris_new/projects/8/ProgramFlow/BasicLoop
diff --git a/original/tools/bin/classes/CPUEmulatorMain.class b/original/tools/bin/classes/CPUEmulatorMain.class
new file mode 100644
index 0000000..2c5b68f
Binary files /dev/null and b/original/tools/bin/classes/CPUEmulatorMain.class differ
diff --git a/original/tools/bin/classes/HackAssemblerMain.class b/original/tools/bin/classes/HackAssemblerMain.class
new file mode 100644
index 0000000..b912391
Binary files /dev/null and b/original/tools/bin/classes/HackAssemblerMain.class differ
diff --git a/original/tools/bin/classes/HardwareSimulatorMain.class b/original/tools/bin/classes/HardwareSimulatorMain.class
new file mode 100644
index 0000000..5786077
Binary files /dev/null and b/original/tools/bin/classes/HardwareSimulatorMain.class differ
diff --git a/original/tools/bin/classes/TextComparer.class b/original/tools/bin/classes/TextComparer.class
new file mode 100644
index 0000000..f2e076e
Binary files /dev/null and b/original/tools/bin/classes/TextComparer.class differ
diff --git a/original/tools/bin/classes/VMEmulatorMain.class b/original/tools/bin/classes/VMEmulatorMain.class
new file mode 100644
index 0000000..aa6b7ff
Binary files /dev/null and b/original/tools/bin/classes/VMEmulatorMain.class differ
diff --git a/original/tools/bin/help/asmAbout.html b/original/tools/bin/help/asmAbout.html
new file mode 100644
index 0000000..919e539
--- /dev/null
+++ b/original/tools/bin/help/asmAbout.html
@@ -0,0 +1,96 @@
+
+
+
+
+
+
+
+
+About Assembler
+
+
+
+
+
+
+
+
+
+
Assembler, Version 2.5
+
+
+
+
This program is
+part of www.nand2tetris.org
+
+
and
+the book "The Elements of Computing Systems"
+
+
by
+Nisan and Schocken, MIT Press.
+
+
+
+
Software Architects: Yaron Ukrainitz and Yannai A. Gonczarowski
+
+
+
+
+
+
+
+
diff --git a/original/tools/bin/help/asmUsage.html b/original/tools/bin/help/asmUsage.html
new file mode 100644
index 0000000..1e18db2
--- /dev/null
+++ b/original/tools/bin/help/asmUsage.html
@@ -0,0 +1,115 @@
+
+
+
+
+
+
+
+
+Usage instruction and tips can be found in:
+
+
+
+
+
+
+
+
+
+
Usage instruction and tips can be found in:
+
+
+
+
The Assembler Tutorial
+
+
+
+
Available in www.nand2tetris.org
+
+
+
+
And in relevant book chapters from
+
+
The Elements of Computing Systems,
+
+
by Noam Nisan and Shimon Schocken
+
+
MIT Press
+
+
+
+
+
+
+
+
diff --git a/original/tools/bin/help/compiler.txt b/original/tools/bin/help/compiler.txt
new file mode 100644
index 0000000..07bbba9
--- /dev/null
+++ b/original/tools/bin/help/compiler.txt
@@ -0,0 +1,9 @@
+Jack Compiler, Version 2.5
+
+This program is part of www.nand2tetris.org
+and the book "The Elements of Computing Systems"
+by Nisan and Schocken, MIT Press.
+
+Software Architects: Yaron Ukrainitz and Yannai A. Gonczarowski
+
+Usage instruction and tips can be found in the relevant book chapters.
diff --git a/original/tools/bin/help/cpuAbout.html b/original/tools/bin/help/cpuAbout.html
new file mode 100644
index 0000000..f806d5e
--- /dev/null
+++ b/original/tools/bin/help/cpuAbout.html
@@ -0,0 +1,96 @@
+
+
+
+
+
+
+
+
+About CPU Emulator
+
+
+
+
+
+
+
+
+
+
CPU Emulator, Version 2.5
+
+
+
+
This program is
+part of www.nand2tetris.org
+
+
and
+the book "The Elements of Computing Systems"
+
+
by
+Nisan and Schocken, MIT Press.
+
+
+
+
Software Architects: Yaron Ukrainitz and Yannai A. Gonczarowski
+
+
+
+
+
+
+
+
diff --git a/original/tools/bin/help/cpuUsage.html b/original/tools/bin/help/cpuUsage.html
new file mode 100644
index 0000000..7e69482
--- /dev/null
+++ b/original/tools/bin/help/cpuUsage.html
@@ -0,0 +1,115 @@
+
+
+
+
+
+
+
+
+Usage instruction and tips can be found in:
+
+
+
+
+
+
+
+
Software Architects: Yaron Ukrainitz and Yannai A.
+Gonczarowski
+
+
+
+
+
+
+
+
diff --git a/original/tools/bin/help/vmUsage.html b/original/tools/bin/help/vmUsage.html
new file mode 100644
index 0000000..611662b
--- /dev/null
+++ b/original/tools/bin/help/vmUsage.html
@@ -0,0 +1,115 @@
+
+
+
+
+
+
+
+
+Usage instruction and tips can be found in:
+
+
+
+
+
+
+
+
+
+
Usage instruction and tips can be found in:
+
+
+
+
The VM Emulator Tutorial
+
+
+
+
Available in www.nand2tetris.org
+
+
+
+
And in relevant book chapters from
+
+
The Elements of Computing Systems,
+
+
by Noam Nisan and Shimon Schocken
+
+
MIT Press
+
+
+
+
+
+
+
+
diff --git a/original/tools/bin/images/arrow2.gif b/original/tools/bin/images/arrow2.gif
new file mode 100644
index 0000000..c744eab
Binary files /dev/null and b/original/tools/bin/images/arrow2.gif differ
diff --git a/original/tools/bin/images/calculator2.gif b/original/tools/bin/images/calculator2.gif
new file mode 100644
index 0000000..834cb05
Binary files /dev/null and b/original/tools/bin/images/calculator2.gif differ
diff --git a/original/tools/bin/images/cancel.gif b/original/tools/bin/images/cancel.gif
new file mode 100644
index 0000000..a8509fa
Binary files /dev/null and b/original/tools/bin/images/cancel.gif differ
diff --git a/original/tools/bin/images/chip.gif b/original/tools/bin/images/chip.gif
new file mode 100644
index 0000000..fbfbb02
Binary files /dev/null and b/original/tools/bin/images/chip.gif differ
diff --git a/original/tools/bin/images/clock2.gif b/original/tools/bin/images/clock2.gif
new file mode 100644
index 0000000..addcf78
Binary files /dev/null and b/original/tools/bin/images/clock2.gif differ
diff --git a/original/tools/bin/images/equal.gif b/original/tools/bin/images/equal.gif
new file mode 100644
index 0000000..3402556
Binary files /dev/null and b/original/tools/bin/images/equal.gif differ
diff --git a/original/tools/bin/images/find.gif b/original/tools/bin/images/find.gif
new file mode 100644
index 0000000..e3f4c9d
Binary files /dev/null and b/original/tools/bin/images/find.gif differ
diff --git a/original/tools/bin/images/hex.gif b/original/tools/bin/images/hex.gif
new file mode 100644
index 0000000..68a851b
Binary files /dev/null and b/original/tools/bin/images/hex.gif differ
diff --git a/original/tools/bin/images/keyboard.gif b/original/tools/bin/images/keyboard.gif
new file mode 100644
index 0000000..823aaf8
Binary files /dev/null and b/original/tools/bin/images/keyboard.gif differ
diff --git a/original/tools/bin/images/ok.gif b/original/tools/bin/images/ok.gif
new file mode 100644
index 0000000..fe6ed8d
Binary files /dev/null and b/original/tools/bin/images/ok.gif differ
diff --git a/original/tools/bin/images/ok2.gif b/original/tools/bin/images/ok2.gif
new file mode 100644
index 0000000..083909b
Binary files /dev/null and b/original/tools/bin/images/ok2.gif differ
diff --git a/original/tools/bin/images/open.gif b/original/tools/bin/images/open.gif
new file mode 100644
index 0000000..f69a024
Binary files /dev/null and b/original/tools/bin/images/open.gif differ
diff --git a/original/tools/bin/images/open2.gif b/original/tools/bin/images/open2.gif
new file mode 100644
index 0000000..2b94682
Binary files /dev/null and b/original/tools/bin/images/open2.gif differ
diff --git a/original/tools/bin/images/opendoc.gif b/original/tools/bin/images/opendoc.gif
new file mode 100644
index 0000000..e84f0d6
Binary files /dev/null and b/original/tools/bin/images/opendoc.gif differ
diff --git a/original/tools/bin/images/redflag.gif b/original/tools/bin/images/redflag.gif
new file mode 100644
index 0000000..1b1a6b1
Binary files /dev/null and b/original/tools/bin/images/redflag.gif differ
diff --git a/original/tools/bin/images/save.gif b/original/tools/bin/images/save.gif
new file mode 100644
index 0000000..7b5d5b9
Binary files /dev/null and b/original/tools/bin/images/save.gif differ
diff --git a/original/tools/bin/images/scroll.gif b/original/tools/bin/images/scroll.gif
new file mode 100644
index 0000000..e00a9a1
Binary files /dev/null and b/original/tools/bin/images/scroll.gif differ
diff --git a/original/tools/bin/images/smallcancel.gif b/original/tools/bin/images/smallcancel.gif
new file mode 100644
index 0000000..1f8cddc
Binary files /dev/null and b/original/tools/bin/images/smallcancel.gif differ
diff --git a/original/tools/bin/images/smallequal.gif b/original/tools/bin/images/smallequal.gif
new file mode 100644
index 0000000..a1db606
Binary files /dev/null and b/original/tools/bin/images/smallequal.gif differ
diff --git a/original/tools/bin/images/smallminus.gif b/original/tools/bin/images/smallminus.gif
new file mode 100644
index 0000000..06492f5
Binary files /dev/null and b/original/tools/bin/images/smallminus.gif differ
diff --git a/original/tools/bin/images/smallnew.gif b/original/tools/bin/images/smallnew.gif
new file mode 100644
index 0000000..c3137e5
Binary files /dev/null and b/original/tools/bin/images/smallnew.gif differ
diff --git a/original/tools/bin/images/smallok.gif b/original/tools/bin/images/smallok.gif
new file mode 100644
index 0000000..9bef2b2
Binary files /dev/null and b/original/tools/bin/images/smallok.gif differ
diff --git a/original/tools/bin/images/smallplus.gif b/original/tools/bin/images/smallplus.gif
new file mode 100644
index 0000000..9030b0b
Binary files /dev/null and b/original/tools/bin/images/smallplus.gif differ
diff --git a/original/tools/bin/images/vcrfastforward.gif b/original/tools/bin/images/vcrfastforward.gif
new file mode 100644
index 0000000..11c7235
Binary files /dev/null and b/original/tools/bin/images/vcrfastforward.gif differ
diff --git a/original/tools/bin/images/vcrforward.gif b/original/tools/bin/images/vcrforward.gif
new file mode 100644
index 0000000..b58d649
Binary files /dev/null and b/original/tools/bin/images/vcrforward.gif differ
diff --git a/original/tools/bin/images/vcrrewind.gif b/original/tools/bin/images/vcrrewind.gif
new file mode 100644
index 0000000..e55b4d6
Binary files /dev/null and b/original/tools/bin/images/vcrrewind.gif differ
diff --git a/original/tools/bin/images/vcrstop.gif b/original/tools/bin/images/vcrstop.gif
new file mode 100644
index 0000000..abe2082
Binary files /dev/null and b/original/tools/bin/images/vcrstop.gif differ
diff --git a/original/tools/bin/lib/AssemblerGUI.jar b/original/tools/bin/lib/AssemblerGUI.jar
new file mode 100644
index 0000000..c40d455
Binary files /dev/null and b/original/tools/bin/lib/AssemblerGUI.jar differ
diff --git a/original/tools/bin/lib/Compilers.jar b/original/tools/bin/lib/Compilers.jar
new file mode 100644
index 0000000..9a78b05
Binary files /dev/null and b/original/tools/bin/lib/Compilers.jar differ
diff --git a/original/tools/bin/lib/Hack.jar b/original/tools/bin/lib/Hack.jar
new file mode 100644
index 0000000..9d57398
Binary files /dev/null and b/original/tools/bin/lib/Hack.jar differ
diff --git a/original/tools/bin/lib/HackGUI.jar b/original/tools/bin/lib/HackGUI.jar
new file mode 100644
index 0000000..22d4ff3
Binary files /dev/null and b/original/tools/bin/lib/HackGUI.jar differ
diff --git a/original/tools/bin/lib/Simulators.jar b/original/tools/bin/lib/Simulators.jar
new file mode 100644
index 0000000..72b5db7
Binary files /dev/null and b/original/tools/bin/lib/Simulators.jar differ
diff --git a/original/tools/bin/lib/SimulatorsGUI.jar b/original/tools/bin/lib/SimulatorsGUI.jar
new file mode 100644
index 0000000..4d36e64
Binary files /dev/null and b/original/tools/bin/lib/SimulatorsGUI.jar differ
diff --git a/original/tools/bin/lib/TranslatorsGUI.jar b/original/tools/bin/lib/TranslatorsGUI.jar
new file mode 100644
index 0000000..f29f926
Binary files /dev/null and b/original/tools/bin/lib/TranslatorsGUI.jar differ
diff --git a/original/tools/bin/scripts/defaultCPU.txt b/original/tools/bin/scripts/defaultCPU.txt
new file mode 100644
index 0000000..43b2720
--- /dev/null
+++ b/original/tools/bin/scripts/defaultCPU.txt
@@ -0,0 +1,3 @@
+repeat {
+ ticktock;
+}
\ No newline at end of file
diff --git a/original/tools/bin/scripts/defaultHW.txt b/original/tools/bin/scripts/defaultHW.txt
new file mode 100644
index 0000000..bdb2261
--- /dev/null
+++ b/original/tools/bin/scripts/defaultHW.txt
@@ -0,0 +1,4 @@
+repeat {
+ tick,
+ tock;
+}
\ No newline at end of file
diff --git a/original/tools/bin/scripts/defaultVM.txt b/original/tools/bin/scripts/defaultVM.txt
new file mode 100644
index 0000000..dbc64c4
--- /dev/null
+++ b/original/tools/bin/scripts/defaultVM.txt
@@ -0,0 +1,3 @@
+repeat {
+ vmstep;
+}
\ No newline at end of file
diff --git a/original/tools/builtInChips/ALU.class b/original/tools/builtInChips/ALU.class
new file mode 100644
index 0000000..03f95dc
Binary files /dev/null and b/original/tools/builtInChips/ALU.class differ
diff --git a/original/tools/builtInChips/ALU.hdl b/original/tools/builtInChips/ALU.hdl
new file mode 100644
index 0000000..697a31b
--- /dev/null
+++ b/original/tools/builtInChips/ALU.hdl
@@ -0,0 +1,49 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/ALU.hdl
+/**
+ * ALU (Arithmetic Logic Unit):
+ * Computes out = one of the following functions:
+ * 0, 1, -1,
+ * x, y, !x, !y, -x, -y,
+ * x + 1, y + 1, x - 1, y - 1,
+ * x + y, x - y, y - x,
+ * x & y, x | y
+ * on the 16-bit inputs x, y,
+ * according to the input bits zx, nx, zy, ny, f, no.
+ * In addition, computes the output bits:
+ * zr = (out == 0, 1, 0)
+ * ng = (out < 0, 1, 0)
+ */
+// Implementation: Manipulates the x and y inputs
+// and operates on the resulting values, as follows:
+// if (zx == 1) sets x = 0 // 16-bit constant
+// if (nx == 1) sets x = !x // bitwise not
+// if (zy == 1) sets y = 0 // 16-bit constant
+// if (ny == 1) sets y = !y // bitwise not
+// if (f == 1) sets out = x + y // integer 2's complement addition
+// if (f == 0) sets out = x & y // bitwise and
+// if (no == 1) sets out = !out // bitwise not
+
+CHIP ALU {
+
+ IN // 16-bit inputs:
+ x[16], y[16],
+ // Control bits:
+ zx, // Zero the x input
+ nx, // Negate the x input
+ zy, // Zero the y input
+ ny, // Negate the y input
+ f, // Function code: 1 for add, 0 for and
+ no; // Negate the out output
+
+ OUT // 16-bit output
+ out[16],
+
+ // ALU output flags
+ zr, // 1 if out=0, 0 otherwise
+ ng; // 1 if out<0, 0 otherwise
+
+ BUILTIN ALU;
+}
diff --git a/original/tools/builtInChips/ARegister.class b/original/tools/builtInChips/ARegister.class
new file mode 100644
index 0000000..ab9aadc
Binary files /dev/null and b/original/tools/builtInChips/ARegister.class differ
diff --git a/original/tools/builtInChips/ARegister.hdl b/original/tools/builtInChips/ARegister.hdl
new file mode 100644
index 0000000..4812c76
--- /dev/null
+++ b/original/tools/builtInChips/ARegister.hdl
@@ -0,0 +1,22 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/ARegister.hdl
+/**
+ * A 16-bit register named ARegister with the same functionality
+ * of the Register chip:
+ * If load is asserted, the register's value is set to in;
+ * Otherwise, the register maintains its current value.
+ * out(t+1) = (load(t), in(t), out(t))
+ *
+ * This built-in implementation has a visualization side effect.
+ */
+ CHIP ARegister {
+
+ IN in[16], load;
+ OUT out[16];
+
+ BUILTIN ARegister;
+ CLOCKED in, load;
+}
+
diff --git a/original/tools/builtInChips/Add16.class b/original/tools/builtInChips/Add16.class
new file mode 100644
index 0000000..c3754ce
Binary files /dev/null and b/original/tools/builtInChips/Add16.class differ
diff --git a/original/tools/builtInChips/Add16.hdl b/original/tools/builtInChips/Add16.hdl
new file mode 100644
index 0000000..98acd41
--- /dev/null
+++ b/original/tools/builtInChips/Add16.hdl
@@ -0,0 +1,16 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/Add16.hdl
+/**
+ * 16-bit adder: Adds two 16-bit two's complement values.
+ * The most significant carry bit is ignored.
+ */
+ CHIP Add16 {
+
+ IN a[16], b[16];
+ OUT out[16];
+
+ BUILTIN Add16;
+}
+
diff --git a/original/tools/builtInChips/And.class b/original/tools/builtInChips/And.class
new file mode 100644
index 0000000..2c7492b
Binary files /dev/null and b/original/tools/builtInChips/And.class differ
diff --git a/original/tools/builtInChips/And.hdl b/original/tools/builtInChips/And.hdl
new file mode 100644
index 0000000..e41e953
--- /dev/null
+++ b/original/tools/builtInChips/And.hdl
@@ -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: tools/builtInChips/And.hdl
+/**
+ * And gate:
+ * out = (((a == 1) && (b == 1))), 1, 0)
+ */
+CHIP And {
+
+ IN a, b;
+ OUT out;
+
+ BUILTIN And;
+}
diff --git a/original/tools/builtInChips/And16.hdl b/original/tools/builtInChips/And16.hdl
new file mode 100644
index 0000000..11e827c
--- /dev/null
+++ b/original/tools/builtInChips/And16.hdl
@@ -0,0 +1,16 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/And16.hdl
+/**
+ * 16-bit bitwise And gate:
+ * out[i] = And(a[i],b[i]) for i = 0..15
+ */
+CHIP And16 {
+
+ IN a[16], b[16];
+ OUT out[16];
+
+ BUILTIN And;
+}
+
diff --git a/original/tools/builtInChips/Bit.class b/original/tools/builtInChips/Bit.class
new file mode 100644
index 0000000..1e5a3c4
Binary files /dev/null and b/original/tools/builtInChips/Bit.class differ
diff --git a/original/tools/builtInChips/Bit.hdl b/original/tools/builtInChips/Bit.hdl
new file mode 100644
index 0000000..24ce7a1
--- /dev/null
+++ b/original/tools/builtInChips/Bit.hdl
@@ -0,0 +1,18 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/Bit.hdl
+/**
+ * 1-bit register:
+ * If load is asserted, the register's value is set to in;
+ * Otherwise, the register maintains its current value.
+ * out(t+1) = (load(t), in(t), out(t))
+ */
+ CHIP Bit {
+
+ IN in, load;
+ OUT out;
+
+ BUILTIN Bit;
+ CLOCKED in, load;
+}
diff --git a/original/tools/builtInChips/DFF.class b/original/tools/builtInChips/DFF.class
new file mode 100644
index 0000000..49efcf1
Binary files /dev/null and b/original/tools/builtInChips/DFF.class differ
diff --git a/original/tools/builtInChips/DFF.hdl b/original/tools/builtInChips/DFF.hdl
new file mode 100644
index 0000000..9154ea9
--- /dev/null
+++ b/original/tools/builtInChips/DFF.hdl
@@ -0,0 +1,16 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/DFF.hdl
+/**
+ * Data Flip-flop: out(t) = in(t-1)
+ * where t is the current time unit, or clock cycle.
+ */
+CHIP DFF {
+
+ IN in;
+ OUT out;
+
+ BUILTIN DFF;
+ CLOCKED in;
+}
diff --git a/original/tools/builtInChips/DMux.class b/original/tools/builtInChips/DMux.class
new file mode 100644
index 0000000..8cf4e0b
Binary files /dev/null and b/original/tools/builtInChips/DMux.class differ
diff --git a/original/tools/builtInChips/DMux.hdl b/original/tools/builtInChips/DMux.hdl
new file mode 100644
index 0000000..aca4dfc
--- /dev/null
+++ b/original/tools/builtInChips/DMux.hdl
@@ -0,0 +1,16 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/DMux.hdl
+/**
+ * Demultiplexor:
+ * [a, b] = ((sel == 0), [in, 0], [0, in])
+ */
+CHIP DMux {
+
+ IN in, sel;
+ OUT a, b;
+
+ BUILTIN DMux;
+}
+
diff --git a/original/tools/builtInChips/DMux4Way.class b/original/tools/builtInChips/DMux4Way.class
new file mode 100644
index 0000000..ab72a17
Binary files /dev/null and b/original/tools/builtInChips/DMux4Way.class differ
diff --git a/original/tools/builtInChips/DMux4Way.hdl b/original/tools/builtInChips/DMux4Way.hdl
new file mode 100644
index 0000000..304a1e9
--- /dev/null
+++ b/original/tools/builtInChips/DMux4Way.hdl
@@ -0,0 +1,19 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/DMux4Way.hdl
+/**
+ * 4-way demultiplexor:
+ * [a, b, c, d] = [in, 0, 0, 0] if sel == 00
+ * [0, in, 0, 0] if sel == 01
+ * [0, 0, in, 0] if sel == 10
+ * [0, 0, 0, in] if sel == 11
+ */
+ CHIP DMux4Way {
+
+ IN in, sel[2];
+ OUT a, b, c, d;
+
+ BUILTIN DMux4Way;
+}
+
diff --git a/original/tools/builtInChips/DMux8Way.class b/original/tools/builtInChips/DMux8Way.class
new file mode 100644
index 0000000..80e7437
Binary files /dev/null and b/original/tools/builtInChips/DMux8Way.class differ
diff --git a/original/tools/builtInChips/DMux8Way.hdl b/original/tools/builtInChips/DMux8Way.hdl
new file mode 100644
index 0000000..0fa9ee7
--- /dev/null
+++ b/original/tools/builtInChips/DMux8Way.hdl
@@ -0,0 +1,19 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/DMux8Way.hdl
+/**
+ * 8-way demultiplexor:
+ * [a, b, c, d, e, f, g, h] = [in, 0, 0, 0, 0, 0, 0, 0] if sel == 000
+ * [0, in, 0, 0, 0, 0, 0, 0] if sel == 001
+ * ...
+ * [0, 0, 0, 0, 0, 0, 0, in] if sel == 111
+ */
+ CHIP DMux8Way {
+
+ IN in, sel[3];
+ OUT a, b, c, d, e, f, g, h;
+
+ BUILTIN DMux8Way;
+}
+
diff --git a/original/tools/builtInChips/DRegister.class b/original/tools/builtInChips/DRegister.class
new file mode 100644
index 0000000..74a713d
Binary files /dev/null and b/original/tools/builtInChips/DRegister.class differ
diff --git a/original/tools/builtInChips/DRegister.hdl b/original/tools/builtInChips/DRegister.hdl
new file mode 100644
index 0000000..50b33f6
--- /dev/null
+++ b/original/tools/builtInChips/DRegister.hdl
@@ -0,0 +1,22 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/DRegister.hdl
+/**
+ * A 16-bit register named DRegister with the same functionality
+ * of the Register chip:
+ * If load is asserted, the register's value is set to in;
+ * Otherwise, the register maintains its current value.
+ * out(t+1) = (load(t), in(t), out(t))
+ *
+ * This built-in implementation has a visualization side effect.
+ */
+CHIP DRegister {
+
+ IN in[16], load;
+ OUT out[16];
+
+ BUILTIN DRegister;
+ CLOCKED in, load;
+}
+
diff --git a/original/tools/builtInChips/FullAdder.class b/original/tools/builtInChips/FullAdder.class
new file mode 100644
index 0000000..2ed9ead
Binary files /dev/null and b/original/tools/builtInChips/FullAdder.class differ
diff --git a/original/tools/builtInChips/FullAdder.hdl b/original/tools/builtInChips/FullAdder.hdl
new file mode 100644
index 0000000..fe09fbb
--- /dev/null
+++ b/original/tools/builtInChips/FullAdder.hdl
@@ -0,0 +1,16 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/FullAdder.hdl
+/**
+ * Computes the sum of three bits.
+ */
+ CHIP FullAdder {
+
+ IN a, b, c;
+ OUT sum, // LSB of a + b + c
+ carry; // MSB of a + b + c
+
+ BUILTIN FullAdder;
+}
+
diff --git a/original/tools/builtInChips/HalfAdder.class b/original/tools/builtInChips/HalfAdder.class
new file mode 100644
index 0000000..e7741ed
Binary files /dev/null and b/original/tools/builtInChips/HalfAdder.class differ
diff --git a/original/tools/builtInChips/HalfAdder.hdl b/original/tools/builtInChips/HalfAdder.hdl
new file mode 100644
index 0000000..3156752
--- /dev/null
+++ b/original/tools/builtInChips/HalfAdder.hdl
@@ -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: tools/builtInChips/HalfAdder.hdl
+/**
+ * Computes the sum of two bits.
+ */
+ CHIP HalfAdder {
+
+ IN a, b;
+ OUT sum, // LSB of a + b
+ carry; // MSB of a + b
+
+ BUILTIN HalfAdder;
+}
diff --git a/original/tools/builtInChips/Inc16.class b/original/tools/builtInChips/Inc16.class
new file mode 100644
index 0000000..b5b2aeb
Binary files /dev/null and b/original/tools/builtInChips/Inc16.class differ
diff --git a/original/tools/builtInChips/Inc16.hdl b/original/tools/builtInChips/Inc16.hdl
new file mode 100644
index 0000000..06430ed
--- /dev/null
+++ b/original/tools/builtInChips/Inc16.hdl
@@ -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: tools/builtInChips/Inc16.hdl
+/**
+ * 16-bit incrementer:
+ * out = in + 1
+ */
+ CHIP Inc16 {
+
+ IN in[16];
+ OUT out[16];
+
+ BUILTIN Inc16;
+}
diff --git a/original/tools/builtInChips/Keyboard.class b/original/tools/builtInChips/Keyboard.class
new file mode 100644
index 0000000..090b7cc
Binary files /dev/null and b/original/tools/builtInChips/Keyboard.class differ
diff --git a/original/tools/builtInChips/Keyboard.hdl b/original/tools/builtInChips/Keyboard.hdl
new file mode 100644
index 0000000..2fd9829
--- /dev/null
+++ b/original/tools/builtInChips/Keyboard.hdl
@@ -0,0 +1,17 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/Keyboard.hdl
+/**
+ * The keyboard (memory map).
+ * Outputs the character code of the currently pressed key,
+ * or 0 if no key is pressed.
+ *
+ * This built-in implementation has a visualization side effect.
+ */
+CHIP Keyboard {
+
+ OUT out[16];
+
+ BUILTIN Keyboard;
+}
diff --git a/original/tools/builtInChips/Mux.class b/original/tools/builtInChips/Mux.class
new file mode 100644
index 0000000..75c6645
Binary files /dev/null and b/original/tools/builtInChips/Mux.class differ
diff --git a/original/tools/builtInChips/Mux.hdl b/original/tools/builtInChips/Mux.hdl
new file mode 100644
index 0000000..fc727f0
--- /dev/null
+++ b/original/tools/builtInChips/Mux.hdl
@@ -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: tools/builtInChips/Mux.hdl
+/**
+ * Multiplexor:
+ * out = ((sel == 0), a, b)
+ */
+ CHIP Mux {
+
+ IN a, b, sel;
+ OUT out;
+
+ BUILTIN Mux;
+}
diff --git a/original/tools/builtInChips/Mux16.hdl b/original/tools/builtInChips/Mux16.hdl
new file mode 100644
index 0000000..9fa929f
--- /dev/null
+++ b/original/tools/builtInChips/Mux16.hdl
@@ -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: tools/builtInChips/Mux16.hdl
+/**
+ * 16-bit multiplexor:
+ * out[i] = ((sel == 0), a[i], b[i]) for i = 0..15
+ */
+ CHIP Mux16 {
+
+ IN a[16], b[16], sel;
+ OUT out[16];
+
+ BUILTIN Mux;
+}
diff --git a/original/tools/builtInChips/Mux4Way16.class b/original/tools/builtInChips/Mux4Way16.class
new file mode 100644
index 0000000..b2e2ed7
Binary files /dev/null and b/original/tools/builtInChips/Mux4Way16.class differ
diff --git a/original/tools/builtInChips/Mux4Way16.hdl b/original/tools/builtInChips/Mux4Way16.hdl
new file mode 100644
index 0000000..841f502
--- /dev/null
+++ b/original/tools/builtInChips/Mux4Way16.hdl
@@ -0,0 +1,18 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/Mux4Way16.hdl
+/**
+ * 4-way 16-bit multiplexor:
+ * out = a if sel == 00
+ * b if sel == 01
+ * c if sel == 10
+ * d if sel == 11
+ */
+CHIP Mux4Way16 {
+
+ IN a[16], b[16], c[16], d[16], sel[2];
+ OUT out[16];
+
+ BUILTIN Mux4Way16;
+}
diff --git a/original/tools/builtInChips/Mux8Way16.class b/original/tools/builtInChips/Mux8Way16.class
new file mode 100644
index 0000000..d8040ef
Binary files /dev/null and b/original/tools/builtInChips/Mux8Way16.class differ
diff --git a/original/tools/builtInChips/Mux8Way16.hdl b/original/tools/builtInChips/Mux8Way16.hdl
new file mode 100644
index 0000000..3ee4ad1
--- /dev/null
+++ b/original/tools/builtInChips/Mux8Way16.hdl
@@ -0,0 +1,21 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/Mux8Way16.hdl
+/**
+ * 8-way 16-bit multiplexor:
+ * out = a if sel == 000
+ * b if sel == 001
+ * ...
+ * h if sel == 111
+ */
+ CHIP Mux8Way16 {
+
+ IN a[16], b[16], c[16], d[16],
+ e[16], f[16], g[16], h[16],
+ sel[3];
+
+ OUT out[16];
+
+ BUILTIN Mux8Way16;
+}
\ No newline at end of file
diff --git a/original/tools/builtInChips/Nand.class b/original/tools/builtInChips/Nand.class
new file mode 100644
index 0000000..4b429ba
Binary files /dev/null and b/original/tools/builtInChips/Nand.class differ
diff --git a/original/tools/builtInChips/Nand.hdl b/original/tools/builtInChips/Nand.hdl
new file mode 100644
index 0000000..379b4c1
--- /dev/null
+++ b/original/tools/builtInChips/Nand.hdl
@@ -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: tools/builtInChips/Nand.hdl
+/**
+ * Nand gate:
+ * out = (((a == 1) && (b == 1))), 0, 1)
+ */
+CHIP Nand {
+
+ IN a, b;
+ OUT out;
+
+ BUILTIN Nand;
+}
diff --git a/original/tools/builtInChips/Not.class b/original/tools/builtInChips/Not.class
new file mode 100644
index 0000000..4726b67
Binary files /dev/null and b/original/tools/builtInChips/Not.class differ
diff --git a/original/tools/builtInChips/Not.hdl b/original/tools/builtInChips/Not.hdl
new file mode 100644
index 0000000..eec024c
--- /dev/null
+++ b/original/tools/builtInChips/Not.hdl
@@ -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: tools/builtInChips/Not.hdl
+ /**
+ * Not gate:
+ * out = ((in == 0), 1, 0)
+ */
+ CHIP Not {
+
+ IN in;
+ OUT out;
+
+ BUILTIN Not;
+}
\ No newline at end of file
diff --git a/original/tools/builtInChips/Not16.class b/original/tools/builtInChips/Not16.class
new file mode 100644
index 0000000..ff3e68f
Binary files /dev/null and b/original/tools/builtInChips/Not16.class differ
diff --git a/original/tools/builtInChips/Not16.hdl b/original/tools/builtInChips/Not16.hdl
new file mode 100644
index 0000000..ae45f0c
--- /dev/null
+++ b/original/tools/builtInChips/Not16.hdl
@@ -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: tools/builtInChips/Not16.hdl
+/**
+ * 16-bit Not gate:
+ * out[i] = ((in[i] == 0), 1, 0) for i = 0..15
+ */
+ CHIP Not16 {
+
+ IN in[16];
+ OUT out[16];
+
+ BUILTIN Not16;
+}
\ No newline at end of file
diff --git a/original/tools/builtInChips/Or.class b/original/tools/builtInChips/Or.class
new file mode 100644
index 0000000..a5b64f9
Binary files /dev/null and b/original/tools/builtInChips/Or.class differ
diff --git a/original/tools/builtInChips/Or.hdl b/original/tools/builtInChips/Or.hdl
new file mode 100644
index 0000000..5d02058
--- /dev/null
+++ b/original/tools/builtInChips/Or.hdl
@@ -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: tools/builtInChips/Or.hdl
+/**
+ * Or gate:
+ * out = (((a == 1) || (b == 1))), 1, 0)
+ */
+ CHIP Or {
+
+ IN a, b;
+ OUT out;
+
+ BUILTIN Or;
+}
diff --git a/original/tools/builtInChips/Or16.hdl b/original/tools/builtInChips/Or16.hdl
new file mode 100644
index 0000000..1a0258c
--- /dev/null
+++ b/original/tools/builtInChips/Or16.hdl
@@ -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: tools/builtInChips/Or16.hdl
+/**
+ * 16-bit bitwise Or gate:
+ * out[i] = (a[i] Or b[i]) for i = 0..15
+ */
+ CHIP Or16 {
+
+ IN a[16], b[16];
+ OUT out[16];
+
+ BUILTIN Or;
+}
diff --git a/original/tools/builtInChips/Or8Way.class b/original/tools/builtInChips/Or8Way.class
new file mode 100644
index 0000000..104804b
Binary files /dev/null and b/original/tools/builtInChips/Or8Way.class differ
diff --git a/original/tools/builtInChips/Or8Way.hdl b/original/tools/builtInChips/Or8Way.hdl
new file mode 100644
index 0000000..ae541fa
--- /dev/null
+++ b/original/tools/builtInChips/Or8Way.hdl
@@ -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: tools/builtInChips/Or8Way.hdl
+/**
+ * 8-way Or gate:
+ * out = in[0] Or in[1] Or ... Or in[7]
+ */
+ CHIP Or8Way {
+
+ IN in[8];
+ OUT out;
+
+ BUILTIN Or8Way;
+}
diff --git a/original/tools/builtInChips/PC.class b/original/tools/builtInChips/PC.class
new file mode 100644
index 0000000..1e6ada1
Binary files /dev/null and b/original/tools/builtInChips/PC.class differ
diff --git a/original/tools/builtInChips/PC.hdl b/original/tools/builtInChips/PC.hdl
new file mode 100644
index 0000000..4f2f1b9
--- /dev/null
+++ b/original/tools/builtInChips/PC.hdl
@@ -0,0 +1,23 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/PC.hdl
+
+/**
+ * A 16-bit counter with increment, load, and reset modes.
+ * if (inc(t) == 1) out(t+1) = out(t) + 1
+ * else if (load(t) == 1) out(t+1) = in(t)
+ * else if (reset(t) == 1) out(t+1) = 0
+ * else out(t+1) = out(t).
+ *
+ * To select a mode, assert the relevant control bit,
+ * and de-assert the other two bits.
+ */
+CHIP PC {
+
+ IN in[16], load, inc, reset;
+ OUT out[16];
+
+ BUILTIN PC;
+ CLOCKED in, load, inc, reset;
+}
diff --git a/original/tools/builtInChips/RAM.class b/original/tools/builtInChips/RAM.class
new file mode 100644
index 0000000..e17050f
Binary files /dev/null and b/original/tools/builtInChips/RAM.class differ
diff --git a/original/tools/builtInChips/RAM16K.class b/original/tools/builtInChips/RAM16K.class
new file mode 100644
index 0000000..2f1e3fe
Binary files /dev/null and b/original/tools/builtInChips/RAM16K.class differ
diff --git a/original/tools/builtInChips/RAM16K.hdl b/original/tools/builtInChips/RAM16K.hdl
new file mode 100644
index 0000000..a398437
--- /dev/null
+++ b/original/tools/builtInChips/RAM16K.hdl
@@ -0,0 +1,18 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/RAM16K.hdl
+/**
+ * Memory of 16K 16-bit registers.
+ * If load is asserted, the value of the register selected by
+ * address is set to in; Otherwise, the value does not change.
+ * The value of the selected register is emitted by out.
+ */
+ CHIP RAM16K {
+
+ IN in[16], load, address[14];
+ OUT out[16];
+
+ BUILTIN RAM16K;
+ CLOCKED in, load;
+}
diff --git a/original/tools/builtInChips/RAM4K.class b/original/tools/builtInChips/RAM4K.class
new file mode 100644
index 0000000..164ebf8
Binary files /dev/null and b/original/tools/builtInChips/RAM4K.class differ
diff --git a/original/tools/builtInChips/RAM4K.hdl b/original/tools/builtInChips/RAM4K.hdl
new file mode 100644
index 0000000..e1f5b64
--- /dev/null
+++ b/original/tools/builtInChips/RAM4K.hdl
@@ -0,0 +1,18 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/RAM4K.hdl
+/**
+ * Memory of 4K 16-bit registers.
+ * If load is asserted, the value of the register selected by
+ * address is set to in; Otherwise, the value does not change.
+ * The value of the selected register is emitted by out.
+ */
+ CHIP RAM4K {
+
+ IN in[16], load, address[12];
+ OUT out[16];
+
+ BUILTIN RAM4K;
+ CLOCKED in, load;
+}
diff --git a/original/tools/builtInChips/RAM512.class b/original/tools/builtInChips/RAM512.class
new file mode 100644
index 0000000..69bff7a
Binary files /dev/null and b/original/tools/builtInChips/RAM512.class differ
diff --git a/original/tools/builtInChips/RAM512.hdl b/original/tools/builtInChips/RAM512.hdl
new file mode 100644
index 0000000..514b7f5
--- /dev/null
+++ b/original/tools/builtInChips/RAM512.hdl
@@ -0,0 +1,18 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/RAM512.hdl
+/**
+ * Memory of 512 16-bit registers.
+ * If load is asserted, the value of the register selected by
+ * address is set to in; Otherwise, the value does not change.
+ * The value of the selected register is emitted by out.
+ */
+ CHIP RAM512 {
+
+ IN in[16], load, address[9];
+ OUT out[16];
+
+ BUILTIN RAM512;
+ CLOCKED in, load;
+}
diff --git a/original/tools/builtInChips/RAM64.class b/original/tools/builtInChips/RAM64.class
new file mode 100644
index 0000000..a1fe78a
Binary files /dev/null and b/original/tools/builtInChips/RAM64.class differ
diff --git a/original/tools/builtInChips/RAM64.hdl b/original/tools/builtInChips/RAM64.hdl
new file mode 100644
index 0000000..d21f0b0
--- /dev/null
+++ b/original/tools/builtInChips/RAM64.hdl
@@ -0,0 +1,18 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/RAM64.hdl
+/**
+ * Memory of sixty four 16-bit registers.
+ * If load is asserted, the value of the register selected by
+ * address is set to in; Otherwise, the value does not change.
+ * The value of the selected register is emitted by out.
+ */
+ CHIP RAM64 {
+
+ IN in[16], load, address[6];
+ OUT out[16];
+
+ BUILTIN RAM64;
+ CLOCKED in, load;
+}
diff --git a/original/tools/builtInChips/RAM8.class b/original/tools/builtInChips/RAM8.class
new file mode 100644
index 0000000..88f106e
Binary files /dev/null and b/original/tools/builtInChips/RAM8.class differ
diff --git a/original/tools/builtInChips/RAM8.hdl b/original/tools/builtInChips/RAM8.hdl
new file mode 100644
index 0000000..401ff4d
--- /dev/null
+++ b/original/tools/builtInChips/RAM8.hdl
@@ -0,0 +1,18 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/RAM8.hdl
+/**
+ * Memory of eight 16-bit registers.
+ * If load is asserted, the value of the register selected by
+ * address is set to in; Otherwise, the value does not change.
+ * The value of the selected register is emitted by out.
+ */
+ CHIP RAM8 {
+
+ IN in[16], load, address[3];
+ OUT out[16];
+
+ BUILTIN RAM8;
+ CLOCKED in, load;
+}
diff --git a/original/tools/builtInChips/ROM32K.class b/original/tools/builtInChips/ROM32K.class
new file mode 100644
index 0000000..c4320d8
Binary files /dev/null and b/original/tools/builtInChips/ROM32K.class differ
diff --git a/original/tools/builtInChips/ROM32K.hdl b/original/tools/builtInChips/ROM32K.hdl
new file mode 100644
index 0000000..97f6a8e
--- /dev/null
+++ b/original/tools/builtInChips/ROM32K.hdl
@@ -0,0 +1,25 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/ROM32K.hdl
+/**
+ * Read-Only memory (ROM) of 32K registers, each 16-bit wide.
+ * Facilitates data read, as follows:
+ * out(t) = ROM32K[address(t)](t)
+ * In words: the chip outputs the value stored at the
+ * memory location specified by address.
+ *
+ * Can be used to serve as the instruction memory of the Hack computer.
+ * To that end, the built-in chip implementation supports the handling
+ * of the "ROM32K load Xxx" script command, where Xxx is the name of a
+ * text file containing a program written in the Hack machine language.
+ * When the simulator encounters such a command in a test script,
+ * the code found in the file is loaded into the simulated ROM32K chip.
+ */
+ CHIP ROM32K {
+
+ IN address[15];
+ OUT out[16];
+
+ BUILTIN ROM32K;
+}
diff --git a/original/tools/builtInChips/Register.class b/original/tools/builtInChips/Register.class
new file mode 100644
index 0000000..3958fcd
Binary files /dev/null and b/original/tools/builtInChips/Register.class differ
diff --git a/original/tools/builtInChips/Register.hdl b/original/tools/builtInChips/Register.hdl
new file mode 100644
index 0000000..390e92a
--- /dev/null
+++ b/original/tools/builtInChips/Register.hdl
@@ -0,0 +1,18 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/Register.hdl
+/**
+ * 16-bit register:
+ * If load is asserted, the register's value is set to in;
+ * Otherwise, the register maintains its current value.
+ * out(t+1) = (load(t), in(t), out(t))
+ */
+ CHIP Register {
+
+ IN in[16], load;
+ OUT out[16];
+
+ BUILTIN Register;
+ CLOCKED in, load;
+}
diff --git a/original/tools/builtInChips/RegisterWithGUI.class b/original/tools/builtInChips/RegisterWithGUI.class
new file mode 100644
index 0000000..c80208c
Binary files /dev/null and b/original/tools/builtInChips/RegisterWithGUI.class differ
diff --git a/original/tools/builtInChips/Screen.class b/original/tools/builtInChips/Screen.class
new file mode 100644
index 0000000..100ed03
Binary files /dev/null and b/original/tools/builtInChips/Screen.class differ
diff --git a/original/tools/builtInChips/Screen.hdl b/original/tools/builtInChips/Screen.hdl
new file mode 100644
index 0000000..fc91f07
--- /dev/null
+++ b/original/tools/builtInChips/Screen.hdl
@@ -0,0 +1,33 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: tools/builtInChips/Screen.hdl
+/**
+ * The Screen (memory map).
+ * Same functionality as a 16-bit 8K RAM:
+ * If load is asserted, the value of the register selected by
+ * address is set to in; Otherwise, the value does not change.
+ * The value of the selected register is emitted by out.
+ *
+ * This built-in implementation has the side effect of continuously
+ * refreshing a visual 256 by 512 black-and-white screen, simulated
+ * by the simulator. Each row in the visual screen is represented
+ * by 32 consecutive 16-bit words, starting at the top left corner
+ * of the visual screen. Thus the pixel at row r from the top and
+ * column c from the left (0<=r<256, 0<=c<512) reflects the c%16
+ * bit (counting from LSB to MSB) of the word found in Screen[r*32+c/16].
+ */
+CHIP Screen {
+
+ IN in[16], // what to write
+ load, // write-enable bit
+ address[13]; // where to read/write
+ OUT out[16]; // Screen value at the given address
+
+ BUILTIN Screen;
+ CLOCKED in, load;
+}
+
+
+
+
\ No newline at end of file
diff --git a/original/tools/builtInChips/Xor.class b/original/tools/builtInChips/Xor.class
new file mode 100644
index 0000000..d99ad18
Binary files /dev/null and b/original/tools/builtInChips/Xor.class differ
diff --git a/original/tools/builtInChips/Xor.hdl b/original/tools/builtInChips/Xor.hdl
new file mode 100644
index 0000000..d43a622
--- /dev/null
+++ b/original/tools/builtInChips/Xor.hdl
@@ -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: tools/builtInChips/Xor.hdl
+/**
+ * Exclusive-or gate:
+ * out = (((a == 0) & (b = 1)) | ((a == 1) & (b = 0)), 1, 0)
+ */
+ CHIP Xor {
+
+ IN a, b;
+ OUT out;
+
+ BUILTIN Xor;
+}
diff --git a/original/tools/builtInVMCode/Array.class b/original/tools/builtInVMCode/Array.class
new file mode 100644
index 0000000..c76b652
Binary files /dev/null and b/original/tools/builtInVMCode/Array.class differ
diff --git a/original/tools/builtInVMCode/JackOSClass.class b/original/tools/builtInVMCode/JackOSClass.class
new file mode 100644
index 0000000..25df72a
Binary files /dev/null and b/original/tools/builtInVMCode/JackOSClass.class differ
diff --git a/original/tools/builtInVMCode/Keyboard.class b/original/tools/builtInVMCode/Keyboard.class
new file mode 100644
index 0000000..7366f75
Binary files /dev/null and b/original/tools/builtInVMCode/Keyboard.class differ
diff --git a/original/tools/builtInVMCode/Math.class b/original/tools/builtInVMCode/Math.class
new file mode 100644
index 0000000..71aef91
Binary files /dev/null and b/original/tools/builtInVMCode/Math.class differ
diff --git a/original/tools/builtInVMCode/Memory.class b/original/tools/builtInVMCode/Memory.class
new file mode 100644
index 0000000..e9bb7ad
Binary files /dev/null and b/original/tools/builtInVMCode/Memory.class differ
diff --git a/original/tools/builtInVMCode/Output.class b/original/tools/builtInVMCode/Output.class
new file mode 100644
index 0000000..65b25b7
Binary files /dev/null and b/original/tools/builtInVMCode/Output.class differ
diff --git a/original/tools/builtInVMCode/Screen.class b/original/tools/builtInVMCode/Screen.class
new file mode 100644
index 0000000..8644e09
Binary files /dev/null and b/original/tools/builtInVMCode/Screen.class differ
diff --git a/original/tools/builtInVMCode/String.class b/original/tools/builtInVMCode/String.class
new file mode 100644
index 0000000..98c7f58
Binary files /dev/null and b/original/tools/builtInVMCode/String.class differ
diff --git a/original/tools/builtInVMCode/Sys.class b/original/tools/builtInVMCode/Sys.class
new file mode 100644
index 0000000..0c15f1b
Binary files /dev/null and b/original/tools/builtInVMCode/Sys.class differ
diff --git a/projects/01/.DS_Store b/projects/01/.DS_Store
deleted file mode 100644
index 3c87038..0000000
Binary files a/projects/01/.DS_Store and /dev/null differ
diff --git a/projects/01/abgabe/Not.hdl b/projects/01/abgabe/Not.hdl
new file mode 100644
index 0000000..14fb886
--- /dev/null
+++ b/projects/01/abgabe/Not.hdl
@@ -0,0 +1,18 @@
+// 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/01/Not.hdl
+
+/**
+ * Not gate:
+ * out = not in
+ */
+
+CHIP Not {
+ IN in;
+ OUT out;
+
+ PARTS:
+ Nand(a=in,b=in,out=out);
+ // Put your code here:
+}
diff --git a/projects/01/project/And.cmp b/projects/01/project/And.cmp
new file mode 100644
index 0000000..7a3c7de
--- /dev/null
+++ b/projects/01/project/And.cmp
@@ -0,0 +1,5 @@
+| a | b |out|
+| 0 | 0 | 0 |
+| 0 | 1 | 0 |
+| 1 | 0 | 0 |
+| 1 | 1 | 1 |
diff --git a/projects/01/project/And.hdl b/projects/01/project/And.hdl
new file mode 100644
index 0000000..658ff73
--- /dev/null
+++ b/projects/01/project/And.hdl
@@ -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/1/And.hdl
+/**
+ * And gate:
+ * if (a and b) out = 1, else out = 0
+ */
+CHIP And {
+ IN a, b;
+ OUT out;
+
+ PARTS:
+ //// Replace this comment with your code.
+}
\ No newline at end of file
diff --git a/projects/01/project/And.tst b/projects/01/project/And.tst
new file mode 100644
index 0000000..92d93ad
--- /dev/null
+++ b/projects/01/project/And.tst
@@ -0,0 +1,29 @@
+// 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/1/And.tst
+
+load And.hdl,
+output-file And.out,
+compare-to And.cmp,
+output-list a b out;
+
+set a 0,
+set b 0,
+eval,
+output;
+
+set a 0,
+set b 1,
+eval,
+output;
+
+set a 1,
+set b 0,
+eval,
+output;
+
+set a 1,
+set b 1,
+eval,
+output;
diff --git a/projects/01/project/And16.cmp b/projects/01/project/And16.cmp
new file mode 100644
index 0000000..fb8dbfc
--- /dev/null
+++ b/projects/01/project/And16.cmp
@@ -0,0 +1,7 @@
+| a | b | out |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 |
+| 0000000000000000 | 1111111111111111 | 0000000000000000 |
+| 1111111111111111 | 1111111111111111 | 1111111111111111 |
+| 1010101010101010 | 0101010101010101 | 0000000000000000 |
+| 0011110011000011 | 0000111111110000 | 0000110011000000 |
+| 0001001000110100 | 1001100001110110 | 0001000000110100 |
diff --git a/projects/01/project/And16.hdl b/projects/01/project/And16.hdl
new file mode 100644
index 0000000..dfd56bc
--- /dev/null
+++ b/projects/01/project/And16.hdl
@@ -0,0 +1,16 @@
+// 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/1/And16.hdl
+/**
+ * 16-bit And gate:
+ * for i = 0, ..., 15:
+ * out[i] = a[i] And b[i]
+ */
+CHIP And16 {
+ IN a[16], b[16];
+ OUT out[16];
+
+ PARTS:
+ //// Replace this comment with your code.
+}
\ No newline at end of file
diff --git a/projects/01/project/And16.tst b/projects/01/project/And16.tst
new file mode 100644
index 0000000..52a7884
--- /dev/null
+++ b/projects/01/project/And16.tst
@@ -0,0 +1,39 @@
+// 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/1/And16.tst
+
+load And16.hdl,
+output-file And16.out,
+compare-to And16.cmp,
+output-list a%B1.16.1 b%B1.16.1 out%B1.16.1;
+
+set a %B0000000000000000,
+set b %B0000000000000000,
+eval,
+output;
+
+set a %B0000000000000000,
+set b %B1111111111111111,
+eval,
+output;
+
+set a %B1111111111111111,
+set b %B1111111111111111,
+eval,
+output;
+
+set a %B1010101010101010,
+set b %B0101010101010101,
+eval,
+output;
+
+set a %B0011110011000011,
+set b %B0000111111110000,
+eval,
+output;
+
+set a %B0001001000110100,
+set b %B1001100001110110,
+eval,
+output;
\ No newline at end of file
diff --git a/projects/01/project/DMux.cmp b/projects/01/project/DMux.cmp
new file mode 100644
index 0000000..5b65adb
--- /dev/null
+++ b/projects/01/project/DMux.cmp
@@ -0,0 +1,5 @@
+|in |sel| a | b |
+| 0 | 0 | 0 | 0 |
+| 0 | 1 | 0 | 0 |
+| 1 | 0 | 1 | 0 |
+| 1 | 1 | 0 | 1 |
diff --git a/projects/01/project/DMux.hdl b/projects/01/project/DMux.hdl
new file mode 100644
index 0000000..9dbdfb9
--- /dev/null
+++ b/projects/01/project/DMux.hdl
@@ -0,0 +1,16 @@
+// 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/1/DMux.hdl
+/**
+ * Demultiplexor:
+ * [a, b] = [in, 0] if sel = 0
+ * [0, in] if sel = 1
+ */
+CHIP DMux {
+ IN in, sel;
+ OUT a, b;
+
+ PARTS:
+ //// Replace this comment with your code.
+}
diff --git a/projects/01/project/DMux.tst b/projects/01/project/DMux.tst
new file mode 100644
index 0000000..cebda16
--- /dev/null
+++ b/projects/01/project/DMux.tst
@@ -0,0 +1,27 @@
+// 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/1/DMux.tst
+
+load DMux.hdl,
+output-file DMux.out,
+compare-to DMux.cmp,
+output-list in sel a b;
+
+set in 0,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set in 1,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
diff --git a/projects/01/project/DMux4Way.cmp b/projects/01/project/DMux4Way.cmp
new file mode 100644
index 0000000..7734e2a
--- /dev/null
+++ b/projects/01/project/DMux4Way.cmp
@@ -0,0 +1,9 @@
+|in | sel | a | b | c | d |
+| 0 | 00 | 0 | 0 | 0 | 0 |
+| 0 | 01 | 0 | 0 | 0 | 0 |
+| 0 | 10 | 0 | 0 | 0 | 0 |
+| 0 | 11 | 0 | 0 | 0 | 0 |
+| 1 | 00 | 1 | 0 | 0 | 0 |
+| 1 | 01 | 0 | 1 | 0 | 0 |
+| 1 | 10 | 0 | 0 | 1 | 0 |
+| 1 | 11 | 0 | 0 | 0 | 1 |
diff --git a/projects/01/project/DMux4Way.hdl b/projects/01/project/DMux4Way.hdl
new file mode 100644
index 0000000..399729e
--- /dev/null
+++ b/projects/01/project/DMux4Way.hdl
@@ -0,0 +1,18 @@
+// 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/1/DMux4Way.hdl
+/**
+ * 4-way demultiplexor:
+ * [a, b, c, d] = [in, 0, 0, 0] if sel = 00
+ * [0, in, 0, 0] if sel = 01
+ * [0, 0, in, 0] if sel = 10
+ * [0, 0, 0, in] if sel = 11
+ */
+CHIP DMux4Way {
+ IN in, sel[2];
+ OUT a, b, c, d;
+
+ PARTS:
+ //// Replace this comment with your code.
+}
\ No newline at end of file
diff --git a/projects/01/project/DMux4Way.tst b/projects/01/project/DMux4Way.tst
new file mode 100644
index 0000000..4f5b6a4
--- /dev/null
+++ b/projects/01/project/DMux4Way.tst
@@ -0,0 +1,43 @@
+// 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/1/DMux4Way.tst
+
+load DMux4Way.hdl,
+output-file DMux4Way.out,
+compare-to DMux4Way.cmp,
+output-list in sel%B2.2.2 a b c d;
+
+set in 0,
+set sel %B00,
+eval,
+output;
+
+set sel %B01,
+eval,
+output;
+
+set sel %B10,
+eval,
+output;
+
+set sel %B11,
+eval,
+output;
+
+set in 1,
+set sel %B00,
+eval,
+output;
+
+set sel %B01,
+eval,
+output;
+
+set sel %B10,
+eval,
+output;
+
+set sel %B11,
+eval,
+output;
diff --git a/projects/01/project/DMux8Way.cmp b/projects/01/project/DMux8Way.cmp
new file mode 100644
index 0000000..e1b2e74
--- /dev/null
+++ b/projects/01/project/DMux8Way.cmp
@@ -0,0 +1,17 @@
+|in | sel | a | b | c | d | e | f | g | h |
+| 0 | 000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+| 0 | 001 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+| 0 | 010 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+| 0 | 011 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+| 0 | 100 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+| 0 | 101 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+| 0 | 110 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+| 0 | 111 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+| 1 | 000 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+| 1 | 001 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
+| 1 | 010 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
+| 1 | 011 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
+| 1 | 100 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
+| 1 | 101 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
+| 1 | 110 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
+| 1 | 111 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
diff --git a/projects/01/project/DMux8Way.hdl b/projects/01/project/DMux8Way.hdl
new file mode 100644
index 0000000..e3d3dca
--- /dev/null
+++ b/projects/01/project/DMux8Way.hdl
@@ -0,0 +1,22 @@
+// 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/1/DMux8Way.hdl
+/**
+ * 8-way demultiplexor:
+ * [a, b, c, d, e, f, g, h] = [in, 0, 0, 0, 0, 0, 0, 0] if sel = 000
+ * [0, in, 0, 0, 0, 0, 0, 0] if sel = 001
+ * [0, 0, in, 0, 0, 0, 0, 0] if sel = 010
+ * [0, 0, 0, in, 0, 0, 0, 0] if sel = 011
+ * [0, 0, 0, 0, in, 0, 0, 0] if sel = 100
+ * [0, 0, 0, 0, 0, in, 0, 0] if sel = 101
+ * [0, 0, 0, 0, 0, 0, in, 0] if sel = 110
+ * [0, 0, 0, 0, 0, 0, 0, in] if sel = 111
+ */
+CHIP DMux8Way {
+ IN in, sel[3];
+ OUT a, b, c, d, e, f, g, h;
+
+ PARTS:
+ //// Replace this comment with your code.
+}
diff --git a/projects/01/project/DMux8Way.tst b/projects/01/project/DMux8Way.tst
new file mode 100644
index 0000000..ec1fc9b
--- /dev/null
+++ b/projects/01/project/DMux8Way.tst
@@ -0,0 +1,75 @@
+// 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/1/DMux8Way.tst
+
+load DMux8Way.hdl,
+output-file DMux8Way.out,
+compare-to DMux8Way.cmp,
+output-list in sel%B2.3.2 a b c d e f g h;
+
+set in 0,
+set sel %B000,
+eval,
+output;
+
+set sel %B001,
+eval,
+output;
+
+set sel %B010,
+eval,
+output;
+
+set sel %B011,
+eval,
+output;
+
+set sel %B100,
+eval,
+output;
+
+set sel %B101,
+eval,
+output;
+
+set sel %B110,
+eval,
+output;
+
+set sel %B111,
+eval,
+output;
+
+set in 1,
+set sel %B000,
+eval,
+output;
+
+set sel %B001,
+eval,
+output;
+
+set sel %B010,
+eval,
+output;
+
+set sel %B011,
+eval,
+output;
+
+set sel %B100,
+eval,
+output;
+
+set sel %B101,
+eval,
+output;
+
+set sel %B110,
+eval,
+output;
+
+set sel %B111,
+eval,
+output;
diff --git a/projects/01/project/Mux.cmp b/projects/01/project/Mux.cmp
new file mode 100644
index 0000000..eb25f2e
--- /dev/null
+++ b/projects/01/project/Mux.cmp
@@ -0,0 +1,9 @@
+| a | b |sel|out|
+| 0 | 0 | 0 | 0 |
+| 0 | 0 | 1 | 0 |
+| 0 | 1 | 0 | 0 |
+| 0 | 1 | 1 | 1 |
+| 1 | 0 | 0 | 1 |
+| 1 | 0 | 1 | 0 |
+| 1 | 1 | 0 | 1 |
+| 1 | 1 | 1 | 1 |
diff --git a/projects/01/project/Mux.hdl b/projects/01/project/Mux.hdl
new file mode 100644
index 0000000..9f9e720
--- /dev/null
+++ b/projects/01/project/Mux.hdl
@@ -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/1/Mux.hdl
+/**
+ * Multiplexor:
+ * if (sel = 0) out = a, else out = b
+ */
+CHIP Mux {
+ IN a, b, sel;
+ OUT out;
+
+ PARTS:
+ //// Replace this comment with your code.
+}
\ No newline at end of file
diff --git a/projects/01/project/Mux.tst b/projects/01/project/Mux.tst
new file mode 100644
index 0000000..8e5c43e
--- /dev/null
+++ b/projects/01/project/Mux.tst
@@ -0,0 +1,49 @@
+// 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/1/Mux.tst
+
+load Mux.hdl,
+output-file Mux.out,
+compare-to Mux.cmp,
+output-list a b sel out;
+
+set a 0,
+set b 0,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set a 0,
+set b 1,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set a 1,
+set b 0,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set a 1,
+set b 1,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
diff --git a/projects/01/project/Mux16.cmp b/projects/01/project/Mux16.cmp
new file mode 100644
index 0000000..80b6ece
--- /dev/null
+++ b/projects/01/project/Mux16.cmp
@@ -0,0 +1,9 @@
+| a | b |sel| out |
+| 0000000000000000 | 0000000000000000 | 0 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 1 | 0000000000000000 |
+| 0000000000000000 | 0001001000110100 | 0 | 0000000000000000 |
+| 0000000000000000 | 0001001000110100 | 1 | 0001001000110100 |
+| 1001100001110110 | 0000000000000000 | 0 | 1001100001110110 |
+| 1001100001110110 | 0000000000000000 | 1 | 0000000000000000 |
+| 1010101010101010 | 0101010101010101 | 0 | 1010101010101010 |
+| 1010101010101010 | 0101010101010101 | 1 | 0101010101010101 |
diff --git a/projects/01/project/Mux16.hdl b/projects/01/project/Mux16.hdl
new file mode 100644
index 0000000..3d2bccf
--- /dev/null
+++ b/projects/01/project/Mux16.hdl
@@ -0,0 +1,16 @@
+// 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/1/Mux16.hdl
+/**
+ * 16-bit multiplexor:
+ * for i = 0, ..., 15:
+ * if (sel = 0) out[i] = a[i], else out[i] = b[i]
+ */
+CHIP Mux16 {
+ IN a[16], b[16], sel;
+ OUT out[16];
+
+ PARTS:
+ //// Replace this comment with your code.
+}
diff --git a/projects/01/project/Mux16.tst b/projects/01/project/Mux16.tst
new file mode 100644
index 0000000..2a1ae88
--- /dev/null
+++ b/projects/01/project/Mux16.tst
@@ -0,0 +1,49 @@
+// 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/1/Mux16.tst
+
+load Mux16.hdl,
+output-file Mux16.out,
+compare-to Mux16.cmp,
+output-list a%B1.16.1 b%B1.16.1 sel out%B1.16.1;
+
+set a 0,
+set b 0,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set a %B0000000000000000,
+set b %B0001001000110100,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set a %B1001100001110110,
+set b %B0000000000000000,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set a %B1010101010101010,
+set b %B0101010101010101,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
\ No newline at end of file
diff --git a/projects/01/project/Mux4Way16.cmp b/projects/01/project/Mux4Way16.cmp
new file mode 100644
index 0000000..659176d
--- /dev/null
+++ b/projects/01/project/Mux4Way16.cmp
@@ -0,0 +1,9 @@
+| a | b | c | d | sel | out |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 00 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 01 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 10 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 11 | 0000000000000000 |
+| 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 00 | 0001001000110100 |
+| 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 01 | 1001100001110110 |
+| 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 10 | 1010101010101010 |
+| 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 11 | 0101010101010101 |
diff --git a/projects/01/project/Mux4Way16.hdl b/projects/01/project/Mux4Way16.hdl
new file mode 100644
index 0000000..8d6b645
--- /dev/null
+++ b/projects/01/project/Mux4Way16.hdl
@@ -0,0 +1,18 @@
+// 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/1/Mux4Way16.hdl
+/**
+ * 4-way 16-bit multiplexor:
+ * out = a if sel = 00
+ * b if sel = 01
+ * c if sel = 10
+ * d if sel = 11
+ */
+CHIP Mux4Way16 {
+ IN a[16], b[16], c[16], d[16], sel[2];
+ OUT out[16];
+
+ PARTS:
+ //// Replace this comment with your code.
+}
\ No newline at end of file
diff --git a/projects/01/project/Mux4Way16.tst b/projects/01/project/Mux4Way16.tst
new file mode 100644
index 0000000..0ff852f
--- /dev/null
+++ b/projects/01/project/Mux4Way16.tst
@@ -0,0 +1,49 @@
+// 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/1/Mux4Way16.tst
+
+load Mux4Way16.hdl,
+output-file Mux4Way16.out,
+compare-to Mux4Way16.cmp,
+output-list a%B1.16.1 b%B1.16.1 c%B1.16.1 d%B1.16.1 sel%B2.2.2 out%B1.16.1;
+
+set a 0,
+set b 0,
+set c 0,
+set d 0,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set sel 2,
+eval,
+output;
+
+set sel 3,
+eval,
+output;
+
+set a %B0001001000110100,
+set b %B1001100001110110,
+set c %B1010101010101010,
+set d %B0101010101010101,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set sel 2,
+eval,
+output;
+
+set sel 3,
+eval,
+output;
diff --git a/projects/01/project/Mux8Way16.cmp b/projects/01/project/Mux8Way16.cmp
new file mode 100644
index 0000000..11ff518
--- /dev/null
+++ b/projects/01/project/Mux8Way16.cmp
@@ -0,0 +1,17 @@
+| a | b | c | d | e | f | g | h | sel | out |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 000 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 001 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 010 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 011 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 100 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 101 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 110 | 0000000000000000 |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 111 | 0000000000000000 |
+| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 000 | 0001001000110100 |
+| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 001 | 0010001101000101 |
+| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 010 | 0011010001010110 |
+| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 011 | 0100010101100111 |
+| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 100 | 0101011001111000 |
+| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 101 | 0110011110001001 |
+| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 110 | 0111100010011010 |
+| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 111 | 1000100110101011 |
diff --git a/projects/01/project/Mux8Way16.hdl b/projects/01/project/Mux8Way16.hdl
new file mode 100644
index 0000000..4fe712e
--- /dev/null
+++ b/projects/01/project/Mux8Way16.hdl
@@ -0,0 +1,24 @@
+// 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/1/Mux8Way16.hdl
+/**
+ * 8-way 16-bit multiplexor:
+ * out = a if sel = 000
+ * b if sel = 001
+ * c if sel = 010
+ * d if sel = 011
+ * e if sel = 100
+ * f if sel = 101
+ * g if sel = 110
+ * h if sel = 111
+ */
+CHIP Mux8Way16 {
+ IN a[16], b[16], c[16], d[16],
+ e[16], f[16], g[16], h[16],
+ sel[3];
+ OUT out[16];
+
+ PARTS:
+ //// Replace this comment with your code.
+}
diff --git a/projects/01/project/Mux8Way16.tst b/projects/01/project/Mux8Way16.tst
new file mode 100644
index 0000000..aced052
--- /dev/null
+++ b/projects/01/project/Mux8Way16.tst
@@ -0,0 +1,89 @@
+// 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/1/Mux8Way16.tst
+
+load Mux8Way16.hdl,
+output-file Mux8Way16.out,
+compare-to Mux8Way16.cmp,
+output-list a%B1.16.1 b%B1.16.1 c%B1.16.1 d%B1.16.1 e%B1.16.1 f%B1.16.1 g%B1.16.1 h%B1.16.1 sel%B2.3.2 out%B1.16.1;
+
+set a 0,
+set b 0,
+set c 0,
+set d 0,
+set e 0,
+set f 0,
+set g 0,
+set h 0,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set sel 2,
+eval,
+output;
+
+set sel 3,
+eval,
+output;
+
+set sel 4,
+eval,
+output;
+
+set sel 5,
+eval,
+output;
+
+set sel 6,
+eval,
+output;
+
+set sel 7,
+eval,
+output;
+
+set a %B0001001000110100,
+set b %B0010001101000101,
+set c %B0011010001010110,
+set d %B0100010101100111,
+set e %B0101011001111000,
+set f %B0110011110001001,
+set g %B0111100010011010,
+set h %B1000100110101011,
+set sel 0,
+eval,
+output;
+
+set sel 1,
+eval,
+output;
+
+set sel 2,
+eval,
+output;
+
+set sel 3,
+eval,
+output;
+
+set sel 4,
+eval,
+output;
+
+set sel 5,
+eval,
+output;
+
+set sel 6,
+eval,
+output;
+
+set sel 7,
+eval,
+output;
diff --git a/projects/01/project/Not.cmp b/projects/01/project/Not.cmp
new file mode 100644
index 0000000..9b48db2
--- /dev/null
+++ b/projects/01/project/Not.cmp
@@ -0,0 +1,3 @@
+|in |out|
+| 0 | 1 |
+| 1 | 0 |
diff --git a/projects/01/project/Not.hdl b/projects/01/project/Not.hdl
new file mode 100644
index 0000000..9ce0063
--- /dev/null
+++ b/projects/01/project/Not.hdl
@@ -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/1/Not.hdl
+/**
+ * Not gate:
+ * if (in) out = 0, else out = 1
+ */
+CHIP Not {
+ IN in;
+ OUT out;
+
+ PARTS:
+ //// Replace this comment with your code.
+}
diff --git a/projects/01/project/Not.tst b/projects/01/project/Not.tst
new file mode 100644
index 0000000..ed0c8f9
--- /dev/null
+++ b/projects/01/project/Not.tst
@@ -0,0 +1,17 @@
+// 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/1/Not.tst
+
+load Not.hdl,
+output-file Not.out,
+compare-to Not.cmp,
+output-list in out;
+
+set in 0,
+eval,
+output;
+
+set in 1,
+eval,
+output;
diff --git a/projects/01/project/Not16.cmp b/projects/01/project/Not16.cmp
new file mode 100644
index 0000000..ae2ad1d
--- /dev/null
+++ b/projects/01/project/Not16.cmp
@@ -0,0 +1,6 @@
+| in | out |
+| 0000000000000000 | 1111111111111111 |
+| 1111111111111111 | 0000000000000000 |
+| 1010101010101010 | 0101010101010101 |
+| 0011110011000011 | 1100001100111100 |
+| 0001001000110100 | 1110110111001011 |
diff --git a/projects/01/project/Not16.hdl b/projects/01/project/Not16.hdl
new file mode 100644
index 0000000..e88babf
--- /dev/null
+++ b/projects/01/project/Not16.hdl
@@ -0,0 +1,16 @@
+// 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/1/Not16.hdl
+/**
+ * 16-bit Not gate:
+ * for i = 0, ..., 15:
+ * out[i] = Not(a[i])
+ */
+CHIP Not16 {
+ IN in[16];
+ OUT out[16];
+
+ PARTS:
+ //// Replace this comment with your code.
+}
\ No newline at end of file
diff --git a/projects/01/project/Not16.tst b/projects/01/project/Not16.tst
new file mode 100644
index 0000000..4bde067
--- /dev/null
+++ b/projects/01/project/Not16.tst
@@ -0,0 +1,29 @@
+// 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/1/Not16.tst
+
+load Not16.hdl,
+output-file Not16.out,
+compare-to Not16.cmp,
+output-list in%B1.16.1 out%B1.16.1;
+
+set in %B0000000000000000,
+eval,
+output;
+
+set in %B1111111111111111,
+eval,
+output;
+
+set in %B1010101010101010,
+eval,
+output;
+
+set in %B0011110011000011,
+eval,
+output;
+
+set in %B0001001000110100,
+eval,
+output;
\ No newline at end of file
diff --git a/projects/01/project/Or.cmp b/projects/01/project/Or.cmp
new file mode 100644
index 0000000..11f9d64
--- /dev/null
+++ b/projects/01/project/Or.cmp
@@ -0,0 +1,5 @@
+| a | b |out|
+| 0 | 0 | 0 |
+| 0 | 1 | 1 |
+| 1 | 0 | 1 |
+| 1 | 1 | 1 |
diff --git a/projects/01/project/Or.hdl b/projects/01/project/Or.hdl
new file mode 100644
index 0000000..1aa2dd7
--- /dev/null
+++ b/projects/01/project/Or.hdl
@@ -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/1/Or.hdl
+/**
+ * Or gate:
+ * if (a or b) out = 1, else out = 0
+ */
+CHIP Or {
+ IN a, b;
+ OUT out;
+
+ PARTS:
+ //// Replace this comment with your code.
+}
diff --git a/projects/01/project/Or.tst b/projects/01/project/Or.tst
new file mode 100644
index 0000000..65f07ad
--- /dev/null
+++ b/projects/01/project/Or.tst
@@ -0,0 +1,29 @@
+// 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/1/Or.tst
+
+load Or.hdl,
+output-file Or.out,
+compare-to Or.cmp,
+output-list a b out;
+
+set a 0,
+set b 0,
+eval,
+output;
+
+set a 0,
+set b 1,
+eval,
+output;
+
+set a 1,
+set b 0,
+eval,
+output;
+
+set a 1,
+set b 1,
+eval,
+output;
diff --git a/projects/01/project/Or16.cmp b/projects/01/project/Or16.cmp
new file mode 100644
index 0000000..8664afe
--- /dev/null
+++ b/projects/01/project/Or16.cmp
@@ -0,0 +1,7 @@
+| a | b | out |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 |
+| 0000000000000000 | 1111111111111111 | 1111111111111111 |
+| 1111111111111111 | 1111111111111111 | 1111111111111111 |
+| 1010101010101010 | 0101010101010101 | 1111111111111111 |
+| 0011110011000011 | 0000111111110000 | 0011111111110011 |
+| 0001001000110100 | 1001100001110110 | 1001101001110110 |
diff --git a/projects/01/project/Or16.hdl b/projects/01/project/Or16.hdl
new file mode 100644
index 0000000..4337602
--- /dev/null
+++ b/projects/01/project/Or16.hdl
@@ -0,0 +1,16 @@
+// 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/1/Or16.hdl
+/**
+ * 16-bit Or gate:
+ * for i = 0, ..., 15:
+ * out[i] = a[i] Or b[i]
+ */
+CHIP Or16 {
+ IN a[16], b[16];
+ OUT out[16];
+
+ PARTS:
+ //// Replace this comment with your code.
+}
\ No newline at end of file
diff --git a/projects/01/project/Or16.tst b/projects/01/project/Or16.tst
new file mode 100644
index 0000000..a2e221a
--- /dev/null
+++ b/projects/01/project/Or16.tst
@@ -0,0 +1,39 @@
+// 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/1/Or16.tst
+
+load Or16.hdl,
+output-file Or16.out,
+compare-to Or16.cmp,
+output-list a%B1.16.1 b%B1.16.1 out%B1.16.1;
+
+set a %B0000000000000000,
+set b %B0000000000000000,
+eval,
+output;
+
+set a %B0000000000000000,
+set b %B1111111111111111,
+eval,
+output;
+
+set a %B1111111111111111,
+set b %B1111111111111111,
+eval,
+output;
+
+set a %B1010101010101010,
+set b %B0101010101010101,
+eval,
+output;
+
+set a %B0011110011000011,
+set b %B0000111111110000,
+eval,
+output;
+
+set a %B0001001000110100,
+set b %B1001100001110110,
+eval,
+output;
\ No newline at end of file
diff --git a/projects/01/project/Or8Way.cmp b/projects/01/project/Or8Way.cmp
new file mode 100644
index 0000000..a1d2c4a
--- /dev/null
+++ b/projects/01/project/Or8Way.cmp
@@ -0,0 +1,6 @@
+| in |out|
+| 00000000 | 0 |
+| 11111111 | 1 |
+| 00010000 | 1 |
+| 00000001 | 1 |
+| 00100110 | 1 |
diff --git a/projects/01/project/Or8Way.hdl b/projects/01/project/Or8Way.hdl
new file mode 100644
index 0000000..6eff8a2
--- /dev/null
+++ b/projects/01/project/Or8Way.hdl
@@ -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/1/Or8Way.hdl
+/**
+ * 8-way Or gate:
+ * out = in[0] Or in[1] Or ... Or in[7]
+ */
+CHIP Or8Way {
+ IN in[8];
+ OUT out;
+
+ PARTS:
+ //// Replace this comment with your code.
+}
\ No newline at end of file
diff --git a/projects/01/project/Or8Way.tst b/projects/01/project/Or8Way.tst
new file mode 100644
index 0000000..e8e7e37
--- /dev/null
+++ b/projects/01/project/Or8Way.tst
@@ -0,0 +1,29 @@
+// 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/1/Or8Way.tst
+
+load Or8Way.hdl,
+output-file Or8Way.out,
+compare-to Or8Way.cmp,
+output-list in%B2.8.2 out;
+
+set in %B00000000,
+eval,
+output;
+
+set in %B11111111,
+eval,
+output;
+
+set in %B00010000,
+eval,
+output;
+
+set in %B00000001,
+eval,
+output;
+
+set in %B00100110,
+eval,
+output;
\ No newline at end of file
diff --git a/projects/01/project/Xor.cmp b/projects/01/project/Xor.cmp
new file mode 100644
index 0000000..3737173
--- /dev/null
+++ b/projects/01/project/Xor.cmp
@@ -0,0 +1,5 @@
+| a | b |out|
+| 0 | 0 | 0 |
+| 0 | 1 | 1 |
+| 1 | 0 | 1 |
+| 1 | 1 | 0 |
diff --git a/projects/01/project/Xor.hdl b/projects/01/project/Xor.hdl
new file mode 100644
index 0000000..c6d90f9
--- /dev/null
+++ b/projects/01/project/Xor.hdl
@@ -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/1/Xor.hdl
+/**
+ * Exclusive-or gate:
+ * if ((a and Not(b)) or (Not(a) and b)) out = 1, else out = 0
+ */
+CHIP Xor {
+ IN a, b;
+ OUT out;
+
+ PARTS:
+ //// Replace this comment with your code.
+}
\ No newline at end of file
diff --git a/projects/01/project/Xor.tst b/projects/01/project/Xor.tst
new file mode 100644
index 0000000..a6af078
--- /dev/null
+++ b/projects/01/project/Xor.tst
@@ -0,0 +1,29 @@
+// 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/1/Xor.tst
+
+load Xor.hdl,
+output-file Xor.out,
+compare-to Xor.cmp,
+output-list a b out;
+
+set a 0,
+set b 0,
+eval,
+output;
+
+set a 0,
+set b 1,
+eval,
+output;
+
+set a 1,
+set b 0,
+eval,
+output;
+
+set a 1,
+set b 1,
+eval,
+output;