Showing posts with label push. Show all posts
Showing posts with label push. Show all posts

Saturday, March 25, 2017

Nand2Tetris 2 : Project 07 Cheat Sheet

If you're like me wondering if documentation for project 7 could be improved - the answer is a resounding yes. Do C_ARITHMETIC commands include the logical ones? YES!! Book says so clearly on Pg 127. But, you can watch the videos twice and still be left with this q.

How about implementing the gt, lt, eq? You have to use jumps, but how do you do that - you're putting out code with a tonne of @DONE's.

And remember (?), the VM represents true as -1 or 0xFFFF and not 1 :) How should you know and what significance does this have? I don't know..

Tip : if using python, you should use raw strings (r prefix) for the match pattern so you can pass special tokens to the regex engine using backslashes that don't get interpreted by the parser itself. (Is it poss for me to confuse you more:) ?)

Saturday, March 18, 2017

Shimon's More Efficient Push - Nice

In the video, where he does push constant 17, he shows

@17
D=A
@SP
A=M
M=D
@SP
M=M+1

Notice that needs 3 A instructions. But, if you pay attention, during the demo, with BasicTest.vm, for  push constant 10, his implementation is :

@10
D=A
@SP
AM=M+1
A=A-1
M=D

Saved an instruction! Nice. Ha - did you think Stuxnet was easy to build my man? Truly, since he scrolls down in his ASM file, he's given you the implementation of "pop argument 2" and so it should be okay to put that down here - but that would be mean :)

Not that they're hard to implement, but he's given you add and sub as well :) Both cute, and using 5 instructions each. Booleans are super easy. For the conditionals, you'll have to use the jumps to conditionally write the appropriate value to the stack.