diff options
Diffstat (limited to 'projects/12/SysTest')
-rw-r--r-- | projects/12/SysTest/Main.vm | 281 | ||||
-rw-r--r-- | projects/12/SysTest/Sys.jack | 51 | ||||
-rw-r--r-- | projects/12/SysTest/Sys.vm | 74 |
3 files changed, 406 insertions, 0 deletions
diff --git a/projects/12/SysTest/Main.vm b/projects/12/SysTest/Main.vm new file mode 100644 index 0000000..4890e2f --- /dev/null +++ b/projects/12/SysTest/Main.vm @@ -0,0 +1,281 @@ +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 new file mode 100644 index 0000000..53c078c --- /dev/null +++ b/projects/12/SysTest/Sys.jack @@ -0,0 +1,51 @@ +// 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 new file mode 100644 index 0000000..fec2862 --- /dev/null +++ b/projects/12/SysTest/Sys.vm @@ -0,0 +1,74 @@ +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 |