Showing posts with label assembly language. Show all posts
Showing posts with label assembly language. Show all posts

Saturday, March 11, 2017

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

Nand2Tetris Screen Addressing

http://www.nand2tetris.org/lectures/PDF/lecture%2005%20computer%20architecture.pdf


So, you have 256 rows each 1 pixel thick.
You have 32 columns each 16 bits thick, or 512 columns, each 1 pixel thick.

So, to set pixel at x,y where x,y within (0-511, 0-255) :

Set (black) the y % 16 bit of the word addressed by Screen[ x*32 + y/16]

where Screen[X] implies memory address 16384 + X.

Friday, March 10, 2017

nand2tetris Hilf Help Shimon!

I load a program into the CPU emulator and nothing happens.

Might need to drag the lower right corners south-east a little to see the status line - you'll probably see a message there. Why the hell they don't have a View > Parser Log through the Menu just beats me. But hey, it's free :)

I do

@LOOP
JMP

and it doesn't like it. Ya, coz you HAVE to supply the core part of a C (compute) instruction always - only the jump and destination are optional. So, in this case, just do

0, JMP