Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions nand2tetris/projects/7/VMTranslator/docs/pushConstant.md
Original file line number Diff line number Diff line change
@@ -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
```
20 changes: 20 additions & 0 deletions nand2tetris/projects/7/VMTranslator/docs/pushPointer.md
Original file line number Diff line number Diff line change
@@ -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
```
14 changes: 14 additions & 0 deletions nand2tetris/projects/7/VMTranslator/docs/pushSegment.md
Original file line number Diff line number Diff line change
@@ -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
```
26 changes: 26 additions & 0 deletions nand2tetris/projects/7/VMTranslator/docs/pushStatic.md
Original file line number Diff line number Diff line change
@@ -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
```
22 changes: 22 additions & 0 deletions nand2tetris/projects/7/VMTranslator/docs/pushTemp.md
Original file line number Diff line number Diff line change
@@ -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
```