Showing posts with label hack computer. Show all posts
Showing posts with label hack computer. Show all posts

Saturday, April 15, 2017

Nand2Tetris Common Issues

../../tools/JackCompiler.bat Fraction/

Compiling "C:\Users....\09\Fraction\"
Could not find file or directory: C:\Users..

Problem - the '/' provided along with directory name. Yes, lame, I know :) Shimon's response : our purpose is didactic, not production :)

while( 1 ) {

}

use while( true ) ...

Aha - API claims drawCircle can handle radius of 181... Nice try there. I just found out you have to stay below 128 (127 is ok)

In Circle.jack (line 23): In subroutine PlotCircle: Expected (

Most likely reason - you used a "do" when you meant to use "let" :) Don't you miss Perl's errors/warnings :) ?

Gotcha - you HAVE to declare ALL variables before any "action".

var int xyz;
let xyz = 0;
var int pqr;

won't fly :)

Saturday, April 8, 2017

Shame on Yaron Ukrainitz

Sick

AM = M - 1

works. But

MA = M - 1

gives

In line XYZ, destination expected.

Sunday, March 12, 2017

Nand2Tetris Hack Divide By 2 (Right Shift)

// Divides R0 by 2 and stores the dividend in R1 and remainder in R2
// (R0, R1, R2 refer to RAM[0], RAM[1], and RAM[2], respectively.)

// how : counter goes from 2 to 32768 ( doubling each time )
// start with 1 and dump result of the AND in R2
// start off setting R1 to 0 and after that, based on result of the AND of
// counter with R0, you either OR R1 with counter or do nothing

@R1
M = 0
D = 1
@R0
D = M & D
@R2
M = D // remainder captured
@lagcount
M = 1
@2
D = A
@counter
M = D

(LOOP)
@R0
D = M & D // we're expecting D (pre) to already have the counter value based on knowing our code
@NO_ACTION
D, JEQ
@lagcount // else, we need to OR R1 with the lagging counter
D = M
@R1
M = M | D
(NO_ACTION)
@16384 // can only load a 15 bit number :)
D = A
D = D + A
@counter
D = M - D
@END
D, JEQ
// else, we need to double counter and double lagcount
@lagcount
D = M
M = M + D
@counter
D = M
MD = M + D

@LOOP
0, JMP

(END)
@END
0, JMP

Saturday, March 11, 2017

Shimon : Once Again I Have to Remind You..


that, if you don't understand this code, you have to stop and convince yourself that you understand it.

Make sure that you understand this intricate business of indirect addressing using the A register.

Nand2Tetris Hack Assembly Language Divide

// divide.asm
// Divides R0 by R1 and stores the dividend in R2 and remainder in R3
// (R0, R1, R2 refer to RAM[0], RAM[1], and RAM[2], respectively.)

@R2
M = 0
@R3
M = 0
@R0
D = M
@END
D, JEQ
@store
M = D // store to restore
(LOOP)
@R1
D = D - M
@REMAINDER
D, JLT
@R2
M = M + 1
@EVENLY
D, JEQ
@LOOP
0, JMP

(REMAINDER)
@R1
D = D + M
@R3
M = D
(EVENLY)
@store
D = M
@R0
M = D

(END)
@END
0, JMP