From d3a0cc3a8ba6dfeb64d3faeffdeb6845b60e5840 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Sat, 20 Jan 2018 15:41:49 +0100 Subject: rearranged the dir for github - removed tools and pdfs - rearranged the projects dirs - added md files - other minor changes --- .../FibonacciElement/FibonacciElement.asm | 421 --------------- .../FibonacciElement/FibonacciElement.cmp | 2 - .../FibonacciElement/FibonacciElement.out | 2 - .../FibonacciElement/FibonacciElement.tst | 18 - .../FibonacciElement/FibonacciElementVME.tst | 17 - projects/08/FunctionCalls/FibonacciElement/Main.vm | 30 -- projects/08/FunctionCalls/FibonacciElement/Sys.vm | 15 - .../08/FunctionCalls/NestedCall/NestedCall.cmp | 2 - .../08/FunctionCalls/NestedCall/NestedCall.html | 196 ------- .../08/FunctionCalls/NestedCall/NestedCall.tst | 65 --- .../FunctionCalls/NestedCall/NestedCallStack.html | 306 ----------- .../08/FunctionCalls/NestedCall/NestedCallVME.tst | 70 --- projects/08/FunctionCalls/NestedCall/Sys.vm | 63 --- .../SimpleFunction/SimpleFunction.asm | 138 ----- .../SimpleFunction/SimpleFunction.cmp | 2 - .../SimpleFunction/SimpleFunction.out | 2 - .../SimpleFunction/SimpleFunction.tst | 29 - .../FunctionCalls/SimpleFunction/SimpleFunction.vm | 16 - .../SimpleFunction/SimpleFunction1.asm | 137 ----- .../SimpleFunction/SimpleFunctionVME.tst | 29 - projects/08/FunctionCalls/StaticsTest/Class1.vm | 20 - projects/08/FunctionCalls/StaticsTest/Class2.vm | 20 - .../08/FunctionCalls/StaticsTest/StaticsTest.asm | 586 --------------------- .../08/FunctionCalls/StaticsTest/StaticsTest.cmp | 2 - .../08/FunctionCalls/StaticsTest/StaticsTest.out | 2 - .../08/FunctionCalls/StaticsTest/StaticsTest.tst | 17 - .../FunctionCalls/StaticsTest/StaticsTestVME.tst | 17 - projects/08/FunctionCalls/StaticsTest/Sys.vm | 20 - projects/08/ProgramFlow/BasicLoop/BasicLoop.asm | 133 ----- projects/08/ProgramFlow/BasicLoop/BasicLoop.cmp | 2 - projects/08/ProgramFlow/BasicLoop/BasicLoop.out | 2 - projects/08/ProgramFlow/BasicLoop/BasicLoop.tst | 20 - projects/08/ProgramFlow/BasicLoop/BasicLoop.vm | 22 - projects/08/ProgramFlow/BasicLoop/BasicLoopVME.tst | 20 - .../FibonacciSeries/FibonacciSeries.asm | 234 -------- .../FibonacciSeries/FibonacciSeries.cmp | 2 - .../FibonacciSeries/FibonacciSeries.out | 2 - .../FibonacciSeries/FibonacciSeries.tst | 22 - .../ProgramFlow/FibonacciSeries/FibonacciSeries.vm | 49 -- .../FibonacciSeries/FibonacciSeries1.asm | 241 --------- .../FibonacciSeries/FibonacciSeriesVME.tst | 22 - projects/08/VMTranslator | Bin 93880 -> 0 bytes projects/08/VMTranslator.hi | Bin 2434 -> 0 bytes projects/08/VMTranslator.hs | 139 ----- projects/08/VMTranslator.o | Bin 118760 -> 0 bytes 45 files changed, 3154 deletions(-) delete mode 100644 projects/08/FunctionCalls/FibonacciElement/FibonacciElement.asm delete mode 100644 projects/08/FunctionCalls/FibonacciElement/FibonacciElement.cmp delete mode 100644 projects/08/FunctionCalls/FibonacciElement/FibonacciElement.out delete mode 100644 projects/08/FunctionCalls/FibonacciElement/FibonacciElement.tst delete mode 100644 projects/08/FunctionCalls/FibonacciElement/FibonacciElementVME.tst delete mode 100644 projects/08/FunctionCalls/FibonacciElement/Main.vm delete mode 100644 projects/08/FunctionCalls/FibonacciElement/Sys.vm delete mode 100644 projects/08/FunctionCalls/NestedCall/NestedCall.cmp delete mode 100644 projects/08/FunctionCalls/NestedCall/NestedCall.html delete mode 100644 projects/08/FunctionCalls/NestedCall/NestedCall.tst delete mode 100644 projects/08/FunctionCalls/NestedCall/NestedCallStack.html delete mode 100644 projects/08/FunctionCalls/NestedCall/NestedCallVME.tst delete mode 100644 projects/08/FunctionCalls/NestedCall/Sys.vm delete mode 100644 projects/08/FunctionCalls/SimpleFunction/SimpleFunction.asm delete mode 100644 projects/08/FunctionCalls/SimpleFunction/SimpleFunction.cmp delete mode 100644 projects/08/FunctionCalls/SimpleFunction/SimpleFunction.out delete mode 100644 projects/08/FunctionCalls/SimpleFunction/SimpleFunction.tst delete mode 100644 projects/08/FunctionCalls/SimpleFunction/SimpleFunction.vm delete mode 100644 projects/08/FunctionCalls/SimpleFunction/SimpleFunction1.asm delete mode 100644 projects/08/FunctionCalls/SimpleFunction/SimpleFunctionVME.tst delete mode 100644 projects/08/FunctionCalls/StaticsTest/Class1.vm delete mode 100644 projects/08/FunctionCalls/StaticsTest/Class2.vm delete mode 100644 projects/08/FunctionCalls/StaticsTest/StaticsTest.asm delete mode 100644 projects/08/FunctionCalls/StaticsTest/StaticsTest.cmp delete mode 100644 projects/08/FunctionCalls/StaticsTest/StaticsTest.out delete mode 100644 projects/08/FunctionCalls/StaticsTest/StaticsTest.tst delete mode 100644 projects/08/FunctionCalls/StaticsTest/StaticsTestVME.tst delete mode 100644 projects/08/FunctionCalls/StaticsTest/Sys.vm delete mode 100644 projects/08/ProgramFlow/BasicLoop/BasicLoop.asm delete mode 100644 projects/08/ProgramFlow/BasicLoop/BasicLoop.cmp delete mode 100644 projects/08/ProgramFlow/BasicLoop/BasicLoop.out delete mode 100644 projects/08/ProgramFlow/BasicLoop/BasicLoop.tst delete mode 100644 projects/08/ProgramFlow/BasicLoop/BasicLoop.vm delete mode 100644 projects/08/ProgramFlow/BasicLoop/BasicLoopVME.tst delete mode 100644 projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.asm delete mode 100644 projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.cmp delete mode 100644 projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.out delete mode 100644 projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.tst delete mode 100644 projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.vm delete mode 100644 projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries1.asm delete mode 100644 projects/08/ProgramFlow/FibonacciSeries/FibonacciSeriesVME.tst delete mode 100755 projects/08/VMTranslator delete mode 100644 projects/08/VMTranslator.hi delete mode 100644 projects/08/VMTranslator.hs delete mode 100644 projects/08/VMTranslator.o (limited to 'projects/08') diff --git a/projects/08/FunctionCalls/FibonacciElement/FibonacciElement.asm b/projects/08/FunctionCalls/FibonacciElement/FibonacciElement.asm deleted file mode 100644 index a2ca368..0000000 --- a/projects/08/FunctionCalls/FibonacciElement/FibonacciElement.asm +++ /dev/null @@ -1,421 +0,0 @@ -@256 -D=A -@SP -M=D -@RET0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@0 -D=D-A -@ARG -M=D -@Sys.init -0;JMP -(RET0) -(Main.fibonacci) -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@2 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFMain3 -D;JLT -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFMain3 -0;JMP -(IFMain3) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFMain3) -@SP -AM=M-1 -D=M -@Main.fibonacci$IF_TRUE -D;JNE -@Main.fibonacci$IF_FALSE -0;JMP -(Main.fibonacci$IF_TRUE) -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP -(Main.fibonacci$IF_FALSE) -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@2 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@SP -A=M -M=D -@SP -M=M+1 -@RET13 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Main.fibonacci -0;JMP -(RET13) -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@SP -A=M -M=D -@SP -M=M+1 -@RET17 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Main.fibonacci -0;JMP -(RET17) -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP -(Sys.init) -@4 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET2 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Main.fibonacci -0;JMP -(RET2) -(Sys.init$WHILE) -@Sys.init$WHILE -0;JMP diff --git a/projects/08/FunctionCalls/FibonacciElement/FibonacciElement.cmp b/projects/08/FunctionCalls/FibonacciElement/FibonacciElement.cmp deleted file mode 100644 index d667834..0000000 --- a/projects/08/FunctionCalls/FibonacciElement/FibonacciElement.cmp +++ /dev/null @@ -1,2 +0,0 @@ -| RAM[0] |RAM[261]| -| 262 | 3 | diff --git a/projects/08/FunctionCalls/FibonacciElement/FibonacciElement.out b/projects/08/FunctionCalls/FibonacciElement/FibonacciElement.out deleted file mode 100644 index fdf5e2d..0000000 --- a/projects/08/FunctionCalls/FibonacciElement/FibonacciElement.out +++ /dev/null @@ -1,2 +0,0 @@ -| RAM[0] |RAM[261]| -| 262 | 3 | diff --git a/projects/08/FunctionCalls/FibonacciElement/FibonacciElement.tst b/projects/08/FunctionCalls/FibonacciElement/FibonacciElement.tst deleted file mode 100644 index 1f907b1..0000000 --- a/projects/08/FunctionCalls/FibonacciElement/FibonacciElement.tst +++ /dev/null @@ -1,18 +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/08/FunctionCalls/FibonacciElement/FibonacciElement.tst - -// FibonacciElement.asm results from translating both Main.vm and Sys.vm into -// a single assembly program, stored in the file FibonacciElement.asm. - -load FibonacciElement.asm, -output-file FibonacciElement.out, -compare-to FibonacciElement.cmp, -output-list RAM[0]%D1.6.1 RAM[261]%D1.6.1; - -repeat 6000 { - ticktock; -} - -output; diff --git a/projects/08/FunctionCalls/FibonacciElement/FibonacciElementVME.tst b/projects/08/FunctionCalls/FibonacciElement/FibonacciElementVME.tst deleted file mode 100644 index 87c0920..0000000 --- a/projects/08/FunctionCalls/FibonacciElement/FibonacciElementVME.tst +++ /dev/null @@ -1,17 +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/08/FunctionCalls/FibonacciElement/FibonacciElementVME.tst - -load, // Load all the VM files from the current directory -output-file FibonacciElement.out, -compare-to FibonacciElement.cmp, -output-list RAM[0]%D1.6.1 RAM[261]%D1.6.1; - -set sp 261, - -repeat 110 { - vmstep; -} - -output; diff --git a/projects/08/FunctionCalls/FibonacciElement/Main.vm b/projects/08/FunctionCalls/FibonacciElement/Main.vm deleted file mode 100644 index 55e5ad2..0000000 --- a/projects/08/FunctionCalls/FibonacciElement/Main.vm +++ /dev/null @@ -1,30 +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/08/FunctionCalls/FibonacciElement/Main.vm - -// Computes the n'th element of the Fibonacci series, recursively. -// n is given in argument[0]. Called by the Sys.init function -// (part of the Sys.vm file), which also pushes the argument[0] -// parameter before this code starts running. - -function Main.fibonacci 0 -push argument 0 -push constant 2 -lt // checks if n<2 -if-goto IF_TRUE -goto IF_FALSE -label IF_TRUE // if n<2, return n -push argument 0 -return -label IF_FALSE // if n>=2, returns fib(n-2)+fib(n-1) -push argument 0 -push constant 2 -sub -call Main.fibonacci 1 // computes fib(n-2) -push argument 0 -push constant 1 -sub -call Main.fibonacci 1 // computes fib(n-1) -add // returns fib(n-1) + fib(n-2) -return diff --git a/projects/08/FunctionCalls/FibonacciElement/Sys.vm b/projects/08/FunctionCalls/FibonacciElement/Sys.vm deleted file mode 100644 index f3965c9..0000000 --- a/projects/08/FunctionCalls/FibonacciElement/Sys.vm +++ /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/08/FunctionCalls/FibonacciElement/Sys.vm - -// Pushes a constant, say n, onto the stack, and calls the Main.fibonacii -// function, which computes the n'th element of the Fibonacci series. -// Note that by convention, the Sys.init function is called "automatically" -// by the bootstrap code. - -function Sys.init 0 -push constant 4 -call Main.fibonacci 1 // computes the 4'th fibonacci element -label WHILE -goto WHILE // loops infinitely diff --git a/projects/08/FunctionCalls/NestedCall/NestedCall.cmp b/projects/08/FunctionCalls/NestedCall/NestedCall.cmp deleted file mode 100644 index 9200202..0000000 --- a/projects/08/FunctionCalls/NestedCall/NestedCall.cmp +++ /dev/null @@ -1,2 +0,0 @@ -| RAM[0] | RAM[1] | RAM[2] | RAM[3] | RAM[4] | RAM[5] | RAM[6] | -| 261 | 261 | 256 | 4000 | 5000 | 135 | 246 | diff --git a/projects/08/FunctionCalls/NestedCall/NestedCall.html b/projects/08/FunctionCalls/NestedCall/NestedCall.html deleted file mode 100644 index 0821f9c..0000000 --- a/projects/08/FunctionCalls/NestedCall/NestedCall.html +++ /dev/null @@ -1,196 +0,0 @@ - - - - - NestedCall.tst — Nand2Tetris Calling Convention Test - - - - -

