diff --git a/nand2tetris/projects/7/VMTranslator/docs/pushConstant.md b/nand2tetris/projects/7/VMTranslator/docs/pushConstant.md new file mode 100644 index 0000000..448677d --- /dev/null +++ b/nand2tetris/projects/7/VMTranslator/docs/pushConstant.md @@ -0,0 +1,10 @@ +`push constant i` +---- + +Output +---- +``` +D <- i # D_eq_i.asm +RAM[SP] <- D # RAM_SP_eq_D.asm +SP++ # SPpp.asm +``` \ No newline at end of file diff --git a/nand2tetris/projects/7/VMTranslator/docs/pushPointer.md b/nand2tetris/projects/7/VMTranslator/docs/pushPointer.md new file mode 100644 index 0000000..0e03cdb --- /dev/null +++ b/nand2tetris/projects/7/VMTranslator/docs/pushPointer.md @@ -0,0 +1,20 @@ +`push pointer i` +---- + +For `pointer` we get the _address_ pointed to by THIS/THAT. + +We translate +* `pointer 0` to `THIS` and +* `pointer 1` to `THAT`. + +Store it in `segmentPointer`. + +Output +---- + +``` +addr <- segmentPointer # D_eq_RAM_i.asm +D <- RAM[addr] # ^-- +RAM[SP] <- D # RAM_SP_eq_D.asm +SP++ # SPpp.asm +``` \ No newline at end of file diff --git a/nand2tetris/projects/7/VMTranslator/docs/pushSegment.md b/nand2tetris/projects/7/VMTranslator/docs/pushSegment.md new file mode 100644 index 0000000..5ae97f2 --- /dev/null +++ b/nand2tetris/projects/7/VMTranslator/docs/pushSegment.md @@ -0,0 +1,14 @@ +`push segment i` +---- + +where `segment in ["local", "argument", "this", "that"]` + +Output +---- + +``` +addr <- segmentPointer + i # D_eq_RAM_segmentPointer_p_i.asm +D <- RAM[addr] # ^-- +RAM[SP] <- D # RAM_SP_eq_D.asm +SP++ # SPpp.asm +``` \ No newline at end of file diff --git a/nand2tetris/projects/7/VMTranslator/docs/pushStatic.md b/nand2tetris/projects/7/VMTranslator/docs/pushStatic.md new file mode 100644 index 0000000..658ca4b --- /dev/null +++ b/nand2tetris/projects/7/VMTranslator/docs/pushStatic.md @@ -0,0 +1,26 @@ +`push static i` +---- + +<<<<<<< Updated upstream +For `static` we set `index = "Filename.i"`, hence all we have to do is `D <- Filename.i`. + +This also means `push static i` is equivalent to `push segment i` documented in [`pushSegment.md`](pushSegment.md). +======= +For `static` we set `index = "filename.i"`, hence what we have to do is `D <- RAM[filename.i]`. +>>>>>>> Stashed changes + +Output +---- + +``` +<<<<<<< Updated upstream +D <- i # D_eq_i.asm +RAM[SP] <- RAM[D] # RAM_SP_eq_RAM_D.asm +SP++ # SPpp.asm +======= +addr <- i # D_eq_RAM_i.asm +D <- RAM[addr] # ^-- +RAM[SP] <- D # RAM_SP_eq_D.asm +SP++ # SPpp.asm +>>>>>>> Stashed changes +``` \ No newline at end of file diff --git a/nand2tetris/projects/7/VMTranslator/docs/pushTemp.md b/nand2tetris/projects/7/VMTranslator/docs/pushTemp.md new file mode 100644 index 0000000..3cffe5e --- /dev/null +++ b/nand2tetris/projects/7/VMTranslator/docs/pushTemp.md @@ -0,0 +1,22 @@ +`push temp i` +---- + +`RAM[SP] <- RAM[temp + i]` + +temp is realized as 5 in the Hack language, so +`RAM[SP] <- RAM[5 + i]` + +In the function `writePushPop` we do this by setting `i = temp + i`: +``` +i += 5 + i +``` + +So the final version must be: + +Output +---- +``` +D = i # D_eq_i.asm +RAM[SP] <- RAM[D] # RAM_SP_eq_RAM_D.asm +SP++ # SPpp.asm +``` \ No newline at end of file