From e5407ed9844c814cb0cbe48cf21707d054a78244 Mon Sep 17 00:00:00 2001 From: ATherkel Date: Sat, 18 May 2024 18:54:11 +0200 Subject: [PATCH 1/6] Create pushTemp.md --- .../projects/7/VMTranslator/docs/pushTemp.md | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 nand2tetris/projects/7/VMTranslator/docs/pushTemp.md 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 From af6434e231bada56afe0fdb2e579081c0221ec7b Mon Sep 17 00:00:00 2001 From: ATherkel Date: Sat, 18 May 2024 18:54:16 +0200 Subject: [PATCH 2/6] Create pushSegment.md --- .../projects/7/VMTranslator/docs/pushSegment.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 nand2tetris/projects/7/VMTranslator/docs/pushSegment.md 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 From 3bfaec254a27fa9b752857e5f74cd0cd2c59f0c4 Mon Sep 17 00:00:00 2001 From: ATherkel Date: Sat, 18 May 2024 18:54:20 +0200 Subject: [PATCH 3/6] Create pushConstant.md --- .../projects/7/VMTranslator/docs/pushConstant.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 nand2tetris/projects/7/VMTranslator/docs/pushConstant.md 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 From 112e05ff64fe71c2809358fe03e05175d390267d Mon Sep 17 00:00:00 2001 From: ATherkel Date: Sat, 18 May 2024 18:55:21 +0200 Subject: [PATCH 4/6] Create pushStatic.md --- .../projects/7/VMTranslator/docs/pushStatic.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 nand2tetris/projects/7/VMTranslator/docs/pushStatic.md diff --git a/nand2tetris/projects/7/VMTranslator/docs/pushStatic.md b/nand2tetris/projects/7/VMTranslator/docs/pushStatic.md new file mode 100644 index 0000000..4042d21 --- /dev/null +++ b/nand2tetris/projects/7/VMTranslator/docs/pushStatic.md @@ -0,0 +1,15 @@ +`push static i` +---- + +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). + +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 From a3a53b880100b0c25678a2c17a1c00158adf9077 Mon Sep 17 00:00:00 2001 From: ATherkel Date: Sun, 19 May 2024 12:21:21 +0200 Subject: [PATCH 5/6] Create pushPointer.md --- .../7/VMTranslator/docs/pushPointer.md | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 nand2tetris/projects/7/VMTranslator/docs/pushPointer.md 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 From ea0de73e6bb77b71bc311e52df2c1c3cfd1ad735 Mon Sep 17 00:00:00 2001 From: ATherkel Date: Sun, 19 May 2024 12:23:04 +0200 Subject: [PATCH 6/6] Update pushStatic.md --- .../projects/7/VMTranslator/docs/pushStatic.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/nand2tetris/projects/7/VMTranslator/docs/pushStatic.md b/nand2tetris/projects/7/VMTranslator/docs/pushStatic.md index 4042d21..658ca4b 100644 --- a/nand2tetris/projects/7/VMTranslator/docs/pushStatic.md +++ b/nand2tetris/projects/7/VMTranslator/docs/pushStatic.md @@ -1,15 +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