Synopsis

-NestedCall.tst is an intermediate test (in terms of complexity) intended to be used between the SimpleFunction and -FibonacciElement tests. It may be useful when SimpleFunction passes but FibonacciElement fails or crashes. NestedCall also -tests several requirements of the Function Calling Protocol that are not verified by the other -supplied tests. NestedCall can be used with or without the VM bootstrap code. -

-NestedCallVME.tst runs the same test on the VM Emulator. -

-The NestedCall tests and supporting documentation were written by Mark Armbrust. - - -

Test Structure

-

Startup

-NestedCall is implemented entirely within the Sys.vm file. The first function in Sys.vm is -Sys.init(). This allows it to be used before the bootstrap code has been added to the VM Translator -since there will be no file processing order issues. -

-NestedCall loads Sys.asm, sets up the stack to simulate the bootstrap's call to Sys.init(), then -begins execution at the beginning of Sys.asm. If the bootstrap is not present, the program begins -running with Sys.init() since it is the first function in Sys.vm. -

-If Sys.asm includes the bootstrap, the bootstrap will (re)initialize the stack and call Sys.init(), -so the test should see the same environment either way it gets to Sys.init(). -

-The test setup also initializes the - -

Sys.init()

- -THIS and THAT are set to known values so that context save and restore can be tested. -

-Sys.init() calls Sys.main() and stores the return value in temp 1. This tests call to and -return from a function with no arguments. - -

