Sick
AM = M - 1
works. But
MA = M - 1
gives
In line XYZ, destination expected.
Showing posts with label hack assembly language. Show all posts
Showing posts with label hack assembly language. Show all posts
Saturday, April 8, 2017
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 :)
Okay, not hard to debug, but would be easier if you point out that you expect a constant after "@" in line so and so :)
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
// (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.
Sunday, June 5, 2016
Subscribe to:
Posts (Atom)