Showing posts with label VMtranslator. Show all posts
Showing posts with label VMtranslator. Show all posts

Saturday, April 8, 2017

Handy Perl One Liner for Debugging Hack Assembly Language Output

What should you do, if you'd rather see this

0 : // function Class1.set 0
0 : (Class1.set)
0 : // push argument 0
0 : @0
1 : D = A
2 : @ARG
3 : A = M + D
4 : D = M
5 :
5 : @SP
6 : AM = M + 1
7 : A = A - 1

instead of this :

// function Class1.set 0
(Class1.set)
// push argument 0
@0
D = A
@ARG
A = M + D
D = M

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

????

perl -n -e 'BEGIN{$ln=0} print "$ln : " and print; $ln++ unless ( m#^\h*\r?$|^\(|^\h*//# );'

That's what! Thank you Larry Perl - please teach Guido van Rossum something..

Shame on Yaron Ukrainitz

Sick

AM = M - 1

works. But

MA = M - 1

gives

In line XYZ, destination expected.

Sunday, April 2, 2017

Thanks Yaron Ukrainotz : Unexpected End of Line

In line 1 : Unexpected end of line

Okay, not hard to debug, but would be easier if you point out that you expect a constant after "@" in line so and so :)

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:) ?)