Sys.main()

-Sys.init() allocates 5 local variables. It sets local 1, local 2 and -local 3. local 0 and local 4 are intentionally not set. -

-THIS and THAT are changed so that context save and restore can be tested. -

-Sys.main() calls Sys.add12(123) and stores the return value in temp 0. This tests call to and -return from a function with arguments. -

-After Sys.add12() returns, Sys.main() sums local 0 through local 4 and returns the -result. This tests that the local segment was properly allocated on the stack and that the local -variables were not overwritten by the call to Sys.main(). It also tests that local 0 and -local 4 were properly initialized to 0. - -

Sys.add12()

- -THIS and THAT are set to known values so that context save and restore can be tested. -

-Returns argument 0 plus 12. - - -

Test Coverage

- -

-Functions with no arguments return to correct RIP (Return Instruction Point) with correct return value on stack.
-This can fail if the RIP is not correctly pushed on the stack by the calling code, or if the returning -code does not store the RIP in a temporary register before overwriting it with the return value. - -

-Functions with arguments return to correct RIP with correct return value on stack.
-This can fail if it is assumed that ARG points to the RIP. - -

-Functions with local variables allocate space on the stack for the local variables.
-This can fail if the function prologue is not written or if the SP is not updated after zeroing -the local variables. - -

-All local variables are initialized to 0.
-Common errors are to forget this completely, or for the zeroing loop to be off by one. - -

-THIS and THAT are correctly retained across function calls. Looking ahead, in Project 9 you will be asked to write a simple computer game in the high-level Jack language. You can run your game (following compilation) on the supplied VM Emulator. But, if you choose to translate the VM code that the compiler generates using your VM Translator, then code like -"push THIS, push THAT ... pop THIS, pop THAT" can cause some interesting failures! - - -

Debugging

-These comments assume that your VM translator has passed the SimpleFunction test. -

-If RAM[0] is incorrect, you have a stack skew. More data was pushed onto the stack by -call than was popped by return, or vice versa. See debugging with -breakpoints later in this section. -

-If one or more of RAM[1] through RAM[4] is incorrect, the LCL, -ARG, THIS and THAT pointers are not being correctly saved or restored. -Most likely problem is when they are being saved; the SimpleFunction test verified that -return restored them correctly. -

-If RAM[5] is incorrect there may be a problem with setting up the ARG pointer. -

-If RAM[4] is incorrect and RAM[5] is correct, there may be a problem with -allocation or initialization of local variables. - -

Debugging with breakpoints

- -To find tough bugs you can use the "breakpoint" facility in the CPU Emulator (red flag button). -You can use breakpoints to have you program stop when it gets to a particular RAM address. For -example:
- • load the NestedCall.tst file,
- • set a PC breakpoint at the ROM address for (Sys.main),
- • hit the run button.
-When the CPU Emulator stops at the breakpoint you can inspect the RAM to check the stack and pointers values. -(If the breakpoint isn't hit, you will need to to single-step debug through -your calling code to see why it didn't get there.) -

-Other useful places to set breakpoints are the entry points to the other functions and at the -first and final instructions generated for return commands. -

-NestedCallStack.html shows the expected stack values at various points -during the test. - -

Finding ROM address in your ASM code

-It is not easy to find the ROM locations where you want to set breakpoints, because there is no -one-to-one correspondence between the ASM file line numbers and the ROM addresses. This is made even more -difficult because the supplied CPU Emulator does not display the (LABELS) in its ROM panel. -

-There are two things that you can do to make this easier. -

-

Modify your assembler to generate a listing file.
-A listing file shows all the ASM source lines, including comments, as well as the ROM addresses and -the values of the labels and the instructions. For example, here is a snippet of a listing file generated by an assembler written by Mark Armbrust: -
-   20    16      @i      // i -= 1
-   21  FC88      M=M-1
-             
-   22  FC10      D=M     // if i > 0
-   23     6      @LOOP
-   24  E301      D;JGT   //      goto LOOP
-             
-   25        (STOP)
-   25    25      @STOP
-   26  EA87      0;JMP
-
-Data Symbols
-
-   16 D  i
-
-Code Symbols
-
-    6 C  LOOP
-   17 C  SKIP
-   25 C  STOP
-
-For the Nand2Tetris environment, it is most useful to list the ROM addresses and A-instruction -values in decimal. In the above snippet, the C-instruction values are -listed in hexadecimal. -

-The list file is generated during pass 2 of the Assembler, parallel to generating the .hack file. To -make it easier to handle blank and comment only lines, Mark has Parser.commandType() return -NO_COMMAND for source lines with no command. Mark also added Parser.sourceLine() that returns the -unmodified source line. -

-

Have your VM Translator write the VM source lines as comments in the ASM output.
-For example: -
-    // label LOOP
-(Sys.init$LOOP)
-    // goto LOOP
-@Sys.init$LOOP
-0;JMP
-    //
-    // // Sys.main()
-    // 
-    // // Sets locals 1, 2 and 3, leaving locals 0 and 4 unchanged to test
-    // // default local initialization to 0.  (RAM set to -1 by test setup.)
-    // // Calls Sys.add12(123) and stores return value (135) in temp 0.
-    // // Returns local 0 + local 1 + local 2 + local 3 + local 4 (456) to confirm
-    // // that locals were not mangled by function call.
-    // 
-    // function Sys.main 5
-(Sys.main)
-@5
-D=-A
-($3)
-@SP
-
-Note that comments in the VM source become double comments. Looking ahead, in Project 11 you will be asked to write a compiler for the Jack language. If your compiler will write the Jack source lines as comments in the -generated VM files, this convention will be quite useful. - - - \ No newline at end of file diff --git a/projects/08/FunctionCalls/NestedCall/NestedCall.tst b/projects/08/FunctionCalls/NestedCall/NestedCall.tst deleted file mode 100644 index 70e5523..0000000 --- a/projects/08/FunctionCalls/NestedCall/NestedCall.tst +++ /dev/null @@ -1,65 +0,0 @@ -// Test file for NestedCall test. - -load NestedCall.asm, -output-file NestedCall.out, -compare-to NestedCall.cmp, -output-list RAM[0]%D1.6.1 RAM[1]%D1.6.1 RAM[2]%D1.6.1 RAM[3]%D1.6.1 RAM[4]%D1.6.1 RAM[5]%D1.6.1 RAM[6]%D1.6.1; - -set RAM[0] 261, -set RAM[1] 261, -set RAM[2] 256, -set RAM[3] -3, -set RAM[4] -4, -set RAM[5] -1, // test results -set RAM[6] -1, -set RAM[256] 1234, // fake stack frame from call Sys.init -set RAM[257] -1, -set RAM[258] -2, -set RAM[259] -3, -set RAM[260] -4, - -set RAM[261] -1, // Initialize stack to check for local segment -set RAM[262] -1, // being cleared to zero. -set RAM[263] -1, -set RAM[264] -1, -set RAM[265] -1, -set RAM[266] -1, -set RAM[267] -1, -set RAM[268] -1, -set RAM[269] -1, -set RAM[270] -1, -set RAM[271] -1, -set RAM[272] -1, -set RAM[273] -1, -set RAM[274] -1, -set RAM[275] -1, -set RAM[276] -1, -set RAM[277] -1, -set RAM[278] -1, -set RAM[279] -1, -set RAM[280] -1, -set RAM[281] -1, -set RAM[282] -1, -set RAM[283] -1, -set RAM[284] -1, -set RAM[285] -1, -set RAM[286] -1, -set RAM[287] -1, -set RAM[288] -1, -set RAM[289] -1, -set RAM[290] -1, -set RAM[291] -1, -set RAM[292] -1, -set RAM[293] -1, -set RAM[294] -1, -set RAM[295] -1, -set RAM[296] -1, -set RAM[297] -1, -set RAM[298] -1, -set RAM[299] -1, - -repeat 4000 { - ticktock; -} - -output; diff --git a/projects/08/FunctionCalls/NestedCall/NestedCallStack.html b/projects/08/FunctionCalls/NestedCall/NestedCallStack.html deleted file mode 100644 index 70582b6..0000000 --- a/projects/08/FunctionCalls/NestedCall/NestedCallStack.html +++ /dev/null @@ -1,306 +0,0 @@ - - - - - NestedCall.tst — Stack Frames - - - - - - - -
- - - - - - - - - - - -
Bootstrap init
Pointers
0256SP
1-1LCL
2-2ARG
3-3THIS
4-4THAT
Stack
256???←SP

