diff options
author | Yuchen Pei <me@ypei.me> | 2018-01-20 15:41:49 +0100 |
---|---|---|
committer | Yuchen Pei <me@ypei.me> | 2018-01-20 15:41:49 +0100 |
commit | d3a0cc3a8ba6dfeb64d3faeffdeb6845b60e5840 (patch) | |
tree | d58df9ec2480e2a9ec6240f9c797f83d1a0b1056 /projects/12 | |
parent | 3571f998b28fbc8d9250ba04c983935f10a16c15 (diff) |
rearranged the dir for github
- removed tools and pdfs
- rearranged the projects dirs
- added md files
- other minor changes
Diffstat (limited to 'projects/12')
55 files changed, 0 insertions, 9573 deletions
diff --git a/projects/12/Array.jack b/projects/12/Array.jack deleted file mode 100644 index 343c25c..0000000 --- a/projects/12/Array.jack +++ /dev/null @@ -1,26 +0,0 @@ -// 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) {
- return Memory.alloc(size);
- }
-
- /** Disposes this array. */
- method void dispose() {
- do Memory.deAlloc(this);
- return;
- }
-}
diff --git a/projects/12/ArrayTest/Array.jack b/projects/12/ArrayTest/Array.jack deleted file mode 100644 index 343c25c..0000000 --- a/projects/12/ArrayTest/Array.jack +++ /dev/null @@ -1,26 +0,0 @@ -// 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) {
- return Memory.alloc(size);
- }
-
- /** Disposes this array. */
- method void dispose() {
- do Memory.deAlloc(this);
- return;
- }
-}
diff --git a/projects/12/ArrayTest/Array.vm b/projects/12/ArrayTest/Array.vm deleted file mode 100644 index c0cd797..0000000 --- a/projects/12/ArrayTest/Array.vm +++ /dev/null @@ -1,12 +0,0 @@ -function Array.new 0 -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/projects/12/ArrayTest/ArrayTest.cmp b/projects/12/ArrayTest/ArrayTest.cmp deleted file mode 100644 index d1a9798..0000000 --- a/projects/12/ArrayTest/ArrayTest.cmp +++ /dev/null @@ -1,2 +0,0 @@ -|RAM[8000]|RAM[8001]|RAM[8002]|RAM[8003]|
-| 222 | 122 | 100 | 10 |
diff --git a/projects/12/ArrayTest/ArrayTest.out b/projects/12/ArrayTest/ArrayTest.out deleted file mode 100644 index e9f4e75..0000000 --- a/projects/12/ArrayTest/ArrayTest.out +++ /dev/null @@ -1,2 +0,0 @@ -|RAM[8000]|RAM[8001]|RAM[8002]|RAM[8003]| -| 222 | 122 | 100 | 10 | diff --git a/projects/12/ArrayTest/ArrayTest.tst b/projects/12/ArrayTest/ArrayTest.tst deleted file mode 100644 index 89934b9..0000000 --- a/projects/12/ArrayTest/ArrayTest.tst +++ /dev/null @@ -1,15 +0,0 @@ -// This file is part of www.nand2tetris.org
-// and the book "The Elements of Computing Systems"
-// by Nisan and Schocken, MIT Press.
-// File name: projects/12/ArrayTest/ArrayTest.tst
-
-load,
-output-file ArrayTest.out,
-compare-to ArrayTest.cmp,
-output-list RAM[8000]%D2.6.1 RAM[8001]%D2.6.1 RAM[8002]%D2.6.1 RAM[8003]%D2.6.1;
-
-repeat 1000000 {
- vmstep;
-}
-
-output;
diff --git a/projects/12/ArrayTest/Main.jack b/projects/12/ArrayTest/Main.jack deleted file mode 100644 index 439770a..0000000 --- a/projects/12/ArrayTest/Main.jack +++ /dev/null @@ -1,40 +0,0 @@ -// 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/projects/12/ArrayTest/Main.vm b/projects/12/ArrayTest/Main.vm deleted file mode 100644 index 141f20a..0000000 --- a/projects/12/ArrayTest/Main.vm +++ /dev/null @@ -1,131 +0,0 @@ -function Main.main 4 -push constant 8000 -pop local 0 -push constant 3 -call Array.new 1 -pop local 1 -push constant 2 -push local 1 -add -push constant 222 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 0 -push local 0 -add -push constant 2 -push local 1 -add -pop pointer 1 -push that 0 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 3 -call Array.new 1 -pop local 2 -push constant 1 -push local 2 -add -push constant 2 -push local 1 -add -pop pointer 1 -push that 0 -push constant 100 -sub -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 1 -push local 0 -add -push constant 1 -push local 2 -add -pop pointer 1 -push that 0 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 500 -call Array.new 1 -pop local 3 -push constant 499 -push local 3 -add -push constant 2 -push local 1 -add -pop pointer 1 -push that 0 -push constant 1 -push local 2 -add -pop pointer 1 -push that 0 -sub -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 2 -push local 0 -add -push constant 499 -push local 3 -add -pop pointer 1 -push that 0 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push local 1 -call Array.dispose 1 -pop temp 0 -push local 2 -call Array.dispose 1 -pop temp 0 -push constant 3 -call Array.new 1 -pop local 2 -push constant 0 -push local 2 -add -push constant 499 -push local 3 -add -pop pointer 1 -push that 0 -push constant 90 -sub -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 3 -push local 0 -add -push constant 0 -push local 2 -add -pop pointer 1 -push that 0 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push local 3 -call Array.dispose 1 -pop temp 0 -push local 2 -call Array.dispose 1 -pop temp 0 -push constant 0 -return diff --git a/projects/12/Keyboard.jack b/projects/12/Keyboard.jack deleted file mode 100644 index a35704a..0000000 --- a/projects/12/Keyboard.jack +++ /dev/null @@ -1,97 +0,0 @@ -// 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() {
- return;
- }
-
- /**
- * 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() {
- return Memory.peek(24576);
- }
-
- /**
- * 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() {
- var int key, key1;
- let key = 0;
- while (key = 0) {
- let key = Memory.peek(24576);
- }
- let key1 = key;
- while (key1 = key) {
- let key1 = Memory.peek(24576);
- }
- if ((key > 31) & (key < 127) | (key = 128) | (key = 129)) {
- do Output.printChar(key);
- }
- return key;
- }
-
- /**
- * 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) {
- var int c;
- var String s;
- let s = String.new(140);
- do Output.printString(message);
- let c = Keyboard.readChar();
- while (~(c = 128)) {
- if (c = 129) {
- if (s.length() > 0) {
- do s.eraseLastChar();
- }
- } else {
- do s.appendChar(c);
- }
- let c = Keyboard.readChar();
- }
- return s;
- }
-
- /**
- * 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) {
- var String s;
- do Output.printString(message);
- let s = Keyboard.readLine("");
- return s.intValue();
- }
-}
diff --git a/projects/12/KeyboardTest/Keyboard.jack b/projects/12/KeyboardTest/Keyboard.jack deleted file mode 100644 index a35704a..0000000 --- a/projects/12/KeyboardTest/Keyboard.jack +++ /dev/null @@ -1,97 +0,0 @@ -// 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() {
- return;
- }
-
- /**
- * 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() {
- return Memory.peek(24576);
- }
-
- /**
- * 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() {
- var int key, key1;
- let key = 0;
- while (key = 0) {
- let key = Memory.peek(24576);
- }
- let key1 = key;
- while (key1 = key) {
- let key1 = Memory.peek(24576);
- }
- if ((key > 31) & (key < 127) | (key = 128) | (key = 129)) {
- do Output.printChar(key);
- }
- return key;
- }
-
- /**
- * 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) {
- var int c;
- var String s;
- let s = String.new(140);
- do Output.printString(message);
- let c = Keyboard.readChar();
- while (~(c = 128)) {
- if (c = 129) {
- if (s.length() > 0) {
- do s.eraseLastChar();
- }
- } else {
- do s.appendChar(c);
- }
- let c = Keyboard.readChar();
- }
- return s;
- }
-
- /**
- * 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) {
- var String s;
- do Output.printString(message);
- let s = Keyboard.readLine("");
- return s.intValue();
- }
-}
diff --git a/projects/12/KeyboardTest/Keyboard.vm b/projects/12/KeyboardTest/Keyboard.vm deleted file mode 100644 index 5dc3426..0000000 --- a/projects/12/KeyboardTest/Keyboard.vm +++ /dev/null @@ -1,115 +0,0 @@ -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 -pop local 0 -label WHILE_EXP0 -push local 0 -push constant 0 -eq -not -if-goto WHILE_END0 -push constant 24576 -call Memory.peek 1 -pop local 0 -goto WHILE_EXP0 -label WHILE_END0 -push local 0 -pop local 1 -label WHILE_EXP1 -push local 1 -push local 0 -eq -not -if-goto WHILE_END1 -push constant 24576 -call Memory.peek 1 -pop local 1 -goto WHILE_EXP1 -label WHILE_END1 -push local 0 -push constant 31 -gt -push local 0 -push constant 127 -lt -and -push local 0 -push constant 128 -eq -or -push local 0 -push constant 129 -eq -or -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push local 0 -call Output.printChar 1 -pop temp 0 -label IF_FALSE0 -push local 0 -return -function Keyboard.readLine 2 -push constant 140 -call String.new 1 -pop local 1 -push argument 0 -call Output.printString 1 -pop temp 0 -call Keyboard.readChar 0 -pop local 0 -label WHILE_EXP0 -push local 0 -push constant 128 -eq -not -not -if-goto WHILE_END0 -push local 0 -push constant 129 -eq -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push local 1 -call String.length 1 -push constant 0 -gt -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push local 1 -call String.eraseLastChar 1 -pop temp 0 -label IF_FALSE1 -goto IF_END0 -label IF_FALSE0 -push local 1 -push local 0 -call String.appendChar 2 -pop temp 0 -label IF_END0 -call Keyboard.readChar 0 -pop local 0 -goto WHILE_EXP0 -label WHILE_END0 -push local 1 -return -function Keyboard.readInt 1 -push argument 0 -call Output.printString 1 -pop temp 0 -push constant 0 -call String.new 1 -call Keyboard.readLine 1 -pop local 0 -push local 0 -call String.intValue 1 -return diff --git a/projects/12/KeyboardTest/KeyboardTestOutput.gif b/projects/12/KeyboardTest/KeyboardTestOutput.gif Binary files differdeleted file mode 100644 index 944983a..0000000 --- a/projects/12/KeyboardTest/KeyboardTestOutput.gif +++ /dev/null diff --git a/projects/12/KeyboardTest/Main.jack b/projects/12/KeyboardTest/Main.jack deleted file mode 100644 index e89182c..0000000 --- a/projects/12/KeyboardTest/Main.jack +++ /dev/null @@ -1,93 +0,0 @@ -// 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 'Page Down' key");
- while (key = 0) {
- let key = Keyboard.keyPressed();
- }
- let c = key;
- while (~(key = 0)) {
- let key = Keyboard.keyPressed();
- }
-
- do Output.println();
-
- if (c = 137) {
- 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/projects/12/KeyboardTest/Main.vm b/projects/12/KeyboardTest/Main.vm deleted file mode 100644 index aec89d6..0000000 --- a/projects/12/KeyboardTest/Main.vm +++ /dev/null @@ -1,949 +0,0 @@ -function Main.main 5 -push constant 0 -pop local 4 -push constant 16 -call String.new 1 -push constant 107 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 121 -call String.appendChar 2 -push constant 80 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -label WHILE_EXP0 -push local 4 -not -not -if-goto WHILE_END0 -push constant 32 -call String.new 1 -push constant 80 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 39 -call String.appendChar 2 -push constant 80 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 68 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 119 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 39 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 107 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 121 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -label WHILE_EXP1 -push local 1 -push constant 0 -eq -not -if-goto WHILE_END1 -call Keyboard.keyPressed 0 -pop local 1 -goto WHILE_EXP1 -label WHILE_END1 -push local 1 -pop local 0 -label WHILE_EXP2 -push local 1 -push constant 0 -eq -not -not -if-goto WHILE_END2 -call Keyboard.keyPressed 0 -pop local 1 -goto WHILE_EXP2 -label WHILE_END2 -call Output.println 0 -pop temp 0 -push local 0 -push constant 137 -eq -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 2 -call String.new 1 -push constant 111 -call String.appendChar 2 -push constant 107 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 0 -not -pop local 4 -label IF_FALSE0 -goto WHILE_EXP0 -label WHILE_END0 -push constant 0 -pop local 4 -push constant 14 -call String.new 1 -push constant 114 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 67 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 59 -call String.new 1 -push constant 40 -call String.appendChar 2 -push constant 86 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 102 -call String.appendChar 2 -push constant 121 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 41 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -label WHILE_EXP3 -push local 4 -not -not -if-goto WHILE_END3 -push constant 29 -call String.new 1 -push constant 80 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 109 -call String.appendChar 2 -push constant 98 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 39 -call String.appendChar 2 -push constant 51 -call String.appendChar 2 -push constant 39 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -call Keyboard.readChar 0 -pop local 0 -call Output.println 0 -pop temp 0 -push local 0 -push constant 51 -eq -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push constant 2 -call String.new 1 -push constant 111 -call String.appendChar 2 -push constant 107 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 0 -not -pop local 4 -label IF_FALSE1 -goto WHILE_EXP3 -label WHILE_END3 -push constant 0 -pop local 4 -push constant 14 -call String.new 1 -push constant 114 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 76 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 38 -call String.new 1 -push constant 40 -call String.appendChar 2 -push constant 86 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 102 -call String.appendChar 2 -push constant 121 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 102 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 39 -call String.appendChar 2 -push constant 98 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 107 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 39 -call String.appendChar 2 -push constant 41 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -label WHILE_EXP4 -push local 4 -not -not -if-goto WHILE_END4 -push constant 36 -call String.new 1 -push constant 80 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 121 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 39 -call String.appendChar 2 -push constant 74 -call String.appendChar 2 -push constant 65 -call String.appendChar 2 -push constant 67 -call String.appendChar 2 -push constant 75 -call String.appendChar 2 -push constant 39 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -call Keyboard.readLine 1 -pop local 2 -push local 2 -call String.length 1 -push constant 4 -eq -if-goto IF_TRUE2 -goto IF_FALSE2 -label IF_TRUE2 -push local 2 -push constant 0 -call String.charAt 2 -push constant 74 -eq -push local 2 -push constant 1 -call String.charAt 2 -push constant 65 -eq -and -push local 2 -push constant 2 -call String.charAt 2 -push constant 67 -eq -and -push local 2 -push constant 3 -call String.charAt 2 -push constant 75 -eq -and -if-goto IF_TRUE3 -goto IF_FALSE3 -label IF_TRUE3 -push constant 2 -call String.new 1 -push constant 111 -call String.appendChar 2 -push constant 107 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 0 -not -pop local 4 -label IF_FALSE3 -label IF_FALSE2 -goto WHILE_EXP4 -label WHILE_END4 -push constant 0 -pop local 4 -push constant 13 -call String.new 1 -push constant 114 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 73 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 38 -call String.new 1 -push constant 40 -call String.appendChar 2 -push constant 86 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 102 -call String.appendChar 2 -push constant 121 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 102 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 39 -call String.appendChar 2 -push constant 98 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 107 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 39 -call String.appendChar 2 -push constant 41 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -label WHILE_EXP5 -push local 4 -not -not -if-goto WHILE_END5 -push constant 38 -call String.new 1 -push constant 80 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 121 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 39 -call String.appendChar 2 -push constant 45 -call String.appendChar 2 -push constant 51 -call String.appendChar 2 -push constant 50 -call String.appendChar 2 -push constant 49 -call String.appendChar 2 -push constant 50 -call String.appendChar 2 -push constant 51 -call String.appendChar 2 -push constant 39 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -call Keyboard.readInt 1 -pop local 3 -push local 3 -push constant 32123 -neg -eq -if-goto IF_TRUE4 -goto IF_FALSE4 -label IF_TRUE4 -push constant 2 -call String.new 1 -push constant 111 -call String.appendChar 2 -push constant 107 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 0 -not -pop local 4 -label IF_FALSE4 -goto WHILE_EXP5 -label WHILE_END5 -call Output.println 0 -pop temp 0 -push constant 27 -call String.new 1 -push constant 84 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 109 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 102 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 121 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push constant 0 -return diff --git a/projects/12/Math.jack b/projects/12/Math.jack deleted file mode 100644 index 01bce8f..0000000 --- a/projects/12/Math.jack +++ /dev/null @@ -1,158 +0,0 @@ -// 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.
- * Note: Jack compilers implement multiplication and division using OS method calls.
- */
-class Math {
- static Array twoToThe;
-
- /** Initializes the library. */
- function void init() {
- var int i, x;
- let x = 1;
- let i = 0;
- let twoToThe = Array.new(16);
- while (i < 16){
- let twoToThe[i] = x;
- let x = x + x;
- let i = i + 1;
- }
- return;
- }
-
- function boolean bit(int x, int i) {
- return ~(x & twoToThe[i] = 0);
- }
-
- function int sign(int x) {
- if (x > 0) {
- return 1;
- } else {
- if (x < 0) {
- return -1;
- } else {
- return 0;
- }
- }
- }
-
- /** Returns the absolute value of x. */
- function int abs(int x) {
- if (x > 0){
- return x;
- } else {
- return -x;
- }
- }
-
- /** Returns the product of x and y.
- * When a Jack compiler detects the multiplication operator '*' in the
- * program's code, it handles it by invoking this method. In other words,
- * the Jack expressions x*y and multiply(x,y) return the same value.
- */
- function int multiply(int x, int y) {
- var int res, shiftedX, i;
- let shiftedX = x;
- let i = 0;
- let res = 0;
- //while ((~(twoToThe[i] > y)) & (i < 16)) {
- while (i < 16) {
- if (Math.bit(y, i)){
- let res = res + shiftedX;
- }
- let shiftedX = shiftedX + shiftedX;
- let i = i + 1;
- }
- return res;
- }
-
- /** Returns the integer part of x/y.
- * When a Jack compiler detects the multiplication operator '/' in the
- * program's code, it handles it by invoking this method. In other words,
- * the Jack expressions x/y and divide(x,y) return the same value.
- */
- function int divide(int x, int y) {
- var int ax, ay;
- if (x > 0) {
- if (y > 0) {
- return Math.divide1(x, y);
- } else {
- return -Math.divide1(x, -y);
- }
- } else {
- if (y > 0) {
- return -Math.divide1(-x, y);
- } else {
- return Math.divide1(-x, -y);
- }
- }
- }
-
- function int divide1(int x, int y) {
- var int q;
- if (y = 0) {
- do Output.printString("Error: division by zero.");
- do Sys.error(0);
- }
- if ((y > x) | (y < 0)) {
- return 0;
- }
- let q = Math.divide1(x, y * 2);
- if (x - (2 * q * y) < y) {
- return 2 * q;
- } else {
- return 2 * q + 1;
- }
- }
-
- function int length(int x){
- var int n;
- let n = 14;
- while (twoToThe[n] > x){
- let n = n - 1;
- }
- return n;
- }
-
- /** Returns the integer part of the square root of x. */
- function int sqrt(int x) {
- var int y, k, z, w;
- if (x < 0) {
- do Output.printString("Error: square rooting a negative number.");
- do Sys.error(0);
- }
- let k = Math.length(x) / 2;
- let y = 0;
- while (~(k < 0)) {
- let z = y + twoToThe[k];
- let w = z * z;
- if ((~(w > x)) & (w > 0)) {
- let y = z;
- }
- let k = k - 1;
- }
- return y;
- }
-
- /** Returns the greater number. */
- function int max(int a, int b) {
- if (a > b) {
- return a;
- } else {
- return b;
- }
- }
-
- /** Returns the smaller number. */
- function int min(int a, int b) {
- if (a < b) {
- return a;
- } else {
- return b;
- }
- }
-}
diff --git a/projects/12/MathTest/Main.jack b/projects/12/MathTest/Main.jack deleted file mode 100644 index de5cec2..0000000 --- a/projects/12/MathTest/Main.jack +++ /dev/null @@ -1,35 +0,0 @@ -// 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
-
-/** Test program for 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;
-
- 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); // 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;
- }
-}
diff --git a/projects/12/MathTest/Main.vm b/projects/12/MathTest/Main.vm deleted file mode 100644 index 025f20c..0000000 --- a/projects/12/MathTest/Main.vm +++ /dev/null @@ -1,162 +0,0 @@ -function Main.main 1 -push constant 8000 -pop local 0 -push constant 0 -push local 0 -add -push constant 2 -push constant 3 -call Math.multiply 2 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 1 -push local 0 -add -push constant 0 -push local 0 -add -pop pointer 1 -push that 0 -push constant 30 -neg -call Math.multiply 2 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 2 -push local 0 -add -push constant 1 -push local 0 -add -pop pointer 1 -push that 0 -push constant 100 -call Math.multiply 2 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 3 -push local 0 -add -push constant 1 -push constant 2 -push local 0 -add -pop pointer 1 -push that 0 -call Math.multiply 2 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 4 -push local 0 -add -push constant 3 -push local 0 -add -pop pointer 1 -push that 0 -push constant 0 -call Math.multiply 2 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 5 -push local 0 -add -push constant 9 -push constant 3 -call Math.divide 2 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 6 -push local 0 -add -push constant 18000 -neg -push constant 6 -call Math.divide 2 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 7 -push local 0 -add -push constant 32766 -push constant 32767 -neg -call Math.divide 2 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 8 -push local 0 -add -push constant 9 -call Math.sqrt 1 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 9 -push local 0 -add -push constant 32767 -call Math.sqrt 1 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 10 -push local 0 -add -push constant 345 -push constant 123 -call Math.min 2 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 11 -push local 0 -add -push constant 123 -push constant 345 -neg -call Math.max 2 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 12 -push local 0 -add -push constant 27 -call Math.abs 1 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 13 -push local 0 -add -push constant 32767 -neg -call Math.abs 1 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 0 -return diff --git a/projects/12/MathTest/Math.jack b/projects/12/MathTest/Math.jack deleted file mode 100644 index 01bce8f..0000000 --- a/projects/12/MathTest/Math.jack +++ /dev/null @@ -1,158 +0,0 @@ -// 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.
- * Note: Jack compilers implement multiplication and division using OS method calls.
- */
-class Math {
- static Array twoToThe;
-
- /** Initializes the library. */
- function void init() {
- var int i, x;
- let x = 1;
- let i = 0;
- let twoToThe = Array.new(16);
- while (i < 16){
- let twoToThe[i] = x;
- let x = x + x;
- let i = i + 1;
- }
- return;
- }
-
- function boolean bit(int x, int i) {
- return ~(x & twoToThe[i] = 0);
- }
-
- function int sign(int x) {
- if (x > 0) {
- return 1;
- } else {
- if (x < 0) {
- return -1;
- } else {
- return 0;
- }
- }
- }
-
- /** Returns the absolute value of x. */
- function int abs(int x) {
- if (x > 0){
- return x;
- } else {
- return -x;
- }
- }
-
- /** Returns the product of x and y.
- * When a Jack compiler detects the multiplication operator '*' in the
- * program's code, it handles it by invoking this method. In other words,
- * the Jack expressions x*y and multiply(x,y) return the same value.
- */
- function int multiply(int x, int y) {
- var int res, shiftedX, i;
- let shiftedX = x;
- let i = 0;
- let res = 0;
- //while ((~(twoToThe[i] > y)) & (i < 16)) {
- while (i < 16) {
- if (Math.bit(y, i)){
- let res = res + shiftedX;
- }
- let shiftedX = shiftedX + shiftedX;
- let i = i + 1;
- }
- return res;
- }
-
- /** Returns the integer part of x/y.
- * When a Jack compiler detects the multiplication operator '/' in the
- * program's code, it handles it by invoking this method. In other words,
- * the Jack expressions x/y and divide(x,y) return the same value.
- */
- function int divide(int x, int y) {
- var int ax, ay;
- if (x > 0) {
- if (y > 0) {
- return Math.divide1(x, y);
- } else {
- return -Math.divide1(x, -y);
- }
- } else {
- if (y > 0) {
- return -Math.divide1(-x, y);
- } else {
- return Math.divide1(-x, -y);
- }
- }
- }
-
- function int divide1(int x, int y) {
- var int q;
- if (y = 0) {
- do Output.printString("Error: division by zero.");
- do Sys.error(0);
- }
- if ((y > x) | (y < 0)) {
- return 0;
- }
- let q = Math.divide1(x, y * 2);
- if (x - (2 * q * y) < y) {
- return 2 * q;
- } else {
- return 2 * q + 1;
- }
- }
-
- function int length(int x){
- var int n;
- let n = 14;
- while (twoToThe[n] > x){
- let n = n - 1;
- }
- return n;
- }
-
- /** Returns the integer part of the square root of x. */
- function int sqrt(int x) {
- var int y, k, z, w;
- if (x < 0) {
- do Output.printString("Error: square rooting a negative number.");
- do Sys.error(0);
- }
- let k = Math.length(x) / 2;
- let y = 0;
- while (~(k < 0)) {
- let z = y + twoToThe[k];
- let w = z * z;
- if ((~(w > x)) & (w > 0)) {
- let y = z;
- }
- let k = k - 1;
- }
- return y;
- }
-
- /** Returns the greater number. */
- function int max(int a, int b) {
- if (a > b) {
- return a;
- } else {
- return b;
- }
- }
-
- /** Returns the smaller number. */
- function int min(int a, int b) {
- if (a < b) {
- return a;
- } else {
- return b;
- }
- }
-}
diff --git a/projects/12/MathTest/Math.vm b/projects/12/MathTest/Math.vm deleted file mode 100644 index 513fc1a..0000000 --- a/projects/12/MathTest/Math.vm +++ /dev/null @@ -1,472 +0,0 @@ -function Math.init 2 -push constant 1 -pop local 1 -push constant 0 -pop local 0 -push constant 16 -call Array.new 1 -pop static 0 -label WHILE_EXP0 -push local 0 -push constant 16 -lt -not -if-goto WHILE_END0 -push local 0 -push static 0 -add -push local 1 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push local 1 -push local 1 -add -pop local 1 -push local 0 -push constant 1 -add -pop local 0 -goto WHILE_EXP0 -label WHILE_END0 -push constant 0 -return -function Math.bit 0 -push argument 0 -push argument 1 -push static 0 -add -pop pointer 1 -push that 0 -and -push constant 0 -eq -not -return -function Math.sign 0 -push argument 0 -push constant 0 -gt -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 1 -return -goto IF_END0 -label IF_FALSE0 -push argument 0 -push constant 0 -lt -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push constant 1 -neg -return -goto IF_END1 -label IF_FALSE1 -push constant 0 -return -label IF_END1 -label IF_END0 -function Math.abs 0 -push argument 0 -push constant 0 -gt -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push argument 0 -return -goto IF_END0 -label IF_FALSE0 -push argument 0 -neg -return -label IF_END0 -function Math.multiply 3 -push argument 0 -pop local 1 -push constant 0 -pop local 2 -push constant 0 -pop local 0 -label WHILE_EXP0 -push local 2 -push constant 16 -lt -not -if-goto WHILE_END0 -push argument 1 -push local 2 -call Math.bit 2 -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push local 0 -push local 1 -add -pop local 0 -label IF_FALSE0 -push local 1 -push local 1 -add -pop local 1 -push local 2 -push constant 1 -add -pop local 2 -goto WHILE_EXP0 -label WHILE_END0 -push local 0 -return -function Math.divide 2 -push argument 0 -push constant 0 -gt -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push argument 1 -push constant 0 -gt -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push argument 0 -push argument 1 -call Math.divide1 2 -return -goto IF_END1 -label IF_FALSE1 -push argument 0 -push argument 1 -neg -call Math.divide1 2 -neg -return -label IF_END1 -goto IF_END0 -label IF_FALSE0 -push argument 1 -push constant 0 -gt -if-goto IF_TRUE2 -goto IF_FALSE2 -label IF_TRUE2 -push argument 0 -neg -push argument 1 -call Math.divide1 2 -neg -return -goto IF_END2 -label IF_FALSE2 -push argument 0 -neg -push argument 1 -neg -call Math.divide1 2 -return -label IF_END2 -label IF_END0 -function Math.divide1 1 -push argument 1 -push constant 0 -eq -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 24 -call String.new 1 -push constant 69 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 118 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 98 -call String.appendChar 2 -push constant 121 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 122 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 46 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push constant 0 -call Sys.error 1 -pop temp 0 -label IF_FALSE0 -push argument 1 -push argument 0 -gt -push argument 1 -push constant 0 -lt -or -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push constant 0 -return -label IF_FALSE1 -push argument 0 -push argument 1 -push constant 2 -call Math.multiply 2 -call Math.divide1 2 -pop local 0 -push argument 0 -push constant 2 -push local 0 -call Math.multiply 2 -push argument 1 -call Math.multiply 2 -sub -push argument 1 -lt -if-goto IF_TRUE2 -goto IF_FALSE2 -label IF_TRUE2 -push constant 2 -push local 0 -call Math.multiply 2 -return -goto IF_END2 -label IF_FALSE2 -push constant 2 -push local 0 -call Math.multiply 2 -push constant 1 -add -return -label IF_END2 -function Math.length 1 -push constant 14 -pop local 0 -label WHILE_EXP0 -push local 0 -push static 0 -add -pop pointer 1 -push that 0 -push argument 0 -gt -not -if-goto WHILE_END0 -push local 0 -push constant 1 -sub -pop local 0 -goto WHILE_EXP0 -label WHILE_END0 -push local 0 -return -function Math.sqrt 4 -push argument 0 -push constant 0 -lt -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 40 -call String.new 1 -push constant 69 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 113 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 118 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 109 -call String.appendChar 2 -push constant 98 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 46 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push constant 0 -call Sys.error 1 -pop temp 0 -label IF_FALSE0 -push argument 0 -call Math.length 1 -push constant 2 -call Math.divide 2 -pop local 1 -push constant 0 -pop local 0 -label WHILE_EXP0 -push local 1 -push constant 0 -lt -not -not -if-goto WHILE_END0 -push local 0 -push local 1 -push static 0 -add -pop pointer 1 -push that 0 -add -pop local 2 -push local 2 -push local 2 -call Math.multiply 2 -pop local 3 -push local 3 -push argument 0 -gt -not -push local 3 -push constant 0 -gt -and -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push local 2 -pop local 0 -label IF_FALSE1 -push local 1 -push constant 1 -sub -pop local 1 -goto WHILE_EXP0 -label WHILE_END0 -push local 0 -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 -return -goto IF_END0 -label IF_FALSE0 -push argument 1 -return -label IF_END0 -function Math.min 0 -push argument 0 -push argument 1 -lt -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push argument 0 -return -goto IF_END0 -label IF_FALSE0 -push argument 1 -return -label IF_END0 diff --git a/projects/12/MathTest/MathTest.cmp b/projects/12/MathTest/MathTest.cmp deleted file mode 100644 index 703c1be..0000000 --- a/projects/12/MathTest/MathTest.cmp +++ /dev/null @@ -1,2 +0,0 @@ -|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/projects/12/MathTest/MathTest.out b/projects/12/MathTest/MathTest.out deleted file mode 100644 index 8b5a504..0000000 --- a/projects/12/MathTest/MathTest.out +++ /dev/null @@ -1,2 +0,0 @@ -|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/projects/12/MathTest/MathTest.tst b/projects/12/MathTest/MathTest.tst deleted file mode 100644 index 127dbb4..0000000 --- a/projects/12/MathTest/MathTest.tst +++ /dev/null @@ -1,15 +0,0 @@ -// 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/projects/12/Memory.jack b/projects/12/Memory.jack deleted file mode 100644 index 54e04aa..0000000 --- a/projects/12/Memory.jack +++ /dev/null @@ -1,72 +0,0 @@ -// 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 {
- static Array memory;
- static Array heap;
- static int last;
-
- /** Initializes the class. */
- function void init() {
- let memory = 0;
- let heap = 2048;
- let heap[0] = -1;
- let heap[1] = 14334;
- let last = 0;
- return;
- }
-
- /** Returns the RAM value at the given address. */
- function int peek(int address) {
- return memory[address];
- }
-
- /** Sets the RAM value at the given address to the given value. */
- function void poke(int address, int value) {
- let memory[address] = value;
- return;
- }
-
- /** Finds an available RAM block of the given size and returns
- * a reference to its base address. */
- function int alloc(int size) {
- var int current;
- var int size2;
- var int newLast;
- let current = 0;
- let size2 = size + 2;
- while ((current > -1) & (heap[current + 1] < size2)) {
- let current = heap[current];
- }
- if (current = -1) {
- do String.println("Insufficient space for allocation!");
- do Sys.error(1);
- return -1;
- } else {
- let heap[current + 1] = heap[current + 1] - size2;
- let newLast = current + heap[current + 1] + 2;
- let heap[newLast] = heap[current];
- let heap[current] = newLast;
- let heap[newLast + 1] = size;
- return heap + newLast + 2;
- }
- }
-
- /** De-allocates the given object (cast as an array) by making
- * it available for future allocations. */
- function void deAlloc(Array o) {
- var int oBase;
- let oBase = o - heap - 2;
- let heap[oBase] = -1;
- let heap[last] = oBase;
- let last = oBase;
- return;
- }
-}
diff --git a/projects/12/MemoryTest/Main.jack b/projects/12/MemoryTest/Main.jack deleted file mode 100644 index 77a53a9..0000000 --- a/projects/12/MemoryTest/Main.jack +++ /dev/null @@ -1,42 +0,0 @@ -// This file is part of www.nand2tetris.org
-// and the book "The Elements of Computing Systems"
-// by Nisan and Schocken, MIT Press.
-// File name: projects/12/MemoryTest/Main.jack
-
-/** Test program for the OS Memory class. */
-class Main {
-
- /** Performs various memory manipulations. */
- function void main() {
- var int temp;
- var Array a, b, c;
-
- do Memory.poke(8000, 333); // RAM[8000] = 333
- let temp = Memory.peek(8000);
- do Memory.poke(8001, temp + 1); // RAM[8001] = 334
-
- let a = Array.new(3); // uses Memory.alloc
- let a[2] = 222;
- do Memory.poke(8002, a[2]); // RAM[8002] = 222
-
- let b = Array.new(3);
- let b[1] = a[2] - 100;
- do Memory.poke(8003, b[1]); // RAM[8003] = 122
-
- let c = Array.new(500);
- let c[499] = a[2] - b[1];
- do Memory.poke(8004, c[499]); // RAM[8004] = 100
-
- do a.dispose(); // uses Memory.deAlloc
- do b.dispose();
-
- let b = Array.new(3);
- let b[0] = c[499] - 90;
- do Memory.poke(8005, b[0]); // RAM[8005] = 10
-
- do c.dispose();
- do b.dispose();
-
- return;
- }
-}
diff --git a/projects/12/MemoryTest/Main.vm b/projects/12/MemoryTest/Main.vm deleted file mode 100644 index a3a9e81..0000000 --- a/projects/12/MemoryTest/Main.vm +++ /dev/null @@ -1,126 +0,0 @@ -function Main.main 4 -push constant 8000 -push constant 333 -call Memory.poke 2 -pop temp 0 -push constant 8000 -call Memory.peek 1 -pop local 0 -push constant 8001 -push local 0 -push constant 1 -add -call Memory.poke 2 -pop temp 0 -push constant 3 -call Array.new 1 -pop local 1 -push constant 2 -push local 1 -add -push constant 222 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 8002 -push constant 2 -push local 1 -add -pop pointer 1 -push that 0 -call Memory.poke 2 -pop temp 0 -push constant 3 -call Array.new 1 -pop local 2 -push constant 1 -push local 2 -add -push constant 2 -push local 1 -add -pop pointer 1 -push that 0 -push constant 100 -sub -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 8003 -push constant 1 -push local 2 -add -pop pointer 1 -push that 0 -call Memory.poke 2 -pop temp 0 -push constant 500 -call Array.new 1 -pop local 3 -push constant 499 -push local 3 -add -push constant 2 -push local 1 -add -pop pointer 1 -push that 0 -push constant 1 -push local 2 -add -pop pointer 1 -push that 0 -sub -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 8004 -push constant 499 -push local 3 -add -pop pointer 1 -push that 0 -call Memory.poke 2 -pop temp 0 -push local 1 -call Array.dispose 1 -pop temp 0 -push local 2 -call Array.dispose 1 -pop temp 0 -push constant 3 -call Array.new 1 -pop local 2 -push constant 0 -push local 2 -add -push constant 499 -push local 3 -add -pop pointer 1 -push that 0 -push constant 90 -sub -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 8005 -push constant 0 -push local 2 -add -pop pointer 1 -push that 0 -call Memory.poke 2 -pop temp 0 -push local 3 -call Array.dispose 1 -pop temp 0 -push local 2 -call Array.dispose 1 -pop temp 0 -push constant 0 -return diff --git a/projects/12/MemoryTest/Memory.jack b/projects/12/MemoryTest/Memory.jack deleted file mode 100644 index 54e04aa..0000000 --- a/projects/12/MemoryTest/Memory.jack +++ /dev/null @@ -1,72 +0,0 @@ -// 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 {
- static Array memory;
- static Array heap;
- static int last;
-
- /** Initializes the class. */
- function void init() {
- let memory = 0;
- let heap = 2048;
- let heap[0] = -1;
- let heap[1] = 14334;
- let last = 0;
- return;
- }
-
- /** Returns the RAM value at the given address. */
- function int peek(int address) {
- return memory[address];
- }
-
- /** Sets the RAM value at the given address to the given value. */
- function void poke(int address, int value) {
- let memory[address] = value;
- return;
- }
-
- /** Finds an available RAM block of the given size and returns
- * a reference to its base address. */
- function int alloc(int size) {
- var int current;
- var int size2;
- var int newLast;
- let current = 0;
- let size2 = size + 2;
- while ((current > -1) & (heap[current + 1] < size2)) {
- let current = heap[current];
- }
- if (current = -1) {
- do String.println("Insufficient space for allocation!");
- do Sys.error(1);
- return -1;
- } else {
- let heap[current + 1] = heap[current + 1] - size2;
- let newLast = current + heap[current + 1] + 2;
- let heap[newLast] = heap[current];
- let heap[current] = newLast;
- let heap[newLast + 1] = size;
- return heap + newLast + 2;
- }
- }
-
- /** De-allocates the given object (cast as an array) by making
- * it available for future allocations. */
- function void deAlloc(Array o) {
- var int oBase;
- let oBase = o - heap - 2;
- let heap[oBase] = -1;
- let heap[last] = oBase;
- let last = oBase;
- return;
- }
-}
diff --git a/projects/12/MemoryTest/Memory.vm b/projects/12/MemoryTest/Memory.vm deleted file mode 100644 index 0570b46..0000000 --- a/projects/12/MemoryTest/Memory.vm +++ /dev/null @@ -1,258 +0,0 @@ -function Memory.init 0 -push constant 0 -pop static 0 -push constant 2048 -pop static 1 -push constant 0 -push static 1 -add -push constant 1 -neg -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 1 -push static 1 -add -push constant 14334 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 0 -pop static 2 -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 3 -push constant 0 -pop local 0 -push argument 0 -push constant 2 -add -pop local 1 -label WHILE_EXP0 -push local 0 -push constant 1 -neg -gt -push local 0 -push constant 1 -add -push static 1 -add -pop pointer 1 -push that 0 -push local 1 -lt -and -not -if-goto WHILE_END0 -push local 0 -push static 1 -add -pop pointer 1 -push that 0 -pop local 0 -goto WHILE_EXP0 -label WHILE_END0 -push local 0 -push constant 1 -neg -eq -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 34 -call String.new 1 -push constant 73 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 102 -call String.appendChar 2 -push constant 102 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 102 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 33 -call String.appendChar 2 -call String.println 1 -pop temp 0 -push constant 1 -call Sys.error 1 -pop temp 0 -push constant 1 -neg -return -goto IF_END0 -label IF_FALSE0 -push local 0 -push constant 1 -add -push static 1 -add -push local 0 -push constant 1 -add -push static 1 -add -pop pointer 1 -push that 0 -push local 1 -sub -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push local 0 -push local 0 -push constant 1 -add -push static 1 -add -pop pointer 1 -push that 0 -add -push constant 2 -add -pop local 2 -push local 2 -push static 1 -add -push local 0 -push static 1 -add -pop pointer 1 -push that 0 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push local 0 -push static 1 -add -push local 2 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push local 2 -push constant 1 -add -push static 1 -add -push argument 0 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push static 1 -push local 2 -add -push constant 2 -add -return -label IF_END0 -function Memory.deAlloc 1 -push argument 0 -push static 1 -sub -push constant 2 -sub -pop local 0 -push local 0 -push static 1 -add -push constant 1 -neg -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push static 2 -push static 1 -add -push local 0 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push local 0 -pop static 2 -push constant 0 -return diff --git a/projects/12/MemoryTest/MemoryTest.cmp b/projects/12/MemoryTest/MemoryTest.cmp deleted file mode 100644 index 057958b..0000000 --- a/projects/12/MemoryTest/MemoryTest.cmp +++ /dev/null @@ -1,2 +0,0 @@ -|RAM[8000]|RAM[8001]|RAM[8002]|RAM[8003]|RAM[8004]|RAM[8005]|
-| 333 | 334 | 222 | 122 | 100 | 10 |
diff --git a/projects/12/MemoryTest/MemoryTest.out b/projects/12/MemoryTest/MemoryTest.out deleted file mode 100644 index e69de29..0000000 --- a/projects/12/MemoryTest/MemoryTest.out +++ /dev/null diff --git a/projects/12/MemoryTest/MemoryTest.tst b/projects/12/MemoryTest/MemoryTest.tst deleted file mode 100644 index 1da34fd..0000000 --- a/projects/12/MemoryTest/MemoryTest.tst +++ /dev/null @@ -1,15 +0,0 @@ -// This file is part of www.nand2tetris.org
-// and the book "The Elements of Computing Systems"
-// by Nisan and Schocken, MIT Press.
-// File name: projects/12/MemoryTest/MemoryTest.tst
-
-load,
-output-file MemoryTest.out,
-compare-to MemoryTest.cmp,
-output-list RAM[8000]%D2.6.1 RAM[8001]%D2.6.1 RAM[8002]%D2.6.1 RAM[8003]%D2.6.1 RAM[8004]%D2.6.1 RAM[8005]%D2.6.1;
-
-repeat 1000000 {
- vmstep;
-}
-
-output;
diff --git a/projects/12/Output.jack b/projects/12/Output.jack deleted file mode 100644 index 61b24de..0000000 --- a/projects/12/Output.jack +++ /dev/null @@ -1,281 +0,0 @@ -// 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/Output.jack
-
-/**
- * A library of functions for writing text on the screen.
- * The Hack physical screen consists of 512 rows of 256 pixels each.
- * The library uses a fixed font, in which each character is displayed
- * within a frame which is 11 pixels high (including 1 pixel for inter-line
- * spacing) and 8 pixels wide (including 2 pixels for inter-character spacing).
- * The resulting grid accommodates 23 rows (indexed 0..22, top to bottom)
- * of 64 characters each (indexed 0..63, left to right). The top left
- * character position on the screen is indexed (0,0). A cursor, implemented
- * as a small filled square, indicates where the next character will be displayed.
- */
-class Output {
-
- // Character map for displaying characters
- static Array charMaps;
- static int cursorI, cursorJ;
-
- /** Initializes the screen, and locates the cursor at the screen's top-left. */
- function void init() {
- do Output.initMap();
- do Output.moveCursor(0, 0);
- return;
- }
-
- // Initializes the character map array
- function void initMap() {
- var int i;
-
- let charMaps = Array.new(127);
-
- // Black square, used for displaying non-printable characters.
- do Output.create(0,63,63,63,63,63,63,63,63,63,0,0);
-
- // Assigns the bitmap for each character in the charachter set.
- // The first parameter is the character index, the next 11 numbers
- // are the values of each row in the frame that represents this character.
- do Output.create(32,0,0,0,0,0,0,0,0,0,0,0); //
- do Output.create(33,12,30,30,30,12,12,0,12,12,0,0); // !
- do Output.create(34,54,54,20,0,0,0,0,0,0,0,0); // "
- do Output.create(35,0,18,18,63,18,18,63,18,18,0,0); // #
- do Output.create(36,12,30,51,3,30,48,51,30,12,12,0); // $
- do Output.create(37,0,0,35,51,24,12,6,51,49,0,0); // %
- do Output.create(38,12,30,30,12,54,27,27,27,54,0,0); // &
- do Output.create(39,12,12,6,0,0,0,0,0,0,0,0); // '
- do Output.create(40,24,12,6,6,6,6,6,12,24,0,0); // (
- do Output.create(41,6,12,24,24,24,24,24,12,6,0,0); // )
- do Output.create(42,0,0,0,51,30,63,30,51,0,0,0); // *
- do Output.create(43,0,0,0,12,12,63,12,12,0,0,0); // +
- do Output.create(44,0,0,0,0,0,0,0,12,12,6,0); // ,
- do Output.create(45,0,0,0,0,0,63,0,0,0,0,0); // -
- do Output.create(46,0,0,0,0,0,0,0,12,12,0,0); // .
- do Output.create(47,0,0,32,48,24,12,6,3,1,0,0); // /
-
- do Output.create(48,12,30,51,51,51,51,51,30,12,0,0); // 0
- do Output.create(49,12,14,15,12,12,12,12,12,63,0,0); // 1
- do Output.create(50,30,51,48,24,12,6,3,51,63,0,0); // 2
- do Output.create(51,30,51,48,48,28,48,48,51,30,0,0); // 3
- do Output.create(52,16,24,28,26,25,63,24,24,60,0,0); // 4
- do Output.create(53,63,3,3,31,48,48,48,51,30,0,0); // 5
- do Output.create(54,28,6,3,3,31,51,51,51,30,0,0); // 6
- do Output.create(55,63,49,48,48,24,12,12,12,12,0,0); // 7
- do Output.create(56,30,51,51,51,30,51,51,51,30,0,0); // 8
- do Output.create(57,30,51,51,51,62,48,48,24,14,0,0); // 9
-
- do Output.create(58,0,0,12,12,0,0,12,12,0,0,0); // :
- do Output.create(59,0,0,12,12,0,0,12,12,6,0,0); // ;
- do Output.create(60,0,0,24,12,6,3,6,12,24,0,0); // <
- do Output.create(61,0,0,0,63,0,0,63,0,0,0,0); // =
- do Output.create(62,0,0,3,6,12,24,12,6,3,0,0); // >
- do Output.create(64,30,51,51,59,59,59,27,3,30,0,0); // @
- do Output.create(63,30,51,51,24,12,12,0,12,12,0,0); // ?
-
- do Output.create(65,12,12,30,30,51,51,63,51,51,0,0); // A
- do Output.create(66,31,51,51,51,31,51,51,51,31,0,0); // B
- do Output.create(67,28,54,35,3,3,3,35,54,28,0,0); // C
- do Output.create(68,15,27,51,51,51,51,51,27,15,0,0); // D
- do Output.create(69,63,51,35,11,15,11,35,51,63,0,0); // E
- do Output.create(70,63,51,35,11,15,11,3,3,3,0,0); // F
- do Output.create(71,28,54,35,3,59,51,51,54,44,0,0); // G
- do Output.create(72,51,51,51,51,63,51,51,51,51,0,0); // H
- do Output.create(73,30,12,12,12,12,12,12,12,30,0,0); // I
- do Output.create(74,60,24,24,24,24,24,27,27,14,0,0); // J
- do Output.create(75,51,51,51,27,15,27,51,51,51,0,0); // K
- do Output.create(76,3,3,3,3,3,3,35,51,63,0,0); // L
- do Output.create(77,33,51,63,63,51,51,51,51,51,0,0); // M
- do Output.create(78,51,51,55,55,63,59,59,51,51,0,0); // N
- do Output.create(79,30,51,51,51,51,51,51,51,30,0,0); // O
- do Output.create(80,31,51,51,51,31,3,3,3,3,0,0); // P
- do Output.create(81,30,51,51,51,51,51,63,59,30,48,0);// Q
- do Output.create(82,31,51,51,51,31,27,51,51,51,0,0); // R
- do Output.create(83,30,51,51,6,28,48,51,51,30,0,0); // S
- do Output.create(84,63,63,45,12,12,12,12,12,30,0,0); // T
- do Output.create(85,51,51,51,51,51,51,51,51,30,0,0); // U
- do Output.create(86,51,51,51,51,51,30,30,12,12,0,0); // V
- do Output.create(87,51,51,51,51,51,63,63,63,18,0,0); // W
- do Output.create(88,51,51,30,30,12,30,30,51,51,0,0); // X
- do Output.create(89,51,51,51,51,30,12,12,12,30,0,0); // Y
- do Output.create(90,63,51,49,24,12,6,35,51,63,0,0); // Z
-
- do Output.create(91,30,6,6,6,6,6,6,6,30,0,0); // [
- do Output.create(92,0,0,1,3,6,12,24,48,32,0,0); // \
- do Output.create(93,30,24,24,24,24,24,24,24,30,0,0); // ]
- do Output.create(94,8,28,54,0,0,0,0,0,0,0,0); // ^
- do Output.create(95,0,0,0,0,0,0,0,0,0,63,0); // _
- do Output.create(96,6,12,24,0,0,0,0,0,0,0,0); // `
-
- do Output.create(97,0,0,0,14,24,30,27,27,54,0,0); // a
- do Output.create(98,3,3,3,15,27,51,51,51,30,0,0); // b
- do Output.create(99,0,0,0,30,51,3,3,51,30,0,0); // c
- do Output.create(100,48,48,48,60,54,51,51,51,30,0,0); // d
- do Output.create(101,0,0,0,30,51,63,3,51,30,0,0); // e
- do Output.create(102,28,54,38,6,15,6,6,6,15,0,0); // f
- do Output.create(103,0,0,30,51,51,51,62,48,51,30,0); // g
- do Output.create(104,3,3,3,27,55,51,51,51,51,0,0); // h
- do Output.create(105,12,12,0,14,12,12,12,12,30,0,0); // i
- do Output.create(106,48,48,0,56,48,48,48,48,51,30,0); // j
- do Output.create(107,3,3,3,51,27,15,15,27,51,0,0); // k
- do Output.create(108,14,12,12,12,12,12,12,12,30,0,0); // l
- do Output.create(109,0,0,0,29,63,43,43,43,43,0,0); // m
- do Output.create(110,0,0,0,29,51,51,51,51,51,0,0); // n
- do Output.create(111,0,0,0,30,51,51,51,51,30,0,0); // o
- do Output.create(112,0,0,0,30,51,51,51,31,3,3,0); // p
- do Output.create(113,0,0,0,30,51,51,51,62,48,48,0); // q
- do Output.create(114,0,0,0,29,55,51,3,3,7,0,0); // r
- do Output.create(115,0,0,0,30,51,6,24,51,30,0,0); // s
- do Output.create(116,4,6,6,15,6,6,6,54,28,0,0); // t
- do Output.create(117,0,0,0,27,27,27,27,27,54,0,0); // u
- do Output.create(118,0,0,0,51,51,51,51,30,12,0,0); // v
- do Output.create(119,0,0,0,51,51,51,63,63,18,0,0); // w
- do Output.create(120,0,0,0,51,30,12,12,30,51,0,0); // x
- do Output.create(121,0,0,0,51,51,51,62,48,24,15,0); // y
- do Output.create(122,0,0,0,63,27,12,6,51,63,0,0); // z
-
- do Output.create(123,56,12,12,12,7,12,12,12,56,0,0); // {
- do Output.create(124,12,12,12,12,12,12,12,12,12,0,0); // |
- do Output.create(125,7,12,12,12,56,12,12,12,7,0,0); // }
- do Output.create(126,38,45,25,0,0,0,0,0,0,0,0); // ~
-
- return;
- }
-
- // Creates the character map array of the given character index, using the given values.
- function void create(int index, int a, int b, int c, int d, int e,
- int f, int g, int h, int i, int j, int k) {
- var Array map;
-
- let map = Array.new(11);
- let charMaps[index] = map;
-
- let map[0] = a;
- let map[1] = b;
- let map[2] = c;
- let map[3] = d;
- let map[4] = e;
- let map[5] = f;
- let map[6] = g;
- let map[7] = h;
- let map[8] = i;
- let map[9] = j;
- let map[10] = k;
-
- return;
- }
-
- // Returns the character map (array of size 11) of the given character.
- // If the given character is invalid or non-printable, returns the
- // character map of a black square.
- function Array getMap(char c) {
- if ((c < 32) | (c > 126)) {
- let c = 0;
- }
- return charMaps[c];
- }
-
- /** Moves the cursor to the j-th column of the i-th row,
- * and erases the character displayed there. */
- function void moveCursor(int i, int j) {
- var int x, y;
- let x = cursorJ * 8;
- let y = cursorI * 11;
- do Screen.setColor(false);
- do Screen.drawRectangle(x, y, x + 7, y + 10);
- let x = j * 8;
- let y = i * 11;
- do Screen.setColor(true);
- do Screen.drawRectangle(x, y, x + 7, y + 10);
- let cursorI = i;
- let cursorJ = j;
- return;
- }
-
- /** Displays the given character at the cursor location,
- * and advances the cursor one column forward. */
- function void printChar(char c) {
- var int k, x, y, addr;
- var Array cm;
- if (c = 129) {
- do Output.backSpace();
- return;
- }
- if (cursorI = 22) {
- if (c = 128) {
- return;
- }
- if (cursorJ = 63) {
- return;
- }
- }
- if (c = 128) {
- do Output.println();
- return;
- }
- let k = 0;
- let x = cursorJ / 2;
- let y = cursorJ - (x * 2); // y = 0: lsb, y = 1: msb
- let addr = cursorI * 352 + x + 16384;
- let cm = Output.getMap(c);
- if (cursorJ = 63) {
- do Output.moveCursor(cursorI + 1, 0);
- } else {
- do Output.moveCursor(cursorI, cursorJ + 1);
- }
- while (k < 11) {
- if (y = 0){
- do Memory.poke(addr, Memory.peek(addr) & (-128) + cm[k]);
- } else {
- do Memory.poke(addr, Memory.peek(addr) & 255 + (cm[k] * 256));
- }
- let k = k + 1;
- let addr = addr + 32;
- }
- return;
- }
-
- /** displays the given string starting at the cursor location,
- * and advances the cursor appropriately. */
- function void printString(String s) {
- var int i;
- var int n;
- let i = 0;
- let n = s.length();
- while (i < n) {
- do Output.printChar(s.charAt(i));
- let i = i + 1;
- }
- return;
- }
-
- /** Displays the given integer starting at the cursor location,
- * and advances the cursor appropriately. */
- function void printInt(int i) {
- var String s;
- let s = String.new(6);
- do s.setInt(i);
- do Output.printString(s);
- return;
- }
-
- /** Advances the cursor to the beginning of the next line. */
- function void println() {
- if (cursorI < 22) {
- do Output.moveCursor(cursorI + 1, 0);
- }
- return;
- }
-
- /** Moves the cursor one column back. */
- function void backSpace() {
- if (cursorJ > 0) {
- do Output.moveCursor(cursorI, cursorJ - 1);
- } else {
- do Output.moveCursor(cursorI - 1, 63);
- }
- return;
- }
-}
diff --git a/projects/12/OutputTest/Main.jack b/projects/12/OutputTest/Main.jack deleted file mode 100644 index f243068..0000000 --- a/projects/12/OutputTest/Main.jack +++ /dev/null @@ -1,42 +0,0 @@ -// 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/OutputTest/Main.jack
-
-/** Test program for the OS Output class. */
-class Main {
-
- /** Outputs the entire character set to the screen using all the
- * methods of the Output class. */
- function void main() {
- var String s;
-
- let s = String.new(1);
- do s.appendChar(String.doubleQuote());
-
- do Output.moveCursor(0, 63);
- do Output.printChar(66);
- do Output.moveCursor(22, 0);
- do Output.printChar(67);
- do Output.moveCursor(22, 63);
- do Output.printChar(68);
- do Output.printChar(65);
-
- do Output.moveCursor(2, 0);
- do Output.printString("0123456789");
- do Output.println();
-
- do Output.printString("ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz");
- do Output.println();
-
- do Output.printString("!#$%&'()*+,-./:;<=>?@[\]^_`{|}~");
- do Output.printString(s);
- do Output.println();
-
- do Output.printInt(-12345);
- do Output.backSpace();
- do Output.printInt(6789);
-
- return;
- }
-}
diff --git a/projects/12/OutputTest/Main.vm b/projects/12/OutputTest/Main.vm deleted file mode 100644 index 0a4c951..0000000 --- a/projects/12/OutputTest/Main.vm +++ /dev/null @@ -1,254 +0,0 @@ -function Main.main 1 -push constant 1 -call String.new 1 -pop local 0 -push local 0 -call String.doubleQuote 0 -call String.appendChar 2 -pop temp 0 -push constant 0 -push constant 63 -call Output.moveCursor 2 -pop temp 0 -push constant 66 -call Output.printChar 1 -pop temp 0 -push constant 22 -push constant 0 -call Output.moveCursor 2 -pop temp 0 -push constant 67 -call Output.printChar 1 -pop temp 0 -push constant 22 -push constant 63 -call Output.moveCursor 2 -pop temp 0 -push constant 68 -call Output.printChar 1 -pop temp 0 -push constant 65 -call Output.printChar 1 -pop temp 0 -push constant 2 -push constant 0 -call Output.moveCursor 2 -pop temp 0 -push constant 10 -call String.new 1 -push constant 48 -call String.appendChar 2 -push constant 49 -call String.appendChar 2 -push constant 50 -call String.appendChar 2 -push constant 51 -call String.appendChar 2 -push constant 52 -call String.appendChar 2 -push constant 53 -call String.appendChar 2 -push constant 54 -call String.appendChar 2 -push constant 55 -call String.appendChar 2 -push constant 56 -call String.appendChar 2 -push constant 57 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 53 -call String.new 1 -push constant 65 -call String.appendChar 2 -push constant 66 -call String.appendChar 2 -push constant 67 -call String.appendChar 2 -push constant 68 -call String.appendChar 2 -push constant 69 -call String.appendChar 2 -push constant 70 -call String.appendChar 2 -push constant 71 -call String.appendChar 2 -push constant 72 -call String.appendChar 2 -push constant 73 -call String.appendChar 2 -push constant 74 -call String.appendChar 2 -push constant 75 -call String.appendChar 2 -push constant 76 -call String.appendChar 2 -push constant 77 -call String.appendChar 2 -push constant 78 -call String.appendChar 2 -push constant 79 -call String.appendChar 2 -push constant 80 -call String.appendChar 2 -push constant 81 -call String.appendChar 2 -push constant 82 -call String.appendChar 2 -push constant 83 -call String.appendChar 2 -push constant 84 -call String.appendChar 2 -push constant 85 -call String.appendChar 2 -push constant 86 -call String.appendChar 2 -push constant 87 -call String.appendChar 2 -push constant 88 -call String.appendChar 2 -push constant 89 -call String.appendChar 2 -push constant 90 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 98 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 102 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 106 -call String.appendChar 2 -push constant 107 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 109 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 113 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 118 -call String.appendChar 2 -push constant 119 -call String.appendChar 2 -push constant 120 -call String.appendChar 2 -push constant 121 -call String.appendChar 2 -push constant 122 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 30 -call String.new 1 -push constant 33 -call String.appendChar 2 -push constant 35 -call String.appendChar 2 -push constant 36 -call String.appendChar 2 -push constant 37 -call String.appendChar 2 -push constant 38 -call String.appendChar 2 -push constant 39 -call String.appendChar 2 -push constant 40 -call String.appendChar 2 -push constant 41 -call String.appendChar 2 -push constant 42 -call String.appendChar 2 -push constant 43 -call String.appendChar 2 -push constant 44 -call String.appendChar 2 -push constant 45 -call String.appendChar 2 -push constant 46 -call String.appendChar 2 -push constant 47 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 59 -call String.appendChar 2 -push constant 60 -call String.appendChar 2 -push constant 61 -call String.appendChar 2 -push constant 62 -call String.appendChar 2 -push constant 63 -call String.appendChar 2 -push constant 64 -call String.appendChar 2 -push constant 91 -call String.appendChar 2 -push constant 93 -call String.appendChar 2 -push constant 94 -call String.appendChar 2 -push constant 95 -call String.appendChar 2 -push constant 96 -call String.appendChar 2 -push constant 123 -call String.appendChar 2 -push constant 124 -call String.appendChar 2 -push constant 125 -call String.appendChar 2 -push constant 126 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push local 0 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 12345 -neg -call Output.printInt 1 -pop temp 0 -call Output.backSpace 0 -pop temp 0 -push constant 6789 -call Output.printInt 1 -pop temp 0 -push constant 0 -return diff --git a/projects/12/OutputTest/Output.jack b/projects/12/OutputTest/Output.jack deleted file mode 100644 index 61b24de..0000000 --- a/projects/12/OutputTest/Output.jack +++ /dev/null @@ -1,281 +0,0 @@ -// 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/Output.jack
-
-/**
- * A library of functions for writing text on the screen.
- * The Hack physical screen consists of 512 rows of 256 pixels each.
- * The library uses a fixed font, in which each character is displayed
- * within a frame which is 11 pixels high (including 1 pixel for inter-line
- * spacing) and 8 pixels wide (including 2 pixels for inter-character spacing).
- * The resulting grid accommodates 23 rows (indexed 0..22, top to bottom)
- * of 64 characters each (indexed 0..63, left to right). The top left
- * character position on the screen is indexed (0,0). A cursor, implemented
- * as a small filled square, indicates where the next character will be displayed.
- */
-class Output {
-
- // Character map for displaying characters
- static Array charMaps;
- static int cursorI, cursorJ;
-
- /** Initializes the screen, and locates the cursor at the screen's top-left. */
- function void init() {
- do Output.initMap();
- do Output.moveCursor(0, 0);
- return;
- }
-
- // Initializes the character map array
- function void initMap() {
- var int i;
-
- let charMaps = Array.new(127);
-
- // Black square, used for displaying non-printable characters.
- do Output.create(0,63,63,63,63,63,63,63,63,63,0,0);
-
- // Assigns the bitmap for each character in the charachter set.
- // The first parameter is the character index, the next 11 numbers
- // are the values of each row in the frame that represents this character.
- do Output.create(32,0,0,0,0,0,0,0,0,0,0,0); //
- do Output.create(33,12,30,30,30,12,12,0,12,12,0,0); // !
- do Output.create(34,54,54,20,0,0,0,0,0,0,0,0); // "
- do Output.create(35,0,18,18,63,18,18,63,18,18,0,0); // #
- do Output.create(36,12,30,51,3,30,48,51,30,12,12,0); // $
- do Output.create(37,0,0,35,51,24,12,6,51,49,0,0); // %
- do Output.create(38,12,30,30,12,54,27,27,27,54,0,0); // &
- do Output.create(39,12,12,6,0,0,0,0,0,0,0,0); // '
- do Output.create(40,24,12,6,6,6,6,6,12,24,0,0); // (
- do Output.create(41,6,12,24,24,24,24,24,12,6,0,0); // )
- do Output.create(42,0,0,0,51,30,63,30,51,0,0,0); // *
- do Output.create(43,0,0,0,12,12,63,12,12,0,0,0); // +
- do Output.create(44,0,0,0,0,0,0,0,12,12,6,0); // ,
- do Output.create(45,0,0,0,0,0,63,0,0,0,0,0); // -
- do Output.create(46,0,0,0,0,0,0,0,12,12,0,0); // .
- do Output.create(47,0,0,32,48,24,12,6,3,1,0,0); // /
-
- do Output.create(48,12,30,51,51,51,51,51,30,12,0,0); // 0
- do Output.create(49,12,14,15,12,12,12,12,12,63,0,0); // 1
- do Output.create(50,30,51,48,24,12,6,3,51,63,0,0); // 2
- do Output.create(51,30,51,48,48,28,48,48,51,30,0,0); // 3
- do Output.create(52,16,24,28,26,25,63,24,24,60,0,0); // 4
- do Output.create(53,63,3,3,31,48,48,48,51,30,0,0); // 5
- do Output.create(54,28,6,3,3,31,51,51,51,30,0,0); // 6
- do Output.create(55,63,49,48,48,24,12,12,12,12,0,0); // 7
- do Output.create(56,30,51,51,51,30,51,51,51,30,0,0); // 8
- do Output.create(57,30,51,51,51,62,48,48,24,14,0,0); // 9
-
- do Output.create(58,0,0,12,12,0,0,12,12,0,0,0); // :
- do Output.create(59,0,0,12,12,0,0,12,12,6,0,0); // ;
- do Output.create(60,0,0,24,12,6,3,6,12,24,0,0); // <
- do Output.create(61,0,0,0,63,0,0,63,0,0,0,0); // =
- do Output.create(62,0,0,3,6,12,24,12,6,3,0,0); // >
- do Output.create(64,30,51,51,59,59,59,27,3,30,0,0); // @
- do Output.create(63,30,51,51,24,12,12,0,12,12,0,0); // ?
-
- do Output.create(65,12,12,30,30,51,51,63,51,51,0,0); // A
- do Output.create(66,31,51,51,51,31,51,51,51,31,0,0); // B
- do Output.create(67,28,54,35,3,3,3,35,54,28,0,0); // C
- do Output.create(68,15,27,51,51,51,51,51,27,15,0,0); // D
- do Output.create(69,63,51,35,11,15,11,35,51,63,0,0); // E
- do Output.create(70,63,51,35,11,15,11,3,3,3,0,0); // F
- do Output.create(71,28,54,35,3,59,51,51,54,44,0,0); // G
- do Output.create(72,51,51,51,51,63,51,51,51,51,0,0); // H
- do Output.create(73,30,12,12,12,12,12,12,12,30,0,0); // I
- do Output.create(74,60,24,24,24,24,24,27,27,14,0,0); // J
- do Output.create(75,51,51,51,27,15,27,51,51,51,0,0); // K
- do Output.create(76,3,3,3,3,3,3,35,51,63,0,0); // L
- do Output.create(77,33,51,63,63,51,51,51,51,51,0,0); // M
- do Output.create(78,51,51,55,55,63,59,59,51,51,0,0); // N
- do Output.create(79,30,51,51,51,51,51,51,51,30,0,0); // O
- do Output.create(80,31,51,51,51,31,3,3,3,3,0,0); // P
- do Output.create(81,30,51,51,51,51,51,63,59,30,48,0);// Q
- do Output.create(82,31,51,51,51,31,27,51,51,51,0,0); // R
- do Output.create(83,30,51,51,6,28,48,51,51,30,0,0); // S
- do Output.create(84,63,63,45,12,12,12,12,12,30,0,0); // T
- do Output.create(85,51,51,51,51,51,51,51,51,30,0,0); // U
- do Output.create(86,51,51,51,51,51,30,30,12,12,0,0); // V
- do Output.create(87,51,51,51,51,51,63,63,63,18,0,0); // W
- do Output.create(88,51,51,30,30,12,30,30,51,51,0,0); // X
- do Output.create(89,51,51,51,51,30,12,12,12,30,0,0); // Y
- do Output.create(90,63,51,49,24,12,6,35,51,63,0,0); // Z
-
- do Output.create(91,30,6,6,6,6,6,6,6,30,0,0); // [
- do Output.create(92,0,0,1,3,6,12,24,48,32,0,0); // \
- do Output.create(93,30,24,24,24,24,24,24,24,30,0,0); // ]
- do Output.create(94,8,28,54,0,0,0,0,0,0,0,0); // ^
- do Output.create(95,0,0,0,0,0,0,0,0,0,63,0); // _
- do Output.create(96,6,12,24,0,0,0,0,0,0,0,0); // `
-
- do Output.create(97,0,0,0,14,24,30,27,27,54,0,0); // a
- do Output.create(98,3,3,3,15,27,51,51,51,30,0,0); // b
- do Output.create(99,0,0,0,30,51,3,3,51,30,0,0); // c
- do Output.create(100,48,48,48,60,54,51,51,51,30,0,0); // d
- do Output.create(101,0,0,0,30,51,63,3,51,30,0,0); // e
- do Output.create(102,28,54,38,6,15,6,6,6,15,0,0); // f
- do Output.create(103,0,0,30,51,51,51,62,48,51,30,0); // g
- do Output.create(104,3,3,3,27,55,51,51,51,51,0,0); // h
- do Output.create(105,12,12,0,14,12,12,12,12,30,0,0); // i
- do Output.create(106,48,48,0,56,48,48,48,48,51,30,0); // j
- do Output.create(107,3,3,3,51,27,15,15,27,51,0,0); // k
- do Output.create(108,14,12,12,12,12,12,12,12,30,0,0); // l
- do Output.create(109,0,0,0,29,63,43,43,43,43,0,0); // m
- do Output.create(110,0,0,0,29,51,51,51,51,51,0,0); // n
- do Output.create(111,0,0,0,30,51,51,51,51,30,0,0); // o
- do Output.create(112,0,0,0,30,51,51,51,31,3,3,0); // p
- do Output.create(113,0,0,0,30,51,51,51,62,48,48,0); // q
- do Output.create(114,0,0,0,29,55,51,3,3,7,0,0); // r
- do Output.create(115,0,0,0,30,51,6,24,51,30,0,0); // s
- do Output.create(116,4,6,6,15,6,6,6,54,28,0,0); // t
- do Output.create(117,0,0,0,27,27,27,27,27,54,0,0); // u
- do Output.create(118,0,0,0,51,51,51,51,30,12,0,0); // v
- do Output.create(119,0,0,0,51,51,51,63,63,18,0,0); // w
- do Output.create(120,0,0,0,51,30,12,12,30,51,0,0); // x
- do Output.create(121,0,0,0,51,51,51,62,48,24,15,0); // y
- do Output.create(122,0,0,0,63,27,12,6,51,63,0,0); // z
-
- do Output.create(123,56,12,12,12,7,12,12,12,56,0,0); // {
- do Output.create(124,12,12,12,12,12,12,12,12,12,0,0); // |
- do Output.create(125,7,12,12,12,56,12,12,12,7,0,0); // }
- do Output.create(126,38,45,25,0,0,0,0,0,0,0,0); // ~
-
- return;
- }
-
- // Creates the character map array of the given character index, using the given values.
- function void create(int index, int a, int b, int c, int d, int e,
- int f, int g, int h, int i, int j, int k) {
- var Array map;
-
- let map = Array.new(11);
- let charMaps[index] = map;
-
- let map[0] = a;
- let map[1] = b;
- let map[2] = c;
- let map[3] = d;
- let map[4] = e;
- let map[5] = f;
- let map[6] = g;
- let map[7] = h;
- let map[8] = i;
- let map[9] = j;
- let map[10] = k;
-
- return;
- }
-
- // Returns the character map (array of size 11) of the given character.
- // If the given character is invalid or non-printable, returns the
- // character map of a black square.
- function Array getMap(char c) {
- if ((c < 32) | (c > 126)) {
- let c = 0;
- }
- return charMaps[c];
- }
-
- /** Moves the cursor to the j-th column of the i-th row,
- * and erases the character displayed there. */
- function void moveCursor(int i, int j) {
- var int x, y;
- let x = cursorJ * 8;
- let y = cursorI * 11;
- do Screen.setColor(false);
- do Screen.drawRectangle(x, y, x + 7, y + 10);
- let x = j * 8;
- let y = i * 11;
- do Screen.setColor(true);
- do Screen.drawRectangle(x, y, x + 7, y + 10);
- let cursorI = i;
- let cursorJ = j;
- return;
- }
-
- /** Displays the given character at the cursor location,
- * and advances the cursor one column forward. */
- function void printChar(char c) {
- var int k, x, y, addr;
- var Array cm;
- if (c = 129) {
- do Output.backSpace();
- return;
- }
- if (cursorI = 22) {
- if (c = 128) {
- return;
- }
- if (cursorJ = 63) {
- return;
- }
- }
- if (c = 128) {
- do Output.println();
- return;
- }
- let k = 0;
- let x = cursorJ / 2;
- let y = cursorJ - (x * 2); // y = 0: lsb, y = 1: msb
- let addr = cursorI * 352 + x + 16384;
- let cm = Output.getMap(c);
- if (cursorJ = 63) {
- do Output.moveCursor(cursorI + 1, 0);
- } else {
- do Output.moveCursor(cursorI, cursorJ + 1);
- }
- while (k < 11) {
- if (y = 0){
- do Memory.poke(addr, Memory.peek(addr) & (-128) + cm[k]);
- } else {
- do Memory.poke(addr, Memory.peek(addr) & 255 + (cm[k] * 256));
- }
- let k = k + 1;
- let addr = addr + 32;
- }
- return;
- }
-
- /** displays the given string starting at the cursor location,
- * and advances the cursor appropriately. */
- function void printString(String s) {
- var int i;
- var int n;
- let i = 0;
- let n = s.length();
- while (i < n) {
- do Output.printChar(s.charAt(i));
- let i = i + 1;
- }
- return;
- }
-
- /** Displays the given integer starting at the cursor location,
- * and advances the cursor appropriately. */
- function void printInt(int i) {
- var String s;
- let s = String.new(6);
- do s.setInt(i);
- do Output.printString(s);
- return;
- }
-
- /** Advances the cursor to the beginning of the next line. */
- function void println() {
- if (cursorI < 22) {
- do Output.moveCursor(cursorI + 1, 0);
- }
- return;
- }
-
- /** Moves the cursor one column back. */
- function void backSpace() {
- if (cursorJ > 0) {
- do Output.moveCursor(cursorI, cursorJ - 1);
- } else {
- do Output.moveCursor(cursorI - 1, 63);
- }
- return;
- }
-}
diff --git a/projects/12/OutputTest/Output.vm b/projects/12/OutputTest/Output.vm deleted file mode 100644 index dd83b63..0000000 --- a/projects/12/OutputTest/Output.vm +++ /dev/null @@ -1,1757 +0,0 @@ -function Output.init 0 -call Output.initMap 0 -pop temp 0 -push constant 0 -push constant 0 -call Output.moveCursor 2 -pop temp 0 -push constant 0 -return -function Output.initMap 1 -push constant 127 -call Array.new 1 -pop static 0 -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 12 -push constant 30 -push constant 30 -push constant 51 -push constant 51 -push constant 63 -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 0 -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.getMap 0 -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 argument 0 -push static 0 -add -pop pointer 1 -push that 0 -return -function Output.moveCursor 2 -push static 2 -push constant 8 -call Math.multiply 2 -pop local 0 -push static 1 -push constant 11 -call Math.multiply 2 -pop local 1 -push constant 0 -call Screen.setColor 1 -pop temp 0 -push local 0 -push local 1 -push local 0 -push constant 7 -add -push local 1 -push constant 10 -add -call Screen.drawRectangle 4 -pop temp 0 -push argument 1 -push constant 8 -call Math.multiply 2 -pop local 0 -push argument 0 -push constant 11 -call Math.multiply 2 -pop local 1 -push constant 0 -not -call Screen.setColor 1 -pop temp 0 -push local 0 -push local 1 -push local 0 -push constant 7 -add -push local 1 -push constant 10 -add -call Screen.drawRectangle 4 -pop temp 0 -push argument 0 -pop static 1 -push argument 1 -pop static 2 -push constant 0 -return -function Output.printChar 5 -push argument 0 -push constant 129 -eq -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -call Output.backSpace 0 -pop temp 0 -push constant 0 -return -label IF_FALSE0 -push static 1 -push constant 22 -eq -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push argument 0 -push constant 128 -eq -if-goto IF_TRUE2 -goto IF_FALSE2 -label IF_TRUE2 -push constant 0 -return -label IF_FALSE2 -push static 2 -push constant 63 -eq -if-goto IF_TRUE3 -goto IF_FALSE3 -label IF_TRUE3 -push constant 0 -return -label IF_FALSE3 -label IF_FALSE1 -push argument 0 -push constant 128 -eq -if-goto IF_TRUE4 -goto IF_FALSE4 -label IF_TRUE4 -call Output.println 0 -pop temp 0 -push constant 0 -return -label IF_FALSE4 -push constant 0 -pop local 0 -push static 2 -push constant 2 -call Math.divide 2 -pop local 1 -push static 2 -push local 1 -push constant 2 -call Math.multiply 2 -sub -pop local 2 -push static 1 -push constant 352 -call Math.multiply 2 -push local 1 -add -push constant 16384 -add -pop local 3 -push argument 0 -call Output.getMap 1 -pop local 4 -push static 2 -push constant 63 -eq -if-goto IF_TRUE5 -goto IF_FALSE5 -label IF_TRUE5 -push static 1 -push constant 1 -add -push constant 0 -call Output.moveCursor 2 -pop temp 0 -goto IF_END5 -label IF_FALSE5 -push static 1 -push static 2 -push constant 1 -add -call Output.moveCursor 2 -pop temp 0 -label IF_END5 -label WHILE_EXP0 -push local 0 -push constant 11 -lt -not -if-goto WHILE_END0 -push local 2 -push constant 0 -eq -if-goto IF_TRUE6 -goto IF_FALSE6 -label IF_TRUE6 -push local 3 -push local 3 -call Memory.peek 1 -push constant 128 -neg -and -push local 0 -push local 4 -add -pop pointer 1 -push that 0 -add -call Memory.poke 2 -pop temp 0 -goto IF_END6 -label IF_FALSE6 -push local 3 -push local 3 -call Memory.peek 1 -push constant 255 -and -push local 0 -push local 4 -add -pop pointer 1 -push that 0 -push constant 256 -call Math.multiply 2 -add -call Memory.poke 2 -pop temp 0 -label IF_END6 -push local 0 -push constant 1 -add -pop local 0 -push local 3 -push constant 32 -add -pop local 3 -goto WHILE_EXP0 -label WHILE_END0 -push constant 0 -return -function Output.printString 2 -push constant 0 -pop local 0 -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 1 -push constant 6 -call String.new 1 -pop local 0 -push local 0 -push argument 0 -call String.setInt 2 -pop temp 0 -push local 0 -call Output.printString 1 -pop temp 0 -push constant 0 -return -function Output.println 0 -push static 1 -push constant 22 -lt -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push static 1 -push constant 1 -add -push constant 0 -call Output.moveCursor 2 -pop temp 0 -label IF_FALSE0 -push constant 0 -return -function Output.backSpace 0 -push static 2 -push constant 0 -gt -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push static 1 -push static 2 -push constant 1 -sub -call Output.moveCursor 2 -pop temp 0 -goto IF_END0 -label IF_FALSE0 -push static 1 -push constant 1 -sub -push constant 63 -call Output.moveCursor 2 -pop temp 0 -label IF_END0 -push constant 0 -return diff --git a/projects/12/OutputTest/OutputTestOutput.gif b/projects/12/OutputTest/OutputTestOutput.gif Binary files differdeleted file mode 100644 index b8ec2c0..0000000 --- a/projects/12/OutputTest/OutputTestOutput.gif +++ /dev/null diff --git a/projects/12/Screen.jack b/projects/12/Screen.jack deleted file mode 100644 index a370ab9..0000000 --- a/projects/12/Screen.jack +++ /dev/null @@ -1,138 +0,0 @@ -// 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/Screen.jack
-
-/**
- * A library of functions for displaying graphics on the screen.
- * The Hack physical screen consists of 512 rows (indexed 0..511, top to bottom)
- * of 256 pixels each (indexed 0..255, left to right). The top left pixel on
- * the screen is indexed (0,0).
- */
-class Screen {
- static Array twoToThe;
- static Array screen;
- static boolean color;
-
- /** Initializes the Screen. */
- function void init() {
- var int i, x;
- let x = 1;
- let i = 0;
- let twoToThe = Array.new(16);
- while (i < 16){
- let twoToThe[i] = x;
- let x = x + x;
- let i = i + 1;
- }
- let screen = 16384;
- let color = true;
- return;
- }
-
- /** Erases the entire screen. */
- function void clearScreen() {
- var boolean c;
- let c = color;
- let color = false;
- do Screen.drawRectangle(0, 0, 511, 255);
- let color = c;
- return;
- }
-
- /** Sets the current color, to be used for all subsequent drawXXX commands.
- * Black is represented by true, white by false. */
- function void setColor(boolean b) {
- let color = b;
- return;
- }
-
- /** Draws the (x,y) pixel, using the current color. */
- function void drawPixel(int x, int y) {
- var int addr, t;
- if ((x < 0) | (y < 0) | (x > 511) | (y > 255)) {
- //String.println("drawPixel: coordinates out of range!");
- //Sys.error(2);
- return;
- }
- let t = x / 16;
- let addr = 32 * y + t;
- if (color) {
- let screen[addr] = screen[addr] | twoToThe[x - (t * 16)];
- } else {
- let screen[addr] = screen[addr] & (- (twoToThe[x - (t * 16)] + 1));
- }
- return;
- }
-
- /** Draws a line from pixel (x1,y1) to pixel (x2,y2), using the current color. */
- function void drawLine(int x1, int y1, int x2, int y2) {
- var int dx, dy, x, y, a, b, diff;
- let x = x1;
- let y = y1;
- do Screen.drawPixel(x, y);
- if (x1 = x2) {
- if (y1 = y2) {
- return;
- } else {
- let diff = 1;
- }
- } else {
- if (y1 = y2) {
- let diff = -1;
- } else {
- let diff = 0;
- }
- }
- let dx = x2 - x1;
- let dy = y2 - y1;
- let a = Math.sign(dx);
- let b = Math.sign(dy);
- let dx = Math.abs(dx);
- let dy = Math.abs(dy);
- while (~((x = x2) & (y = y2))) {
- if (diff < 0){
- let x = x + a;
- let diff = diff + dy;
- } else {
- let y = y + b;
- let diff = diff - dx;
- }
- do Screen.drawPixel(x, y);
- }
- return;
- }
-
- /** Draws a filled rectangle whose top left corner is (x1, y1)
- * and bottom right corner is (x2,y2), using the current color. */
- function void drawRectangle(int x1, int y1, int x2, int y2) {
- var int x;
- if ((x1 > x2) | (y1 > y2)) {
- return;
- }
- let x = x1;
- while (~(x > x2)) {
- do Screen.drawLine(x, y1, x, y2);
- let x = x + 1;
- }
- return;
- }
-
- /** Draws a filled circle of radius r<=181 around (x,y), using the current color. */
- function void drawCircle(int x, int y, int r) {
- var int dx, dy, r2;
- if (r > 181) {
- do String.println("drawCircle: radius too big!");
- do Sys.error(2);
- return;
- }
- let dy = -r;
- let r2 = r * r;
- while (~(dy > r)) {
- let dx = Math.sqrt(r2 - (dy * dy));
- do Screen.drawLine(x - dx, y + dy, x + dx, y + dy);
- let dy = dy + 1;
- }
- return;
- }
-}
diff --git a/projects/12/ScreenTest/Main.jack b/projects/12/ScreenTest/Main.jack deleted file mode 100644 index 00f36bd..0000000 --- a/projects/12/ScreenTest/Main.jack +++ /dev/null @@ -1,36 +0,0 @@ -// 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/ScreenTest/Main.jack
-
-/** Test program for the OS Screen class. */
-class Main {
-
- /** Draws a sample pictue on the screen using lines and circles. */
- function void main() {
-
- do Screen.drawLine(0,220,511,220); // base line
- do Screen.drawRectangle(280,90,410,220); // house
-
- do Screen.setColor(false);
- do Screen.drawRectangle(350,120,390,219); // door
- do Screen.drawRectangle(292,120,332,150); // window
-
- do Screen.setColor(true);
- do Screen.drawCircle(360,170,3); // door handle
- do Screen.drawLine(280,90,345,35); // roof
- do Screen.drawLine(345,35,410,90); // roof
-
- do Screen.drawCircle(140,60,30); // sun
- do Screen.drawLine(140,26, 140, 6);
- do Screen.drawLine(163,35,178,20);
- do Screen.drawLine(174,60,194,60);
- do Screen.drawLine(163,85,178,100);
- do Screen.drawLine(140,94,140,114);
- do Screen.drawLine(117,85,102,100);
- do Screen.drawLine(106,60,86,60);
- do Screen.drawLine(117,35,102,20);
-
- return;
- }
-}
diff --git a/projects/12/ScreenTest/Main.vm b/projects/12/ScreenTest/Main.vm deleted file mode 100644 index 69e860f..0000000 --- a/projects/12/ScreenTest/Main.vm +++ /dev/null @@ -1,104 +0,0 @@ -function Main.main 0 -push constant 0 -push constant 220 -push constant 511 -push constant 220 -call Screen.drawLine 4 -pop temp 0 -push constant 280 -push constant 90 -push constant 410 -push constant 220 -call Screen.drawRectangle 4 -pop temp 0 -push constant 0 -call Screen.setColor 1 -pop temp 0 -push constant 350 -push constant 120 -push constant 390 -push constant 219 -call Screen.drawRectangle 4 -pop temp 0 -push constant 292 -push constant 120 -push constant 332 -push constant 150 -call Screen.drawRectangle 4 -pop temp 0 -push constant 0 -not -call Screen.setColor 1 -pop temp 0 -push constant 360 -push constant 170 -push constant 3 -call Screen.drawCircle 3 -pop temp 0 -push constant 280 -push constant 90 -push constant 345 -push constant 35 -call Screen.drawLine 4 -pop temp 0 -push constant 345 -push constant 35 -push constant 410 -push constant 90 -call Screen.drawLine 4 -pop temp 0 -push constant 140 -push constant 60 -push constant 30 -call Screen.drawCircle 3 -pop temp 0 -push constant 140 -push constant 26 -push constant 140 -push constant 6 -call Screen.drawLine 4 -pop temp 0 -push constant 163 -push constant 35 -push constant 178 -push constant 20 -call Screen.drawLine 4 -pop temp 0 -push constant 174 -push constant 60 -push constant 194 -push constant 60 -call Screen.drawLine 4 -pop temp 0 -push constant 163 -push constant 85 -push constant 178 -push constant 100 -call Screen.drawLine 4 -pop temp 0 -push constant 140 -push constant 94 -push constant 140 -push constant 114 -call Screen.drawLine 4 -pop temp 0 -push constant 117 -push constant 85 -push constant 102 -push constant 100 -call Screen.drawLine 4 -pop temp 0 -push constant 106 -push constant 60 -push constant 86 -push constant 60 -call Screen.drawLine 4 -pop temp 0 -push constant 117 -push constant 35 -push constant 102 -push constant 20 -call Screen.drawLine 4 -pop temp 0 -push constant 0 -return diff --git a/projects/12/ScreenTest/Math.jack b/projects/12/ScreenTest/Math.jack deleted file mode 100644 index 01bce8f..0000000 --- a/projects/12/ScreenTest/Math.jack +++ /dev/null @@ -1,158 +0,0 @@ -// 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.
- * Note: Jack compilers implement multiplication and division using OS method calls.
- */
-class Math {
- static Array twoToThe;
-
- /** Initializes the library. */
- function void init() {
- var int i, x;
- let x = 1;
- let i = 0;
- let twoToThe = Array.new(16);
- while (i < 16){
- let twoToThe[i] = x;
- let x = x + x;
- let i = i + 1;
- }
- return;
- }
-
- function boolean bit(int x, int i) {
- return ~(x & twoToThe[i] = 0);
- }
-
- function int sign(int x) {
- if (x > 0) {
- return 1;
- } else {
- if (x < 0) {
- return -1;
- } else {
- return 0;
- }
- }
- }
-
- /** Returns the absolute value of x. */
- function int abs(int x) {
- if (x > 0){
- return x;
- } else {
- return -x;
- }
- }
-
- /** Returns the product of x and y.
- * When a Jack compiler detects the multiplication operator '*' in the
- * program's code, it handles it by invoking this method. In other words,
- * the Jack expressions x*y and multiply(x,y) return the same value.
- */
- function int multiply(int x, int y) {
- var int res, shiftedX, i;
- let shiftedX = x;
- let i = 0;
- let res = 0;
- //while ((~(twoToThe[i] > y)) & (i < 16)) {
- while (i < 16) {
- if (Math.bit(y, i)){
- let res = res + shiftedX;
- }
- let shiftedX = shiftedX + shiftedX;
- let i = i + 1;
- }
- return res;
- }
-
- /** Returns the integer part of x/y.
- * When a Jack compiler detects the multiplication operator '/' in the
- * program's code, it handles it by invoking this method. In other words,
- * the Jack expressions x/y and divide(x,y) return the same value.
- */
- function int divide(int x, int y) {
- var int ax, ay;
- if (x > 0) {
- if (y > 0) {
- return Math.divide1(x, y);
- } else {
- return -Math.divide1(x, -y);
- }
- } else {
- if (y > 0) {
- return -Math.divide1(-x, y);
- } else {
- return Math.divide1(-x, -y);
- }
- }
- }
-
- function int divide1(int x, int y) {
- var int q;
- if (y = 0) {
- do Output.printString("Error: division by zero.");
- do Sys.error(0);
- }
- if ((y > x) | (y < 0)) {
- return 0;
- }
- let q = Math.divide1(x, y * 2);
- if (x - (2 * q * y) < y) {
- return 2 * q;
- } else {
- return 2 * q + 1;
- }
- }
-
- function int length(int x){
- var int n;
- let n = 14;
- while (twoToThe[n] > x){
- let n = n - 1;
- }
- return n;
- }
-
- /** Returns the integer part of the square root of x. */
- function int sqrt(int x) {
- var int y, k, z, w;
- if (x < 0) {
- do Output.printString("Error: square rooting a negative number.");
- do Sys.error(0);
- }
- let k = Math.length(x) / 2;
- let y = 0;
- while (~(k < 0)) {
- let z = y + twoToThe[k];
- let w = z * z;
- if ((~(w > x)) & (w > 0)) {
- let y = z;
- }
- let k = k - 1;
- }
- return y;
- }
-
- /** Returns the greater number. */
- function int max(int a, int b) {
- if (a > b) {
- return a;
- } else {
- return b;
- }
- }
-
- /** Returns the smaller number. */
- function int min(int a, int b) {
- if (a < b) {
- return a;
- } else {
- return b;
- }
- }
-}
diff --git a/projects/12/ScreenTest/Math.vm b/projects/12/ScreenTest/Math.vm deleted file mode 100644 index 513fc1a..0000000 --- a/projects/12/ScreenTest/Math.vm +++ /dev/null @@ -1,472 +0,0 @@ -function Math.init 2 -push constant 1 -pop local 1 -push constant 0 -pop local 0 -push constant 16 -call Array.new 1 -pop static 0 -label WHILE_EXP0 -push local 0 -push constant 16 -lt -not -if-goto WHILE_END0 -push local 0 -push static 0 -add -push local 1 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push local 1 -push local 1 -add -pop local 1 -push local 0 -push constant 1 -add -pop local 0 -goto WHILE_EXP0 -label WHILE_END0 -push constant 0 -return -function Math.bit 0 -push argument 0 -push argument 1 -push static 0 -add -pop pointer 1 -push that 0 -and -push constant 0 -eq -not -return -function Math.sign 0 -push argument 0 -push constant 0 -gt -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 1 -return -goto IF_END0 -label IF_FALSE0 -push argument 0 -push constant 0 -lt -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push constant 1 -neg -return -goto IF_END1 -label IF_FALSE1 -push constant 0 -return -label IF_END1 -label IF_END0 -function Math.abs 0 -push argument 0 -push constant 0 -gt -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push argument 0 -return -goto IF_END0 -label IF_FALSE0 -push argument 0 -neg -return -label IF_END0 -function Math.multiply 3 -push argument 0 -pop local 1 -push constant 0 -pop local 2 -push constant 0 -pop local 0 -label WHILE_EXP0 -push local 2 -push constant 16 -lt -not -if-goto WHILE_END0 -push argument 1 -push local 2 -call Math.bit 2 -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push local 0 -push local 1 -add -pop local 0 -label IF_FALSE0 -push local 1 -push local 1 -add -pop local 1 -push local 2 -push constant 1 -add -pop local 2 -goto WHILE_EXP0 -label WHILE_END0 -push local 0 -return -function Math.divide 2 -push argument 0 -push constant 0 -gt -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push argument 1 -push constant 0 -gt -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push argument 0 -push argument 1 -call Math.divide1 2 -return -goto IF_END1 -label IF_FALSE1 -push argument 0 -push argument 1 -neg -call Math.divide1 2 -neg -return -label IF_END1 -goto IF_END0 -label IF_FALSE0 -push argument 1 -push constant 0 -gt -if-goto IF_TRUE2 -goto IF_FALSE2 -label IF_TRUE2 -push argument 0 -neg -push argument 1 -call Math.divide1 2 -neg -return -goto IF_END2 -label IF_FALSE2 -push argument 0 -neg -push argument 1 -neg -call Math.divide1 2 -return -label IF_END2 -label IF_END0 -function Math.divide1 1 -push argument 1 -push constant 0 -eq -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 24 -call String.new 1 -push constant 69 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 118 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 98 -call String.appendChar 2 -push constant 121 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 122 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 46 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push constant 0 -call Sys.error 1 -pop temp 0 -label IF_FALSE0 -push argument 1 -push argument 0 -gt -push argument 1 -push constant 0 -lt -or -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push constant 0 -return -label IF_FALSE1 -push argument 0 -push argument 1 -push constant 2 -call Math.multiply 2 -call Math.divide1 2 -pop local 0 -push argument 0 -push constant 2 -push local 0 -call Math.multiply 2 -push argument 1 -call Math.multiply 2 -sub -push argument 1 -lt -if-goto IF_TRUE2 -goto IF_FALSE2 -label IF_TRUE2 -push constant 2 -push local 0 -call Math.multiply 2 -return -goto IF_END2 -label IF_FALSE2 -push constant 2 -push local 0 -call Math.multiply 2 -push constant 1 -add -return -label IF_END2 -function Math.length 1 -push constant 14 -pop local 0 -label WHILE_EXP0 -push local 0 -push static 0 -add -pop pointer 1 -push that 0 -push argument 0 -gt -not -if-goto WHILE_END0 -push local 0 -push constant 1 -sub -pop local 0 -goto WHILE_EXP0 -label WHILE_END0 -push local 0 -return -function Math.sqrt 4 -push argument 0 -push constant 0 -lt -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 40 -call String.new 1 -push constant 69 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 113 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 118 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 109 -call String.appendChar 2 -push constant 98 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 46 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push constant 0 -call Sys.error 1 -pop temp 0 -label IF_FALSE0 -push argument 0 -call Math.length 1 -push constant 2 -call Math.divide 2 -pop local 1 -push constant 0 -pop local 0 -label WHILE_EXP0 -push local 1 -push constant 0 -lt -not -not -if-goto WHILE_END0 -push local 0 -push local 1 -push static 0 -add -pop pointer 1 -push that 0 -add -pop local 2 -push local 2 -push local 2 -call Math.multiply 2 -pop local 3 -push local 3 -push argument 0 -gt -not -push local 3 -push constant 0 -gt -and -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push local 2 -pop local 0 -label IF_FALSE1 -push local 1 -push constant 1 -sub -pop local 1 -goto WHILE_EXP0 -label WHILE_END0 -push local 0 -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 -return -goto IF_END0 -label IF_FALSE0 -push argument 1 -return -label IF_END0 -function Math.min 0 -push argument 0 -push argument 1 -lt -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push argument 0 -return -goto IF_END0 -label IF_FALSE0 -push argument 1 -return -label IF_END0 diff --git a/projects/12/ScreenTest/Screen.jack b/projects/12/ScreenTest/Screen.jack deleted file mode 100644 index a370ab9..0000000 --- a/projects/12/ScreenTest/Screen.jack +++ /dev/null @@ -1,138 +0,0 @@ -// 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/Screen.jack
-
-/**
- * A library of functions for displaying graphics on the screen.
- * The Hack physical screen consists of 512 rows (indexed 0..511, top to bottom)
- * of 256 pixels each (indexed 0..255, left to right). The top left pixel on
- * the screen is indexed (0,0).
- */
-class Screen {
- static Array twoToThe;
- static Array screen;
- static boolean color;
-
- /** Initializes the Screen. */
- function void init() {
- var int i, x;
- let x = 1;
- let i = 0;
- let twoToThe = Array.new(16);
- while (i < 16){
- let twoToThe[i] = x;
- let x = x + x;
- let i = i + 1;
- }
- let screen = 16384;
- let color = true;
- return;
- }
-
- /** Erases the entire screen. */
- function void clearScreen() {
- var boolean c;
- let c = color;
- let color = false;
- do Screen.drawRectangle(0, 0, 511, 255);
- let color = c;
- return;
- }
-
- /** Sets the current color, to be used for all subsequent drawXXX commands.
- * Black is represented by true, white by false. */
- function void setColor(boolean b) {
- let color = b;
- return;
- }
-
- /** Draws the (x,y) pixel, using the current color. */
- function void drawPixel(int x, int y) {
- var int addr, t;
- if ((x < 0) | (y < 0) | (x > 511) | (y > 255)) {
- //String.println("drawPixel: coordinates out of range!");
- //Sys.error(2);
- return;
- }
- let t = x / 16;
- let addr = 32 * y + t;
- if (color) {
- let screen[addr] = screen[addr] | twoToThe[x - (t * 16)];
- } else {
- let screen[addr] = screen[addr] & (- (twoToThe[x - (t * 16)] + 1));
- }
- return;
- }
-
- /** Draws a line from pixel (x1,y1) to pixel (x2,y2), using the current color. */
- function void drawLine(int x1, int y1, int x2, int y2) {
- var int dx, dy, x, y, a, b, diff;
- let x = x1;
- let y = y1;
- do Screen.drawPixel(x, y);
- if (x1 = x2) {
- if (y1 = y2) {
- return;
- } else {
- let diff = 1;
- }
- } else {
- if (y1 = y2) {
- let diff = -1;
- } else {
- let diff = 0;
- }
- }
- let dx = x2 - x1;
- let dy = y2 - y1;
- let a = Math.sign(dx);
- let b = Math.sign(dy);
- let dx = Math.abs(dx);
- let dy = Math.abs(dy);
- while (~((x = x2) & (y = y2))) {
- if (diff < 0){
- let x = x + a;
- let diff = diff + dy;
- } else {
- let y = y + b;
- let diff = diff - dx;
- }
- do Screen.drawPixel(x, y);
- }
- return;
- }
-
- /** Draws a filled rectangle whose top left corner is (x1, y1)
- * and bottom right corner is (x2,y2), using the current color. */
- function void drawRectangle(int x1, int y1, int x2, int y2) {
- var int x;
- if ((x1 > x2) | (y1 > y2)) {
- return;
- }
- let x = x1;
- while (~(x > x2)) {
- do Screen.drawLine(x, y1, x, y2);
- let x = x + 1;
- }
- return;
- }
-
- /** Draws a filled circle of radius r<=181 around (x,y), using the current color. */
- function void drawCircle(int x, int y, int r) {
- var int dx, dy, r2;
- if (r > 181) {
- do String.println("drawCircle: radius too big!");
- do Sys.error(2);
- return;
- }
- let dy = -r;
- let r2 = r * r;
- while (~(dy > r)) {
- let dx = Math.sqrt(r2 - (dy * dy));
- do Screen.drawLine(x - dx, y + dy, x + dx, y + dy);
- let dy = dy + 1;
- }
- return;
- }
-}
diff --git a/projects/12/ScreenTest/Screen.vm b/projects/12/ScreenTest/Screen.vm deleted file mode 100644 index 8468225..0000000 --- a/projects/12/ScreenTest/Screen.vm +++ /dev/null @@ -1,407 +0,0 @@ -function Screen.init 2 -push constant 1 -pop local 1 -push constant 0 -pop local 0 -push constant 16 -call Array.new 1 -pop static 0 -label WHILE_EXP0 -push local 0 -push constant 16 -lt -not -if-goto WHILE_END0 -push local 0 -push static 0 -add -push local 1 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push local 1 -push local 1 -add -pop local 1 -push local 0 -push constant 1 -add -pop local 0 -goto WHILE_EXP0 -label WHILE_END0 -push constant 16384 -pop static 1 -push constant 0 -not -pop static 2 -push constant 0 -return -function Screen.clearScreen 1 -push static 2 -pop local 0 -push constant 0 -pop static 2 -push constant 0 -push constant 0 -push constant 511 -push constant 255 -call Screen.drawRectangle 4 -pop temp 0 -push local 0 -pop static 2 -push constant 0 -return -function Screen.setColor 0 -push argument 0 -pop static 2 -push constant 0 -return -function Screen.drawPixel 2 -push argument 0 -push constant 0 -lt -push argument 1 -push constant 0 -lt -or -push argument 0 -push constant 511 -gt -or -push argument 1 -push constant 255 -gt -or -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 0 -return -label IF_FALSE0 -push argument 0 -push constant 16 -call Math.divide 2 -pop local 1 -push constant 32 -push argument 1 -call Math.multiply 2 -push local 1 -add -pop local 0 -push static 2 -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push local 0 -push static 1 -add -push local 0 -push static 1 -add -pop pointer 1 -push that 0 -push argument 0 -push local 1 -push constant 16 -call Math.multiply 2 -sub -push static 0 -add -pop pointer 1 -push that 0 -or -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -goto IF_END1 -label IF_FALSE1 -push local 0 -push static 1 -add -push local 0 -push static 1 -add -pop pointer 1 -push that 0 -push argument 0 -push local 1 -push constant 16 -call Math.multiply 2 -sub -push static 0 -add -pop pointer 1 -push that 0 -push constant 1 -add -neg -and -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -label IF_END1 -push constant 0 -return -function Screen.drawLine 7 -push argument 0 -pop local 2 -push argument 1 -pop local 3 -push local 2 -push local 3 -call Screen.drawPixel 2 -pop temp 0 -push argument 0 -push argument 2 -eq -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push argument 1 -push argument 3 -eq -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push constant 0 -return -goto IF_END1 -label IF_FALSE1 -push constant 1 -pop local 6 -label IF_END1 -goto IF_END0 -label IF_FALSE0 -push argument 1 -push argument 3 -eq -if-goto IF_TRUE2 -goto IF_FALSE2 -label IF_TRUE2 -push constant 1 -neg -pop local 6 -goto IF_END2 -label IF_FALSE2 -push constant 0 -pop local 6 -label IF_END2 -label IF_END0 -push argument 2 -push argument 0 -sub -pop local 0 -push argument 3 -push argument 1 -sub -pop local 1 -push local 0 -call Math.sign 1 -pop local 4 -push local 1 -call Math.sign 1 -pop local 5 -push local 0 -call Math.abs 1 -pop local 0 -push local 1 -call Math.abs 1 -pop local 1 -label WHILE_EXP0 -push local 2 -push argument 2 -eq -push local 3 -push argument 3 -eq -and -not -not -if-goto WHILE_END0 -push local 6 -push constant 0 -lt -if-goto IF_TRUE3 -goto IF_FALSE3 -label IF_TRUE3 -push local 2 -push local 4 -add -pop local 2 -push local 6 -push local 1 -add -pop local 6 -goto IF_END3 -label IF_FALSE3 -push local 3 -push local 5 -add -pop local 3 -push local 6 -push local 0 -sub -pop local 6 -label IF_END3 -push local 2 -push local 3 -call Screen.drawPixel 2 -pop temp 0 -goto WHILE_EXP0 -label WHILE_END0 -push constant 0 -return -function Screen.drawRectangle 1 -push argument 0 -push argument 2 -gt -push argument 1 -push argument 3 -gt -or -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 0 -return -label IF_FALSE0 -push argument 0 -pop local 0 -label WHILE_EXP0 -push local 0 -push argument 2 -gt -not -not -if-goto WHILE_END0 -push local 0 -push argument 1 -push local 0 -push argument 3 -call Screen.drawLine 4 -pop temp 0 -push local 0 -push constant 1 -add -pop local 0 -goto WHILE_EXP0 -label WHILE_END0 -push constant 0 -return -function Screen.drawCircle 3 -push argument 2 -push constant 181 -gt -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 27 -call String.new 1 -push constant 100 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 119 -call String.appendChar 2 -push constant 67 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 98 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 33 -call String.appendChar 2 -call String.println 1 -pop temp 0 -push constant 2 -call Sys.error 1 -pop temp 0 -push constant 0 -return -label IF_FALSE0 -push argument 2 -neg -pop local 1 -push argument 2 -push argument 2 -call Math.multiply 2 -pop local 2 -label WHILE_EXP0 -push local 1 -push argument 2 -gt -not -not -if-goto WHILE_END0 -push local 2 -push local 1 -push local 1 -call Math.multiply 2 -sub -call Math.sqrt 1 -pop local 0 -push argument 0 -push local 0 -sub -push argument 1 -push local 1 -add -push argument 0 -push local 0 -add -push argument 1 -push local 1 -add -call Screen.drawLine 4 -pop temp 0 -push local 1 -push constant 1 -add -pop local 1 -goto WHILE_EXP0 -label WHILE_END0 -push constant 0 -return diff --git a/projects/12/ScreenTest/ScreenTestOutput.gif b/projects/12/ScreenTest/ScreenTestOutput.gif Binary files differdeleted file mode 100644 index f1742cc..0000000 --- a/projects/12/ScreenTest/ScreenTestOutput.gif +++ /dev/null diff --git a/projects/12/String.jack b/projects/12/String.jack deleted file mode 100644 index 3ef40b2..0000000 --- a/projects/12/String.jack +++ /dev/null @@ -1,176 +0,0 @@ -// 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/String.jack
-
-/**
- * Represents character strings. In addition for constructing and disposing
- * strings, the class features methods for getting and setting individual
- * characters of the string, for erasing the string's last character,
- * for appending a character to the string's end, and more typical
- * string-oriented operations.
- */
-class String {
- field int maxLen;
- field int len;
- field Array s;
-
- /** constructs a new empty string with a maximum length of maxLength
- * and initial length of 0. */
- constructor String new(int maxLength) {
- if (maxLength > 0) {
- let s = Array.new(maxLength);
- }
- let maxLen = maxLength;
- let len = 0;
- return this;
- }
-
- /** Disposes this string. */
- method void dispose() {
- if (maxLen > 0) {
- do s.dispose();
- }
- do Memory.deAlloc(this);
- return;
- }
-
- /** Returns the current length of this string. */
- method int length() {
- return len;
- }
-
- /** Returns the character at the j-th location of this string. */
- method char charAt(int j) {
- if ((j < 0) | (j + 1 > len)){
- do Output.printString("String.charAt: index out of range!");
- do Sys.error(5);
- }
- return s[j];
- }
-
- /** Sets the character at the j-th location of this string to c. */
- method void setCharAt(int j, char c) {
- if ((j < 0) | (j + 1 > len)){
- do Output.printString("String.setCharAt: index out of range!");
- do Sys.error(5);
- }
- let s[j] = c;
- return;
- }
-
- /** Appends c to this string's end and returns this string. */
- method String appendChar(char c) {
- if (len = maxLen) {
- do Output.printString("String.appendChar: reached max length!");
- do Sys.error(5);
- }
- let s[len] = c;
- let len = len + 1;
- return this;
- }
-
- /** Erases the last character from this string. */
- method void eraseLastChar() {
- if (len = 0){
- do Output.printString("String.eraseLastChar: string is already empty!");
- do Sys.error(5);
- }
- let len = len - 1;
- return;
- }
-
- /** Returns the integer value of this string,
- * until a non-digit character is detected. */
- method int intValue() {
- var int n, i;
- var char c;
- var boolean neg, done;
- let n = 0;
- if (s[0] = 45) {
- let i = 1;
- let neg = true;
- } else {
- let i = 0;
- let neg = false;
- }
- let c = s[i];
- if ((c < 48) | (c > 57)) {
- do Sys.error(3);
- do Output.printString("String.intValue: the input data is not number!");
- }
- let done = false;
- while ((~done) & (i < len)) {
- let c = s[i];
- if ((c > 47) & (c < 58)) {
- let n = n * 10 + (c - 48);
- } else {
- let done = true;
- }
- let i = i + 1;
- }
- if (neg) {
- return -n;
- } else {
- return n;
- }
-
- }
-
- /** Sets this string to hold a representation of the given value. */
- method void setInt(int val) { //change Output.printInt after this
- var int x, i, y;
- var boolean neg;
- if (val < 0) {
- let neg = true;
- let len = 2;
- } else {
- let neg = false;
- let len = 1;
- }
- let x = Math.abs(val);
- if (x > 9999) {
- let len = len + 4;
- } else { if (x > 999) {
- let len = len + 3;
- } else { if (x > 99) {
- let len = len + 2;
- } else { if (x > 9) {
- let len = len + 1;
- }}}}
- if (len > maxLen) {
- do Output.printString("String.setInt: val is too big for the string!");
- do Sys.error(5);
- }
- if (x = 0) {
- do setCharAt(0, 48);
- return;
- }
- if (neg) {
- do setCharAt(0, 45);
- }
- let i = len - 1;
- while (x > 0) {
- let y = x / 10;
- do setCharAt(i, x - (y * 10) + 48);
- let x = y;
- let i = i - 1;
- }
- return;
- }
-
- /** Returns the new line character. */
- function char newLine() {
- return 128;
- }
-
- /** Returns the backspace character. */
- function char backSpace() {
- return 129;
- }
-
- /** Returns the double quote (") character. */
- function char doubleQuote() {
- return 34;
- }
-}
diff --git a/projects/12/StringTest/Main.jack b/projects/12/StringTest/Main.jack deleted file mode 100644 index 2848548..0000000 --- a/projects/12/StringTest/Main.jack +++ /dev/null @@ -1,83 +0,0 @@ -// 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/StringTest/Main.jack
-
-/** Test program for the OS String class. */
-class Main {
-
- /** Performs various string manipulations and displays their results. */
- function void main() {
- var String s;
- var String i;
-
- let s = String.new(0); // a zero-capacity string should be supported
- do s.dispose();
-
- let s = String.new(6); // capacity 6, make sure that length 5 is displayed
- let s = s.appendChar(97);
- let s = s.appendChar(98);
- let s = s.appendChar(99);
- let s = s.appendChar(100);
- let s = s.appendChar(101);
- do Output.printString("new,appendChar: ");
- do Output.printString(s); // new, appendChar: abcde
- do Output.println();
-
- let i = String.new(6);
- do i.setInt(12345);
- do Output.printString("setInt: ");
- do Output.printString(i); // setInt: 12345
- do Output.println();
-
- do i.setInt(-32767);
- do Output.printString("setInt: ");
- do Output.printString(i); // setInt: -32767
- do Output.println();
-
- do Output.printString("length: ");
- do Output.printInt(s.length()); // length: 5
- do Output.println();
-
- do Output.printString("charAt[2]: ");
- do Output.printInt(s.charAt(2)); // charAt[2]: 99
- do Output.println();
-
- do s.setCharAt(2, 45);
- do Output.printString("setCharAt(2,'-'): ");
- do Output.printString(s); // setCharAt(2,'-'): ab-de
- do Output.println();
-
- do s.eraseLastChar();
- do Output.printString("eraseLastChar: ");
- do Output.printString(s); // eraseLastChar: ab-d
- do Output.println();
-
- let s = "456";
- do Output.printString("intValue: ");
- do Output.printInt(s.intValue()); // intValue: 456
- do Output.println();
-
- let s = "-32123";
- do Output.printString("intValue: ");
- do Output.printInt(s.intValue()); // intValue: -32123
- do Output.println();
-
- do Output.printString("backSpace: ");
- do Output.printInt(String.backSpace()); // backSpace: 129
- do Output.println();
-
- do Output.printString("doubleQuote: ");
- do Output.printInt(String.doubleQuote());// doubleQuote: 34
- do Output.println();
-
- do Output.printString("newLine: ");
- do Output.printInt(String.newLine()); // newLine: 128
- do Output.println();
-
- do i.dispose();
- do s.dispose();
-
- return;
- }
-}
diff --git a/projects/12/StringTest/Main.vm b/projects/12/StringTest/Main.vm deleted file mode 100644 index 2c9fb9f..0000000 --- a/projects/12/StringTest/Main.vm +++ /dev/null @@ -1,469 +0,0 @@ -function Main.main 2 -push constant 0 -call String.new 1 -pop local 0 -push local 0 -call String.dispose 1 -pop temp 0 -push constant 6 -call String.new 1 -pop local 0 -push local 0 -push constant 97 -call String.appendChar 2 -pop local 0 -push local 0 -push constant 98 -call String.appendChar 2 -pop local 0 -push local 0 -push constant 99 -call String.appendChar 2 -pop local 0 -push local 0 -push constant 100 -call String.appendChar 2 -pop local 0 -push local 0 -push constant 101 -call String.appendChar 2 -pop local 0 -push constant 16 -call String.new 1 -push constant 110 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 119 -call String.appendChar 2 -push constant 44 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 67 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push local 0 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 6 -call String.new 1 -pop local 1 -push local 1 -push constant 12345 -call String.setInt 2 -pop temp 0 -push constant 8 -call String.new 1 -push constant 115 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 73 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push local 1 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push local 1 -push constant 32767 -neg -call String.setInt 2 -pop temp 0 -push constant 8 -call String.new 1 -push constant 115 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 73 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push local 1 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 8 -call String.new 1 -push constant 108 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push local 0 -call String.length 1 -call Output.printInt 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 11 -call String.new 1 -push constant 99 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 65 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 91 -call String.appendChar 2 -push constant 50 -call String.appendChar 2 -push constant 93 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push local 0 -push constant 2 -call String.charAt 2 -call Output.printInt 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push local 0 -push constant 2 -push constant 45 -call String.setCharAt 3 -pop temp 0 -push constant 18 -call String.new 1 -push constant 115 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 67 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 65 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 40 -call String.appendChar 2 -push constant 50 -call String.appendChar 2 -push constant 44 -call String.appendChar 2 -push constant 39 -call String.appendChar 2 -push constant 45 -call String.appendChar 2 -push constant 39 -call String.appendChar 2 -push constant 41 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push local 0 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push local 0 -call String.eraseLastChar 1 -pop temp 0 -push constant 15 -call String.new 1 -push constant 101 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 76 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 67 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push local 0 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 3 -call String.new 1 -push constant 52 -call String.appendChar 2 -push constant 53 -call String.appendChar 2 -push constant 54 -call String.appendChar 2 -pop local 0 -push constant 10 -call String.new 1 -push constant 105 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 86 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push local 0 -call String.intValue 1 -call Output.printInt 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 6 -call String.new 1 -push constant 45 -call String.appendChar 2 -push constant 51 -call String.appendChar 2 -push constant 50 -call String.appendChar 2 -push constant 49 -call String.appendChar 2 -push constant 50 -call String.appendChar 2 -push constant 51 -call String.appendChar 2 -pop local 0 -push constant 10 -call String.new 1 -push constant 105 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 86 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push local 0 -call String.intValue 1 -call Output.printInt 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 11 -call String.new 1 -push constant 98 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 107 -call String.appendChar 2 -push constant 83 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -call String.backSpace 0 -call Output.printInt 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 13 -call String.new 1 -push constant 100 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 98 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 81 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -call String.doubleQuote 0 -call Output.printInt 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 9 -call String.new 1 -push constant 110 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 119 -call String.appendChar 2 -push constant 76 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -call String.newLine 0 -call Output.printInt 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push local 1 -call String.dispose 1 -pop temp 0 -push local 0 -call String.dispose 1 -pop temp 0 -push constant 0 -return diff --git a/projects/12/StringTest/String.jack b/projects/12/StringTest/String.jack deleted file mode 100644 index 3ef40b2..0000000 --- a/projects/12/StringTest/String.jack +++ /dev/null @@ -1,176 +0,0 @@ -// 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/String.jack
-
-/**
- * Represents character strings. In addition for constructing and disposing
- * strings, the class features methods for getting and setting individual
- * characters of the string, for erasing the string's last character,
- * for appending a character to the string's end, and more typical
- * string-oriented operations.
- */
-class String {
- field int maxLen;
- field int len;
- field Array s;
-
- /** constructs a new empty string with a maximum length of maxLength
- * and initial length of 0. */
- constructor String new(int maxLength) {
- if (maxLength > 0) {
- let s = Array.new(maxLength);
- }
- let maxLen = maxLength;
- let len = 0;
- return this;
- }
-
- /** Disposes this string. */
- method void dispose() {
- if (maxLen > 0) {
- do s.dispose();
- }
- do Memory.deAlloc(this);
- return;
- }
-
- /** Returns the current length of this string. */
- method int length() {
- return len;
- }
-
- /** Returns the character at the j-th location of this string. */
- method char charAt(int j) {
- if ((j < 0) | (j + 1 > len)){
- do Output.printString("String.charAt: index out of range!");
- do Sys.error(5);
- }
- return s[j];
- }
-
- /** Sets the character at the j-th location of this string to c. */
- method void setCharAt(int j, char c) {
- if ((j < 0) | (j + 1 > len)){
- do Output.printString("String.setCharAt: index out of range!");
- do Sys.error(5);
- }
- let s[j] = c;
- return;
- }
-
- /** Appends c to this string's end and returns this string. */
- method String appendChar(char c) {
- if (len = maxLen) {
- do Output.printString("String.appendChar: reached max length!");
- do Sys.error(5);
- }
- let s[len] = c;
- let len = len + 1;
- return this;
- }
-
- /** Erases the last character from this string. */
- method void eraseLastChar() {
- if (len = 0){
- do Output.printString("String.eraseLastChar: string is already empty!");
- do Sys.error(5);
- }
- let len = len - 1;
- return;
- }
-
- /** Returns the integer value of this string,
- * until a non-digit character is detected. */
- method int intValue() {
- var int n, i;
- var char c;
- var boolean neg, done;
- let n = 0;
- if (s[0] = 45) {
- let i = 1;
- let neg = true;
- } else {
- let i = 0;
- let neg = false;
- }
- let c = s[i];
- if ((c < 48) | (c > 57)) {
- do Sys.error(3);
- do Output.printString("String.intValue: the input data is not number!");
- }
- let done = false;
- while ((~done) & (i < len)) {
- let c = s[i];
- if ((c > 47) & (c < 58)) {
- let n = n * 10 + (c - 48);
- } else {
- let done = true;
- }
- let i = i + 1;
- }
- if (neg) {
- return -n;
- } else {
- return n;
- }
-
- }
-
- /** Sets this string to hold a representation of the given value. */
- method void setInt(int val) { //change Output.printInt after this
- var int x, i, y;
- var boolean neg;
- if (val < 0) {
- let neg = true;
- let len = 2;
- } else {
- let neg = false;
- let len = 1;
- }
- let x = Math.abs(val);
- if (x > 9999) {
- let len = len + 4;
- } else { if (x > 999) {
- let len = len + 3;
- } else { if (x > 99) {
- let len = len + 2;
- } else { if (x > 9) {
- let len = len + 1;
- }}}}
- if (len > maxLen) {
- do Output.printString("String.setInt: val is too big for the string!");
- do Sys.error(5);
- }
- if (x = 0) {
- do setCharAt(0, 48);
- return;
- }
- if (neg) {
- do setCharAt(0, 45);
- }
- let i = len - 1;
- while (x > 0) {
- let y = x / 10;
- do setCharAt(i, x - (y * 10) + 48);
- let x = y;
- let i = i - 1;
- }
- return;
- }
-
- /** Returns the new line character. */
- function char newLine() {
- return 128;
- }
-
- /** Returns the backspace character. */
- function char backSpace() {
- return 129;
- }
-
- /** Returns the double quote (") character. */
- function char doubleQuote() {
- return 34;
- }
-}
diff --git a/projects/12/StringTest/String.vm b/projects/12/StringTest/String.vm deleted file mode 100644 index 36664c1..0000000 --- a/projects/12/StringTest/String.vm +++ /dev/null @@ -1,917 +0,0 @@ -function String.new 0 -push constant 3 -call Memory.alloc 1 -pop pointer 0 -push argument 0 -push constant 0 -gt -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push argument 0 -call Array.new 1 -pop this 2 -label IF_FALSE0 -push argument 0 -pop this 0 -push constant 0 -pop this 1 -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 2 -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 1 -return -function String.charAt 0 -push argument 0 -pop pointer 0 -push argument 1 -push constant 0 -lt -push argument 1 -push constant 1 -add -push this 1 -gt -or -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 34 -call String.new 1 -push constant 83 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 46 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 65 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 120 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 102 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 33 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push constant 5 -call Sys.error 1 -pop temp 0 -label IF_FALSE0 -push argument 1 -push this 2 -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 constant 1 -add -push this 1 -gt -or -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 37 -call String.new 1 -push constant 83 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 46 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 67 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 65 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 120 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 102 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 33 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push constant 5 -call Sys.error 1 -pop temp 0 -label IF_FALSE0 -push argument 1 -push this 2 -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 1 -push this 0 -eq -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 38 -call String.new 1 -push constant 83 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 46 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 67 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 109 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 120 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 33 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push constant 5 -call Sys.error 1 -pop temp 0 -label IF_FALSE0 -push this 1 -push this 2 -add -push argument 1 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push this 1 -push constant 1 -add -pop this 1 -push pointer 0 -return -function String.eraseLastChar 0 -push argument 0 -pop pointer 0 -push this 1 -push constant 0 -eq -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 46 -call String.new 1 -push constant 83 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 46 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 76 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 67 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 121 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 109 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 121 -call String.appendChar 2 -push constant 33 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push constant 5 -call Sys.error 1 -pop temp 0 -label IF_FALSE0 -push this 1 -push constant 1 -sub -pop this 1 -push constant 0 -return -function String.intValue 5 -push argument 0 -pop pointer 0 -push constant 0 -pop local 0 -push constant 0 -push this 2 -add -pop pointer 1 -push that 0 -push constant 45 -eq -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 1 -pop local 1 -push constant 0 -not -pop local 3 -goto IF_END0 -label IF_FALSE0 -push constant 0 -pop local 1 -push constant 0 -pop local 3 -label IF_END0 -push local 1 -push this 2 -add -pop pointer 1 -push that 0 -pop local 2 -push local 2 -push constant 48 -lt -push local 2 -push constant 57 -gt -or -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push constant 3 -call Sys.error 1 -pop temp 0 -push constant 46 -call String.new 1 -push constant 83 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 46 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 86 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 109 -call String.appendChar 2 -push constant 98 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 33 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -label IF_FALSE1 -push constant 0 -pop local 4 -label WHILE_EXP0 -push local 4 -not -push local 1 -push this 1 -lt -and -not -if-goto WHILE_END0 -push local 1 -push this 2 -add -pop pointer 1 -push that 0 -pop local 2 -push local 2 -push constant 47 -gt -push local 2 -push constant 58 -lt -and -if-goto IF_TRUE2 -goto IF_FALSE2 -label IF_TRUE2 -push local 0 -push constant 10 -call Math.multiply 2 -push local 2 -push constant 48 -sub -add -pop local 0 -goto IF_END2 -label IF_FALSE2 -push constant 0 -not -pop local 4 -label IF_END2 -push local 1 -push constant 1 -add -pop local 1 -goto WHILE_EXP0 -label WHILE_END0 -push local 3 -if-goto IF_TRUE3 -goto IF_FALSE3 -label IF_TRUE3 -push local 0 -neg -return -goto IF_END3 -label IF_FALSE3 -push local 0 -return -label IF_END3 -function String.setInt 4 -push argument 0 -pop pointer 0 -push argument 1 -push constant 0 -lt -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 0 -not -pop local 3 -push constant 2 -pop this 1 -goto IF_END0 -label IF_FALSE0 -push constant 0 -pop local 3 -push constant 1 -pop this 1 -label IF_END0 -push argument 1 -call Math.abs 1 -pop local 0 -push local 0 -push constant 9999 -gt -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push this 1 -push constant 4 -add -pop this 1 -goto IF_END1 -label IF_FALSE1 -push local 0 -push constant 999 -gt -if-goto IF_TRUE2 -goto IF_FALSE2 -label IF_TRUE2 -push this 1 -push constant 3 -add -pop this 1 -goto IF_END2 -label IF_FALSE2 -push local 0 -push constant 99 -gt -if-goto IF_TRUE3 -goto IF_FALSE3 -label IF_TRUE3 -push this 1 -push constant 2 -add -pop this 1 -goto IF_END3 -label IF_FALSE3 -push local 0 -push constant 9 -gt -if-goto IF_TRUE4 -goto IF_FALSE4 -label IF_TRUE4 -push this 1 -push constant 1 -add -pop this 1 -label IF_FALSE4 -label IF_END3 -label IF_END2 -label IF_END1 -push this 1 -push this 0 -gt -if-goto IF_TRUE5 -goto IF_FALSE5 -label IF_TRUE5 -push constant 45 -call String.new 1 -push constant 83 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 46 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 73 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 118 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 98 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 102 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 33 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push constant 5 -call Sys.error 1 -pop temp 0 -label IF_FALSE5 -push local 0 -push constant 0 -eq -if-goto IF_TRUE6 -goto IF_FALSE6 -label IF_TRUE6 -push pointer 0 -push constant 0 -push constant 48 -call String.setCharAt 3 -pop temp 0 -push constant 0 -return -label IF_FALSE6 -push local 3 -if-goto IF_TRUE7 -goto IF_FALSE7 -label IF_TRUE7 -push pointer 0 -push constant 0 -push constant 45 -call String.setCharAt 3 -pop temp 0 -label IF_FALSE7 -push this 1 -push constant 1 -sub -pop local 1 -label WHILE_EXP0 -push local 0 -push constant 0 -gt -not -if-goto WHILE_END0 -push local 0 -push constant 10 -call Math.divide 2 -pop local 2 -push pointer 0 -push local 1 -push local 0 -push local 2 -push constant 10 -call Math.multiply 2 -sub -push constant 48 -add -call String.setCharAt 3 -pop temp 0 -push local 2 -pop local 0 -push local 1 -push constant 1 -sub -pop local 1 -goto WHILE_EXP0 -label WHILE_END0 -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/projects/12/StringTest/StringTestOutput.gif b/projects/12/StringTest/StringTestOutput.gif Binary files differdeleted file mode 100644 index 5c2932c..0000000 --- a/projects/12/StringTest/StringTestOutput.gif +++ /dev/null diff --git a/projects/12/Sys.jack b/projects/12/Sys.jack deleted file mode 100644 index 53c078c..0000000 --- a/projects/12/Sys.jack +++ /dev/null @@ -1,51 +0,0 @@ -// 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/Sys.jack
-
-/**
- * A library that supports various program execution services.
- */
-class Sys {
-
- /** Performs all the initializations required by the OS. */
- function void init() {
- do Keyboard.init();
- do Math.init();
- do Memory.init();
- do Output.init();
- do Screen.init();
- do Main.main();
- do Sys.halt();
- return;
- }
-
- /** Halts the program execution. */
- function void halt() {
- while (true){
- }
- return;
- }
-
- /** Waits approximately duration milliseconds and returns. */
- function void wait(int duration) {
- var int i, j;
- let i = 0;
- while (i < duration){
- let i = i + 1;
- let j = 0;
- while (j < 318){
- let j = j + 1;
- }
- }
- return;
- }
-
- /** Displays the given error code in the form "ERR<errorCode>",
- * and halts the program's execution. */
- function void error(int errorCode) {
- do Output.printString("ERR");
- do Output.printInt(errorCode);
- return;
- }
-}
diff --git a/projects/12/SysTest/Main.jack b/projects/12/SysTest/Main.jack deleted file mode 100644 index a153b25..0000000 --- a/projects/12/SysTest/Main.jack +++ /dev/null @@ -1,31 +0,0 @@ -// 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/SysTest/Main.jack
-
-/** Test program for the OS Sys class. */
-class Main {
-
- /** Tests the wait method of the Sys class. */
- function void main() {
- var char key;
-
- do Output.printString("Wait test:");
- do Output.println();
- do Output.printString("Press any key. After 2 seconds, another message will be printed:");
-
- while (key = 0) {
- let key = Keyboard.keyPressed();
- }
- while (~(key = 0)) {
- let key = Keyboard.keyPressed();
- }
-
- do Sys.wait(2000);
-
- do Output.println();
- do Output.printString("Time is up. Make sure that 2 seconds elapsed.");
-
- return;
- }
-}
diff --git a/projects/12/SysTest/Main.vm b/projects/12/SysTest/Main.vm deleted file mode 100644 index 4890e2f..0000000 --- a/projects/12/SysTest/Main.vm +++ /dev/null @@ -1,281 +0,0 @@ -function Main.main 1 -push constant 10 -call String.new 1 -push constant 87 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 64 -call String.new 1 -push constant 80 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 121 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 107 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 121 -call String.appendChar 2 -push constant 46 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 65 -call String.appendChar 2 -push constant 102 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 50 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 44 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 109 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 103 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 119 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 98 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -label WHILE_EXP0 -push local 0 -push constant 0 -eq -not -if-goto WHILE_END0 -call Keyboard.keyPressed 0 -pop local 0 -goto WHILE_EXP0 -label WHILE_END0 -label WHILE_EXP1 -push local 0 -push constant 0 -eq -not -not -if-goto WHILE_END1 -call Keyboard.keyPressed 0 -pop local 0 -goto WHILE_EXP1 -label WHILE_END1 -push constant 2000 -call Sys.wait 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 45 -call String.new 1 -push constant 84 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 109 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 46 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 77 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 107 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 104 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 50 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 46 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push constant 0 -return diff --git a/projects/12/SysTest/Sys.jack b/projects/12/SysTest/Sys.jack deleted file mode 100644 index 53c078c..0000000 --- a/projects/12/SysTest/Sys.jack +++ /dev/null @@ -1,51 +0,0 @@ -// 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/Sys.jack
-
-/**
- * A library that supports various program execution services.
- */
-class Sys {
-
- /** Performs all the initializations required by the OS. */
- function void init() {
- do Keyboard.init();
- do Math.init();
- do Memory.init();
- do Output.init();
- do Screen.init();
- do Main.main();
- do Sys.halt();
- return;
- }
-
- /** Halts the program execution. */
- function void halt() {
- while (true){
- }
- return;
- }
-
- /** Waits approximately duration milliseconds and returns. */
- function void wait(int duration) {
- var int i, j;
- let i = 0;
- while (i < duration){
- let i = i + 1;
- let j = 0;
- while (j < 318){
- let j = j + 1;
- }
- }
- return;
- }
-
- /** Displays the given error code in the form "ERR<errorCode>",
- * and halts the program's execution. */
- function void error(int errorCode) {
- do Output.printString("ERR");
- do Output.printInt(errorCode);
- return;
- }
-}
diff --git a/projects/12/SysTest/Sys.vm b/projects/12/SysTest/Sys.vm deleted file mode 100644 index fec2862..0000000 --- a/projects/12/SysTest/Sys.vm +++ /dev/null @@ -1,74 +0,0 @@ -function Sys.init 0 -call Keyboard.init 0 -pop temp 0 -call Math.init 0 -pop temp 0 -call Memory.init 0 -pop temp 0 -call Output.init 0 -pop temp 0 -call Screen.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 2 -push constant 0 -pop local 0 -label WHILE_EXP0 -push local 0 -push argument 0 -lt -not -if-goto WHILE_END0 -push local 0 -push constant 1 -add -pop local 0 -push constant 0 -pop local 1 -label WHILE_EXP1 -push local 1 -push constant 318 -lt -not -if-goto WHILE_END1 -push local 1 -push constant 1 -add -pop local 1 -goto WHILE_EXP1 -label WHILE_END1 -goto WHILE_EXP0 -label WHILE_END0 -push constant 0 -return -function Sys.error 0 -push constant 3 -call String.new 1 -push constant 69 -call String.appendChar 2 -push constant 82 -call String.appendChar 2 -push constant 82 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -push argument 0 -call Output.printInt 1 -pop temp 0 -push constant 0 -return |