- This is how my boot­strap code initial­izes the pointers before calling Sys.init(). -

- Setting the LCL, ARG, THIS and THAT point­ers to known illegal values helps identify - when a pointer is used before it is initial­ized. -

- (If you are running the NestedCall test with­out boot­strap code, you will not see this state.)

-
- - - - - - - - - - - - - - - - -
Entry to Sys.init()
Pointers
0261SP
1261LCL
2256ARG
3-3THIS
4-4THAT
Stack
256*Return IP←ARG
257-1Saved LCL
258-2Saved ARGSys.init
259-3Saved THIS frame
260-4Saved THAT
261???←LCL, SP

- This is how NestedCall.tst initial­izes the pointers and stack. This is what RAM looks - like after my boot­strap calls Sys.init(). -

- (If your VM trans­lation includes the boot­strap, the -1 through -4 values may be - different if your boot­strap initial­izes them.)

-
- - - - - - - - - - - - - - - - - - - - -
Entry to Sys.main()
Pointers
0266SP
1266LCL
2261ARG
34000THIS
45000THAT
Stack
256*Return IP
257-1Saved LCL
258-2Saved ARGSys.init
259-3Saved THIS frame
260-4Saved THAT
261*Return IP←ARG
262261Saved LCL
263256Saved ARGSys.main
2644000Saved THIS frame
2655000Saved THAT
266???←LCL, SP
-
- - - - - - - - - - - - - - - - - - - - - - - - - -
After Sys.main() prologue
Pointers
0271SP
1266LCL
2261ARG
34000THIS
45000THAT
Stack
256*Return IP
257-1Saved LCL
258-2Saved ARGSys.init
259-3Saved THIS frame
260-4Saved THAT
261*Return IP←ARG
262261Saved LCL
263256Saved ARGSys.main
2644000Saved THIS frame
2655000Saved THAT
2660local 0←LCL
2670local 1
2680local 2
2690local 3
2700local 4
271???←SP

- The function prologue is the assembly language code generated for the - "function" VM command. -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Entry to Sys.add12(123)
Pointers
0277SP
1277LCL
2271ARG
34001THIS
45001THAT
Stack
256*Return IP
257-1Saved LCL
258-2Saved ARGSys.init
259-3Saved THIS frame
260-4Saved THAT
261*Return IP
262261Saved LCL
263256Saved ARGSys.main
2644000Saved THIS frame
2655000Saved THAT
2660local 0
267200local 1
26840local 2
2696local 3
2700local 4
271123argument 0←ARG
272*Return IP
273266Saved LCLSys.add12
274261Saved ARG frame
2754001Saved THIS
2765001Saved THAT
277???←LCL, SP
-
- -

- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Before Sys.add12() return
Pointers
0278SP
1277LCL
2271ARG
34002THIS
45002THAT
Stack
256*Return IP
257-1Saved LCL
258-2Saved ARGSys.init
259-3Saved THIS frame
260-4Saved THAT
261*Return IP
262261Saved LCL
263256Saved ARGSys.main
2644000Saved THIS frame
2655000Saved THAT
2660local 0
267200local 1
26840local 2
2696local 3
2700local 4
271123argument 0←ARG
272*Return IP
273266Saved LCLSys.add12
274261Saved ARG frame
2754001Saved THIS
2765001Saved THAT
277135Return value←LCL
278???←SP
-
- - - - - - - - - - - - - - - - - - - - - - - - - - -
After Sys.add12() return
Pointers
0272SP
1266LCL
2261ARG
34001THIS
45001THAT
Stack
256*Return IP
257-1Saved LCL
258-2Saved ARGSys.init
259-3Saved THIS frame
260-4Saved THAT
261*Return IP←ARG
262261Saved LCL
263256Saved ARGSys.main
2644000Saved THIS frame
2655000Saved THAT
2660local 0←LCL
267200local 1
26840local 2
2696local 3
2700local 4
271135Return value
272???←SP
-
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Before Sys.main() return
Pointers
0272SP
1266LCL
2261ARG
34001THIS
45001THAT
Stack
256*Return IP
257-1Saved LCL
258-2Saved ARGSys.init
259-3Saved THIS frame
260-4Saved THAT
261*Return IP←ARG
262261Saved LCL
263256Saved ARGSys.main
2644000Saved THIS frame
2655000Saved THAT
2660local 0←LCL
267200local 1
26840local 2
2696local 3
2700local 4
271246Return value
272???←SP
-
- - - - - - - - - - - - - - - - -
After Sys.main() return
Pointers
0262SP
1261LCL
2256ARG
34000THIS
45000THAT
Stack
256*Return IP←ARG
257-1Saved LCL
258-2Saved ARGSys.init
259-3Saved THIS frame
260-4Saved THAT
261246Return value←LCL
262???←SP
-
- - - - - - - - - - - - - - - -
In Sys.init() halt loop
Pointers
0261SP
1261LCL
2256ARG
34000THIS
45000THAT
Stack
256*Return IP←ARG
257-1Saved LCL
258-2Saved ARGSys.init
259-3Saved THIS frame
260-4Saved THAT
261???←LCL, SP
-
- - - \ No newline at end of file diff --git a/projects/08/FunctionCalls/NestedCall/NestedCallVME.tst b/projects/08/FunctionCalls/NestedCall/NestedCallVME.tst deleted file mode 100644 index 2c689b8..0000000 --- a/projects/08/FunctionCalls/NestedCall/NestedCallVME.tst +++ /dev/null @@ -1,70 +0,0 @@ -// Test file for NestedCall test. - -load Sys.vm, -output-file NestedCall.out, -compare-to NestedCall.cmp, -output-list RAM[0]%D1.6.1 RAM[1]%D1.6.1 RAM[2]%D1.6.1 RAM[3]%D1.6.1 RAM[4]%D1.6.1 RAM[5]%D1.6.1 RAM[6]%D1.6.1; - -set RAM[0] 261, -set RAM[1] 261, -set RAM[2] 256, -set RAM[3] -3, -set RAM[4] -4, -set RAM[5] -1, // test results -set RAM[6] -1, -set RAM[256] 1234, // fake stack frame from call Sys.init -set RAM[257] -1, -set RAM[258] -2, -set RAM[259] -3, -set RAM[260] -4, - -set RAM[261] -1, // Initialize stack to check for local segment -set RAM[262] -1, // being cleared to zero. -set RAM[263] -1, -set RAM[264] -1, -set RAM[265] -1, -set RAM[266] -1, -set RAM[267] -1, -set RAM[268] -1, -set RAM[269] -1, -set RAM[270] -1, -set RAM[271] -1, -set RAM[272] -1, -set RAM[273] -1, -set RAM[274] -1, -set RAM[275] -1, -set RAM[276] -1, -set RAM[277] -1, -set RAM[278] -1, -set RAM[279] -1, -set RAM[280] -1, -set RAM[281] -1, -set RAM[282] -1, -set RAM[283] -1, -set RAM[284] -1, -set RAM[285] -1, -set RAM[286] -1, -set RAM[287] -1, -set RAM[288] -1, -set RAM[289] -1, -set RAM[290] -1, -set RAM[291] -1, -set RAM[292] -1, -set RAM[293] -1, -set RAM[294] -1, -set RAM[295] -1, -set RAM[296] -1, -set RAM[297] -1, -set RAM[298] -1, -set RAM[299] -1, - -set sp 261, -set local 261, -set argument 256, -set this 3000, -set that 4000; - -repeat 50 { - vmstep; -} -output; diff --git a/projects/08/FunctionCalls/NestedCall/Sys.vm b/projects/08/FunctionCalls/NestedCall/Sys.vm deleted file mode 100644 index 8b0b003..0000000 --- a/projects/08/FunctionCalls/NestedCall/Sys.vm +++ /dev/null @@ -1,63 +0,0 @@ -// Sys.vm for NestedCall test. - -// Sys.init() -// -// Calls Sys.main() and stores return value in temp 1. -// Does not return. (Enters infinite loop.) - -function Sys.init 0 -push constant 4000 // test THIS and THAT context save -pop pointer 0 -push constant 5000 -pop pointer 1 -call Sys.main 0 -pop temp 1 -label LOOP -goto LOOP - -// Sys.main() -// -// Sets locals 1, 2 and 3, leaving locals 0 and 4 unchanged to test -// default local initialization to 0. (RAM set to -1 by test setup.) -// Calls Sys.add12(123) and stores return value (135) in temp 0. -// Returns local 0 + local 1 + local 2 + local 3 + local 4 (456) to confirm -// that locals were not mangled by function call. - -function Sys.main 5 -push constant 4001 -pop pointer 0 -push constant 5001 -pop pointer 1 -push constant 200 -pop local 1 -push constant 40 -pop local 2 -push constant 6 -pop local 3 -push constant 123 -call Sys.add12 1 -pop temp 0 -push local 0 -push local 1 -push local 2 -push local 3 -push local 4 -add -add -add -add -return - -// Sys.add12(int n) -// -// Returns n+12. - -function Sys.add12 0 -push constant 4002 -pop pointer 0 -push constant 5002 -pop pointer 1 -push argument 0 -push constant 12 -add -return diff --git a/projects/08/FunctionCalls/SimpleFunction/SimpleFunction.asm b/projects/08/FunctionCalls/SimpleFunction/SimpleFunction.asm deleted file mode 100644 index de3a0da..0000000 --- a/projects/08/FunctionCalls/SimpleFunction/SimpleFunction.asm +++ /dev/null @@ -1,138 +0,0 @@ -(SimpleFunction.test) -@SP -A=M -M=0 -@SP -M=M+1 -@SP -A=M -M=0 -@SP -M=M+1 -@LCL -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -A=M -M=!D -@SP -M=M+1 -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP diff --git a/projects/08/FunctionCalls/SimpleFunction/SimpleFunction.cmp b/projects/08/FunctionCalls/SimpleFunction/SimpleFunction.cmp deleted file mode 100644 index c3ea911..0000000 --- a/projects/08/FunctionCalls/SimpleFunction/SimpleFunction.cmp +++ /dev/null @@ -1,2 +0,0 @@ -| RAM[0] | RAM[1] | RAM[2] | RAM[3] | RAM[4] |RAM[310]| -| 311 | 305 | 300 | 3010 | 4010 | 1196 | diff --git a/projects/08/FunctionCalls/SimpleFunction/SimpleFunction.out b/projects/08/FunctionCalls/SimpleFunction/SimpleFunction.out deleted file mode 100644 index ef72b7a..0000000 --- a/projects/08/FunctionCalls/SimpleFunction/SimpleFunction.out +++ /dev/null @@ -1,2 +0,0 @@ -| RAM[0] | RAM[1] | RAM[2] | RAM[3] | RAM[4] |RAM[310]| -| 311 | 305 | 300 | 3010 | 4010 | 1196 | diff --git a/projects/08/FunctionCalls/SimpleFunction/SimpleFunction.tst b/projects/08/FunctionCalls/SimpleFunction/SimpleFunction.tst deleted file mode 100644 index c7b5905..0000000 --- a/projects/08/FunctionCalls/SimpleFunction/SimpleFunction.tst +++ /dev/null @@ -1,29 +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/08/FunctionCalls/SimpleFunction/SimpleFunction.tst - -load SimpleFunction.asm, -output-file SimpleFunction.out, -compare-to SimpleFunction.cmp, -output-list RAM[0]%D1.6.1 RAM[1]%D1.6.1 RAM[2]%D1.6.1 - RAM[3]%D1.6.1 RAM[4]%D1.6.1 RAM[310]%D1.6.1; - -set RAM[0] 317, -set RAM[1] 317, -set RAM[2] 310, -set RAM[3] 3000, -set RAM[4] 4000, -set RAM[310] 1234, -set RAM[311] 37, -set RAM[312] 1000, -set RAM[313] 305, -set RAM[314] 300, -set RAM[315] 3010, -set RAM[316] 4010, - -repeat 300 { - ticktock; -} - -output; diff --git a/projects/08/FunctionCalls/SimpleFunction/SimpleFunction.vm b/projects/08/FunctionCalls/SimpleFunction/SimpleFunction.vm deleted file mode 100644 index d64a34f..0000000 --- a/projects/08/FunctionCalls/SimpleFunction/SimpleFunction.vm +++ /dev/null @@ -1,16 +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/08/FunctionCalls/SimpleFunction/SimpleFunction.vm - -// Performs a simple calculation and returns the result. -function SimpleFunction.test 2 -push local 0 -push local 1 -add -not -push argument 0 -add -push argument 1 -sub -return diff --git a/projects/08/FunctionCalls/SimpleFunction/SimpleFunction1.asm b/projects/08/FunctionCalls/SimpleFunction/SimpleFunction1.asm deleted file mode 100644 index 7fe71a5..0000000 --- a/projects/08/FunctionCalls/SimpleFunction/SimpleFunction1.asm +++ /dev/null @@ -1,137 +0,0 @@ -(SimpleFunction.test) -@SP -A=M -M=0 -@SP -M=M+1 -@SP -A=M -M=0 -@SP -M=M+1 -@LCL -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -A=M -M=!D -@SP -M=M+1 -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R13 -A=M-1 -A=M -0;JMP -(END) -@END -0;JMP \ No newline at end of file diff --git a/projects/08/FunctionCalls/SimpleFunction/SimpleFunctionVME.tst b/projects/08/FunctionCalls/SimpleFunction/SimpleFunctionVME.tst deleted file mode 100644 index c9267ee..0000000 --- a/projects/08/FunctionCalls/SimpleFunction/SimpleFunctionVME.tst +++ /dev/null @@ -1,29 +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/08/FunctionCalls/SimpleFunction/SimpleFunctionVME.tst - -load SimpleFunction.vm, -output-file SimpleFunction.out, -compare-to SimpleFunction.cmp, -output-list RAM[0]%D1.6.1 RAM[1]%D1.6.1 RAM[2]%D1.6.1 - RAM[3]%D1.6.1 RAM[4]%D1.6.1 RAM[310]%D1.6.1; - -set sp 317, -set local 317, -set argument 310, -set this 3000, -set that 4000, -set argument[0] 1234, -set argument[1] 37, -set argument[2] 9, -set argument[3] 305, -set argument[4] 300, -set argument[5] 3010, -set argument[6] 4010, - -repeat 10 { - vmstep; -} - -output; diff --git a/projects/08/FunctionCalls/StaticsTest/Class1.vm b/projects/08/FunctionCalls/StaticsTest/Class1.vm deleted file mode 100644 index c463537..0000000 --- a/projects/08/FunctionCalls/StaticsTest/Class1.vm +++ /dev/null @@ -1,20 +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/08/FunctionCalls/StaticsTest/Class1.vm - -// Stores two supplied arguments in static[0] and static[1]. -function Class1.set 0 -push argument 0 -pop static 0 -push argument 1 -pop static 1 -push constant 0 -return - -// Returns static[0] - static[1]. -function Class1.get 0 -push static 0 -push static 1 -sub -return diff --git a/projects/08/FunctionCalls/StaticsTest/Class2.vm b/projects/08/FunctionCalls/StaticsTest/Class2.vm deleted file mode 100644 index 94f2946..0000000 --- a/projects/08/FunctionCalls/StaticsTest/Class2.vm +++ /dev/null @@ -1,20 +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/08/FunctionCalls/StaticsTest/Class2.vm - -// Stores two supplied arguments in static[0] and static[1]. -function Class2.set 0 -push argument 0 -pop static 0 -push argument 1 -pop static 1 -push constant 0 -return - -// Returns static[0] - static[1]. -function Class2.get 0 -push static 0 -push static 1 -sub -return diff --git a/projects/08/FunctionCalls/StaticsTest/StaticsTest.asm b/projects/08/FunctionCalls/StaticsTest/StaticsTest.asm deleted file mode 100644 index 2d6f2aa..0000000 --- a/projects/08/FunctionCalls/StaticsTest/StaticsTest.asm +++ /dev/null @@ -1,586 +0,0 @@ -@256 -D=A -@SP -M=D -@RET0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@0 -D=D-A -@ARG -M=D -@Sys.init -0;JMP -(RET0) -(Class2.set) -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@Class2.0 -M=D -@ARG -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@Class2.1 -M=D -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP -(Class2.get) -@Class2.0 -D=M -@SP -A=M -M=D -@SP -M=M+1 -@Class2.1 -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP -(Sys.init) -@6 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@8 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET3 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@2 -D=D-A -@ARG -M=D -@Class1.set -0;JMP -(RET3) -@SP -AM=M-1 -D=M -@5 -M=D -@23 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@15 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET7 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@2 -D=D-A -@ARG -M=D -@Class2.set -0;JMP -(RET7) -@SP -AM=M-1 -D=M -@5 -M=D -@RET9 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@0 -D=D-A -@ARG -M=D -@Class1.get -0;JMP -(RET9) -@RET10 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@0 -D=D-A -@ARG -M=D -@Class2.get -0;JMP -(RET10) -(Sys.init$WHILE) -@Sys.init$WHILE -0;JMP -(Class1.set) -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@Class1.0 -M=D -@ARG -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@Class1.1 -M=D -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP -(Class1.get) -@Class1.0 -D=M -@SP -A=M -M=D -@SP -M=M+1 -@Class1.1 -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP diff --git a/projects/08/FunctionCalls/StaticsTest/StaticsTest.cmp b/projects/08/FunctionCalls/StaticsTest/StaticsTest.cmp deleted file mode 100644 index 5589f1e..0000000 --- a/projects/08/FunctionCalls/StaticsTest/StaticsTest.cmp +++ /dev/null @@ -1,2 +0,0 @@ -| RAM[0] |RAM[261]|RAM[262]| -| 263 | -2 | 8 | diff --git a/projects/08/FunctionCalls/StaticsTest/StaticsTest.out b/projects/08/FunctionCalls/StaticsTest/StaticsTest.out deleted file mode 100644 index 309f058..0000000 --- a/projects/08/FunctionCalls/StaticsTest/StaticsTest.out +++ /dev/null @@ -1,2 +0,0 @@ -| RAM[0] |RAM[261]|RAM[262]| -| 263 | -2 | 8 | diff --git a/projects/08/FunctionCalls/StaticsTest/StaticsTest.tst b/projects/08/FunctionCalls/StaticsTest/StaticsTest.tst deleted file mode 100644 index 1b9194e..0000000 --- a/projects/08/FunctionCalls/StaticsTest/StaticsTest.tst +++ /dev/null @@ -1,17 +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/08/FunctionCalls/StaticsTest/StaticsTest.tst - -load StaticsTest.asm, -output-file StaticsTest.out, -compare-to StaticsTest.cmp, -output-list RAM[0]%D1.6.1 RAM[261]%D1.6.1 RAM[262]%D1.6.1; - -set RAM[0] 256, - -repeat 2500 { - ticktock; -} - -output; diff --git a/projects/08/FunctionCalls/StaticsTest/StaticsTestVME.tst b/projects/08/FunctionCalls/StaticsTest/StaticsTestVME.tst deleted file mode 100644 index 130ba66..0000000 --- a/projects/08/FunctionCalls/StaticsTest/StaticsTestVME.tst +++ /dev/null @@ -1,17 +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/08/FunctionCalls/StaticsTest/StaticsTestVME.tst - -load, // loads all the VM files from the current directory. -output-file StaticsTest.out, -compare-to StaticsTest.cmp, -output-list RAM[0]%D1.6.1 RAM[261]%D1.6.1 RAM[262]%D1.6.1; - -set sp 261, - -repeat 36 { - vmstep; -} - -output; diff --git a/projects/08/FunctionCalls/StaticsTest/Sys.vm b/projects/08/FunctionCalls/StaticsTest/Sys.vm deleted file mode 100644 index 3708322..0000000 --- a/projects/08/FunctionCalls/StaticsTest/Sys.vm +++ /dev/null @@ -1,20 +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/08/FunctionCalls/StaticsTest/Sys.vm - -// Tests that different functions, stored in two different -// class files, manipulate the static segment correctly. -function Sys.init 0 -push constant 6 -push constant 8 -call Class1.set 2 -pop temp 0 // Dumps the return value -push constant 23 -push constant 15 -call Class2.set 2 -pop temp 0 // Dumps the return value -call Class1.get 0 -call Class2.get 0 -label WHILE -goto WHILE diff --git a/projects/08/ProgramFlow/BasicLoop/BasicLoop.asm b/projects/08/ProgramFlow/BasicLoop/BasicLoop.asm deleted file mode 100644 index b2e42a7..0000000 --- a/projects/08/ProgramFlow/BasicLoop/BasicLoop.asm +++ /dev/null @@ -1,133 +0,0 @@ -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@0 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -($LOOP_START) -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@0 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@0 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@$LOOP_START -D;JNE -@LCL -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 diff --git a/projects/08/ProgramFlow/BasicLoop/BasicLoop.cmp b/projects/08/ProgramFlow/BasicLoop/BasicLoop.cmp deleted file mode 100644 index 00d35d2..0000000 --- a/projects/08/ProgramFlow/BasicLoop/BasicLoop.cmp +++ /dev/null @@ -1,2 +0,0 @@ -| RAM[0] |RAM[256]| -| 257 | 6 | diff --git a/projects/08/ProgramFlow/BasicLoop/BasicLoop.out b/projects/08/ProgramFlow/BasicLoop/BasicLoop.out deleted file mode 100644 index 1786c7c..0000000 --- a/projects/08/ProgramFlow/BasicLoop/BasicLoop.out +++ /dev/null @@ -1,2 +0,0 @@ -| RAM[0] |RAM[256]| -| 257 | 6 | diff --git a/projects/08/ProgramFlow/BasicLoop/BasicLoop.tst b/projects/08/ProgramFlow/BasicLoop/BasicLoop.tst deleted file mode 100644 index 50ca118..0000000 --- a/projects/08/ProgramFlow/BasicLoop/BasicLoop.tst +++ /dev/null @@ -1,20 +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/08/ProgramFlow/BasicLoop/BasicLoop.tst - -load BasicLoop.asm, -output-file BasicLoop.out, -compare-to BasicLoop.cmp, -output-list RAM[0]%D1.6.1 RAM[256]%D1.6.1; - -set RAM[0] 256, -set RAM[1] 300, -set RAM[2] 400, -set RAM[400] 3, - -repeat 600 { - ticktock; -} - -output; diff --git a/projects/08/ProgramFlow/BasicLoop/BasicLoop.vm b/projects/08/ProgramFlow/BasicLoop/BasicLoop.vm deleted file mode 100644 index 2d63f13..0000000 --- a/projects/08/ProgramFlow/BasicLoop/BasicLoop.vm +++ /dev/null @@ -1,22 +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/08/ProgramFlow/BasicLoop/BasicLoop.vm - -// Computes the sum 1 + 2 + ... + argument[0] and pushes the -// result onto the stack. Argument[0] is initialized by the test -// script before this code starts running. -push constant 0 -pop local 0 // initializes sum = 0 -label LOOP_START -push argument 0 -push local 0 -add -pop local 0 // sum = sum + counter -push argument 0 -push constant 1 -sub -pop argument 0 // counter-- -push argument 0 -if-goto LOOP_START // If counter > 0, goto LOOP_START -push local 0 diff --git a/projects/08/ProgramFlow/BasicLoop/BasicLoopVME.tst b/projects/08/ProgramFlow/BasicLoop/BasicLoopVME.tst deleted file mode 100644 index 237fdff..0000000 --- a/projects/08/ProgramFlow/BasicLoop/BasicLoopVME.tst +++ /dev/null @@ -1,20 +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/08/ProgramFlow/BasicLoop/BasicLoopVME.tst - -load BasicLoop.vm, -output-file BasicLoop.out, -compare-to BasicLoop.cmp, -output-list RAM[0]%D1.6.1 RAM[256]%D1.6.1; - -set sp 256, -set local 300, -set argument 400, -set argument[0] 3, - -repeat 33 { - vmstep; -} - -output; diff --git a/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.asm b/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.asm deleted file mode 100644 index 3436cef..0000000 --- a/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.asm +++ /dev/null @@ -1,234 +0,0 @@ -@ARG -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@4 -M=D -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@0 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@1 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@2 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@0 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -($MAIN_LOOP_START) -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@$COMPUTE_ELEMENT -D;JNE -@$END_PROGRAM -0;JMP -($COMPUTE_ELEMENT) -@THAT -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@2 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@4 -D=M -@SP -A=M -M=D -@SP -M=M+1 -@1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@4 -M=D -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@0 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@$MAIN_LOOP_START -0;JMP -($END_PROGRAM) diff --git a/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.cmp b/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.cmp deleted file mode 100644 index c262a4b..0000000 --- a/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.cmp +++ /dev/null @@ -1,2 +0,0 @@ -|RAM[3000]|RAM[3001]|RAM[3002]|RAM[3003]|RAM[3004]|RAM[3005]| -| 0 | 1 | 1 | 2 | 3 | 5 | diff --git a/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.out b/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.out deleted file mode 100644 index 304e7c1..0000000 --- a/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.out +++ /dev/null @@ -1,2 +0,0 @@ -|RAM[3000]|RAM[3001]|RAM[3002]|RAM[3003]|RAM[3004]|RAM[3005]| -| 0 | 1 | 1 | 2 | 3 | 5 | diff --git a/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.tst b/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.tst deleted file mode 100644 index 07df2b9..0000000 --- a/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.tst +++ /dev/null @@ -1,22 +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/08/ProgramFlow/FibonacciSeries/FibonacciSeries.tst - -load FibonacciSeries.asm, -output-file FibonacciSeries.out, -compare-to FibonacciSeries.cmp, -output-list RAM[3000]%D1.6.2 RAM[3001]%D1.6.2 RAM[3002]%D1.6.2 - RAM[3003]%D1.6.2 RAM[3004]%D1.6.2 RAM[3005]%D1.6.2; - -set RAM[0] 256, -set RAM[1] 300, -set RAM[2] 400, -set RAM[400] 6, -set RAM[401] 3000, - -repeat 1100 { - ticktock; -} - -output; diff --git a/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.vm b/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.vm deleted file mode 100644 index 6a643b6..0000000 --- a/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.vm +++ /dev/null @@ -1,49 +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/08/ProgramFlow/FibonacciSeries/FibonacciSeries.vm - -// Puts the first argument[0] elements of the Fibonacci series -// in the memory, starting in the address given in argument[1]. -// Argument[0] and argument[1] are initialized by the test script -// before this code starts running. - -push argument 1 -pop pointer 1 // that = argument[1] - -push constant 0 -pop that 0 // first element in the series = 0 -push constant 1 -pop that 1 // second element in the series = 1 - -push argument 0 -push constant 2 -sub -pop argument 0 // num_of_elements -= 2 (first 2 elements are set) - -label MAIN_LOOP_START - -push argument 0 -if-goto COMPUTE_ELEMENT // if num_of_elements > 0, goto COMPUTE_ELEMENT -goto END_PROGRAM // otherwise, goto END_PROGRAM - -label COMPUTE_ELEMENT - -push that 0 -push that 1 -add -pop that 2 // that[2] = that[0] + that[1] - -push pointer 1 -push constant 1 -add -pop pointer 1 // that += 1 - -push argument 0 -push constant 1 -sub -pop argument 0 // num_of_elements-- - -goto MAIN_LOOP_START - -label END_PROGRAM diff --git a/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries1.asm b/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries1.asm deleted file mode 100644 index 68a4c8e..0000000 --- a/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries1.asm +++ /dev/null @@ -1,241 +0,0 @@ -@256 -D=A -@SP -M=D -@ARG -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@4 -M=D -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@0 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@1 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@2 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@0 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -(MAIN_LOOP_START) -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@COMPUTE_ELEMENT -D;JNE -@END_PROGRAM -0;JMP -(COMPUTE_ELEMENT) -@THAT -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@2 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@4 -D=M -@SP -A=M -M=D -@SP -M=M+1 -@1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@4 -M=D -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@0 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@MAIN_LOOP_START -0;JMP -(END_PROGRAM) -(END) -@END -0;JMP \ No newline at end of file diff --git a/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeriesVME.tst b/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeriesVME.tst deleted file mode 100644 index 243f31b..0000000 --- a/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeriesVME.tst +++ /dev/null @@ -1,22 +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/08/ProgramFlow/FibonacciSeries/FibonacciSeriesVME.tst - -load FibonacciSeries.vm, -output-file FibonacciSeries.out, -compare-to FibonacciSeries.cmp, -output-list RAM[3000]%D1.6.2 RAM[3001]%D1.6.2 RAM[3002]%D1.6.2 - RAM[3003]%D1.6.2 RAM[3004]%D1.6.2 RAM[3005]%D1.6.2; - -set sp 256, -set local 300, -set argument 400, -set argument[0] 6, -set argument[1] 3000, - -repeat 73 { - vmstep; -} - -output; diff --git a/projects/08/VMTranslator b/projects/08/VMTranslator deleted file mode 100755 index 2b04f49..0000000 Binary files a/projects/08/VMTranslator and /dev/null differ diff --git a/projects/08/VMTranslator.hi b/projects/08/VMTranslator.hi deleted file mode 100644 index 66e0a40..0000000 Binary files a/projects/08/VMTranslator.hi and /dev/null differ diff --git a/projects/08/VMTranslator.hs b/projects/08/VMTranslator.hs deleted file mode 100644 index d5a7075..0000000 --- a/projects/08/VMTranslator.hs +++ /dev/null @@ -1,139 +0,0 @@ ---usage: ./VMTranslator path/to/dir/ ---will produce path/to/dir/dir.asm from path/to/dir/*.vm -import Data.Char (toUpper) -import Data.List.Split (splitOn) -import System.Environment (getArgs) -import Data.Maybe (fromJust) -import Data.List (elemIndex) -import System.Directory (listDirectory) - ---preamble = "@256\nD=A\n@SP\nM=D\n" ---For ProgramFlow and SimpleFunction preamble should be set as "" ---preamble = "" ---For StaticsTest and FibonacciElement, preamble should be setSP ++ callInit -preamble = setSP ++ callInit - where setSP = "@256\nD=A\n@SP\nM=D\n" - callInit = parse' "call" ["Sys.init", "0"] 0 "" "" - ---epilogue = "(END)\n@END\n0;JMP" -epilogue = "" - --- parse' command restOfCommand vmLineNumber fileName functionName = asm code -parse' :: [Char] -> [[Char]] -> Int -> [Char] -> [Char] -> [Char] - -parse' "return" [] _ _ _ = backupLCL ++ backupRet ++ popToARG ++ moveSP ++ restore "THAT" - ++ restore "THIS" ++ restore "ARG" ++ restore "LCL" - ++ gotoRet - where backupLCL = "@LCL\nD=M\n@R13\nM=D\n" - backupRet = "@5\nA=D-A\nD=M\n@R14\nM=D\n" - popToARG = pop "M" ++ "@ARG\nA=M\nM=D\n" - moveSP = "@ARG\nD=M+1\n@SP\nM=D\n" - restore name = "@R13\nAM=M-1\nD=M\n@" ++ name ++ "\nM=D\n" - gotoRet = "@R14\nA=M\n0;JMP\n" - -parse' op [] n fileName _ - | op `elem` ["add", "sub", "and", "or"] = pop "M" ++ pop ('M':(f op):"D") ++ push "D" - | op `elem` ["eq", "gt", "lt"] = pop "M" ++ pop "M-D" ++ ifThenElse op n fileName - | otherwise = pop "M" ++ push (f op:"D") - where f "add" = '+'; f "sub" = '-'; f "and" = '&'; - f "or" = '|'; f "neg" = '-'; f "not" = '!' - -parse' "push" ["constant", x] _ _ _ = "@" ++ x ++ "\nD=A\n" ++ push "D" - -parse' cmd [seg, x] _ _ _ | seg `elem` ["local", "argument", "this", "that"] = - case cmd of - "push" -> getAddr seg x ++ "A=D\nD=M\n" ++ push "D" - "pop" -> getAddr seg x ++ "@R13\nM=D\n" ++ pop "M" ++ "@R13\nA=M\nM=D\n" - -parse' cmd [seg, x] _ _ _ | seg `elem` ["pointer", "temp"] = - case cmd of - "push" -> getAddr' seg x ++ "D=M\n" ++ push "D" - "pop" -> pop "M" ++ getAddr' seg x ++ "M=D\n" - -parse' cmd ["static", x] _ filename _ = - case cmd of - "push" -> getAddr'' x filename ++ "D=M\n" ++ push "D" - "pop" -> pop "M" ++ getAddr'' x filename ++ "M=D\n" - -parse' "label" [x] _ _ fName = "(" ++ fName ++ "$" ++ x ++ ")\n" - -parse' "goto" [x] _ _ fName = "@" ++ fName ++ "$" ++ x ++ "\n0;JMP\n" - -parse' "if-goto" [x] _ _ fName = pop "M" ++ "@" ++ fName ++ "$" ++ x ++ "\nD;JNE\n" - -parse' "function" [f, n] _ _ _ = "(" ++ f ++ ")\n" ++ (mconcat $ replicate (read n) $ push "0") - -parse' "call" [f, m] n _ _ = pushRet ++ save "LCL" ++ save "ARG" ++ save "THIS" - ++ save "THAT" ++ setLCL ++ setARG ++ gotoF ++ placeRet - where pushRet = "@RET" ++ show n ++ "\nD=A\n" ++ push "D" - save x = "@" ++ x ++ "\nD=M\n" ++ push "D" - setLCL = "@SP\nD=M\n@LCL\nM=D\n" - setARG = "@5\nD=D-A\n@" ++ m ++ "\nD=D-A\n@ARG\nM=D\n" - placeRet = "(RET" ++ show n ++ ")\n" - gotoF = "@" ++ f ++ "\n0;JMP\n" ---To do the return-addr: generate label RET582 if say n==582, place the label after the goto f jump - -getAddr seg x = "@" ++ seg2Lab seg ++ "\nD=M\n@" ++ x ++ "\nD=A+D\n" - -getAddr' seg x = "@" ++ show (read x + (if seg == "pointer" then 3 else 5)) ++ "\n" - -getAddr'' x filename = "@" ++ filename ++ "." ++ x ++ "\n" - -seg2Lab seg = case seg of - "local" -> "LCL" - "argument" -> "ARG" - "this" -> "THIS" - "that" -> "THAT" - -push :: [Char] -> [Char] -push xs = "@SP\nA=M\nM=" ++ xs ++ "\n@SP\nM=M+1\n" - --- should change @label to @IFlabel -ifThenElse :: [Char] -> Int -> [Char] -> [Char] -ifThenElse cond n fileName = "@IF" ++ label ++ "\nD;J" ++ cond' ++ "\n" ++ push "0" - ++ "@ENDIF" ++ label ++ "\n0;JMP\n(IF" ++ label ++ ")\n" - ++ push "-1" ++ "(ENDIF" ++ label ++ ")\n" - where label = fileName ++ show n - cond' = toUpper <$> cond - -pop :: [Char] -> [Char] -pop xs = "@SP\nAM=M-1\nD=" ++ xs ++ "\n" - -parseline :: [[Char]] -> Int -> [Char] -> [Char] -> [Char] -> [Char] -parseline [] _ acc _ _ = acc -parseline (line:lines) n acc filename funName = parseline lines (n + 1) (acc ++ parse' cmd target n filename funName') filename funName' - where cmd:target = words line - funName' = if cmd == "function" then head target else funName - -stripJunk :: [Char] -> [[Char]] -stripJunk = filter (not . isEmptyLine) . fmap (head . splitOn "//") . lines . replCrWithNl - -isEmptyLine :: [Char] -> Bool -isEmptyLine = null . filter (not . flip elem " \t") - -parseCode :: [Char] -> [Char] -> [Char] -parseCode xs filename = (parseline (stripJunk xs) 0 "" filename "") - -parseCodes :: [[Char]] -> [[Char]] -> [Char] -parseCodes codes filenames = preamble ++ (mconcat $ zipWith parseCode codes filenames) ++ epilogue - -replCrWithNl :: [Char] -> [Char] -replCrWithNl = fmap cr2nl - where cr2nl '\r' = '\n' - cr2nl c = c - -lastSplit c xs = (take (prefix - 1) xs, drop prefix xs) - where prefix = length xs - (fromJust . elemIndex c . reverse) xs - - --- assuming the input is a dir with a trailing '/' -main = do - dir <- head <$> getArgs - filesWODir <- filter isVMfile <$> listDirectory dir - let vmFiles = (dir++) <$> filesWODir - let ofPath = dir ++ (snd $ lastSplit '/' $ init dir) ++ ".asm" - let filenames = removeExt <$> filesWODir - codes <- sequence $ readFile <$> vmFiles - writeFile ofPath $ parseCodes codes filenames - where isVMfile xs = drop (length xs - 3) xs == ".vm" - removeExt xs = take (length xs - 3) xs diff --git a/projects/08/VMTranslator.o b/projects/08/VMTranslator.o deleted file mode 100644 index 1d984cf..0000000 Binary files a/projects/08/VMTranslator.o and /dev/null differ -- cgit v1.2.3