Question About Screen Memory Map

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Question About Screen Memory Map

Jatudrea
I'm having trouble understanding how to manipulate the screen memory map.  I copied over the rectangle.asm program demonstrated in one of the lectures (it's viewable on Coursera), and am trying to get it to draw pixels black in a further rightwards column.  So far, it just tells me that the number I enter into the A data register is an illegal address.  Does anyone know how I could do this?

I'm going to try to insert the relevant code below as an image; I hope it comes through properly.

The relevant code
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question About Screen Memory Map

ybakos
The program does something specific, and I believe uses a finite loop, so if you just change a number, such as the starting address of @SCREEN to @21600, your loop counter will cause the program to use addresses outside of the bounds of the screen's memory map.

In other words, changing @SCREEN to @21600 will cause an error unless you change other aspects of the program.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question About Screen Memory Map

Jatudrea
Well yes, I see that I'm not getting the results that I want.  What I am asking is what do I need to do so that I do succeed in coloring more than just the leftmost column of the screen?

On Tue, Jun 28, 2016 at 4:19 PM, ybakos [via Nand2Tetris Questions and Answers Forum] <[hidden email]> wrote:
The program does something specific, and I believe uses a finite loop, so if you just change a number, such as the starting address of @SCREEN to @21600, your loop counter will cause the program to use addresses outside of the bounds of the screen's memory map.

In other words, changing @SCREEN to @21600 will cause an error unless you change other aspects of the program.



If you reply to this email, your message will be added to the discussion below:
http://nand2tetris-questions-and-answers-forum.32033.n3.nabble.com/Question-About-Screen-Memory-Map-tp4029966p4029967.html
To unsubscribe from Question About Screen Memory Map, click here.
NAML

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question About Screen Memory Map

cadet1620
Administrator
I can't tell where you are going wrong form the code fragment.  Also, how are you running it?  Using Rect.tst?

Please post your complete program as text (so we can load it into the CPU simulator).  After you get it working, you can edit your post to remove the code.

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question About Screen Memory Map

Jatudrea
// Program: Rectangle.asm
// Draws a filled rectangle at the screen's top left corner.
// The rectangle's width is 16 pixels, and its height is RAM[0].
// Usage: put a non-negative number (rectangle's height) in RAM[0]/

    @R0
    D=M // Loads contents of Memory[0] into data register D
    @n
    M=D // Loads contents of data register D (see above) into memory of variable "n", located at Memory[16]

    @i
    M=0 // Creates a variable "i" at Memory[17] and sets its contents equal to 0.

    @21600   //  This was originally @SCREEN; other than that, the program is identical to the one in the lecture.
    D=A  // Loads the contents of pre-loaded variable "SCREEN" (the numerical value 16834) into data register D
    @address
    M=D // Creates a variable "address" (at Memory[18]) and sets contents equal to 16834 (see above).
(LOOP)
    @i
D=M  //  Loads the current contents of variable "i" into data register D.
@n
D=D-M  // Subtracts contents of variable "n" from contents of variable "i" and loads result into data register D.
@END
D;JGT // If data register D has a value greater than 0, indicating that "i" (the incrementor) has passed "n" (number of desired loops)
     // goes to "end program" infinite loop
@address
A=M   // Loads current contents of "address" into data register A.
M=-1  // Sets contents of "address" to -1
@i
M=M+1 // Increments variable "i"
@32
D=A  // Sets numerical value 32 into data register D.
@address
M=D+M // Adds numerical value of data register D (32; see above) to value of "address" variable, and loads result into "address variable".
     // In short, increases value of "address" variable by 32.
@LOOP
0;JMP // Jumps back to beginning of LOOP
(END)
@END
0;JMP // program's end

On Tue, Jun 28, 2016 at 5:06 PM, cadet1620 [via Nand2Tetris Questions and Answers Forum] <[hidden email]> wrote:
I can't tell where you are going wrong form the code fragment.  Also, how are you running it?  Using Rect.tst?

Please post your complete program as text (so we can load it into the CPU simulator).  After you get it working, you can edit your post to remove the code.

--Mark



If you reply to this email, your message will be added to the discussion below:
http://nand2tetris-questions-and-answers-forum.32033.n3.nabble.com/Question-About-Screen-Memory-Map-tp4029966p4029969.html
To unsubscribe from Question About Screen Memory Map, click here.
NAML

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question About Screen Memory Map

Jatudrea
In reply to this post by cadet1620
I'm just loading it into the CPU Emulator and running it.  I haven't found a pre-loaded rect.asm or rect.tst, so I copied it off the lecture to capture it for myself as rect.asm.

On Tue, Jun 28, 2016 at 5:09 PM, Yehoshua Kahan <[hidden email]> wrote:
// Program: Rectangle.asm
// Draws a filled rectangle at the screen's top left corner.
// The rectangle's width is 16 pixels, and its height is RAM[0].
// Usage: put a non-negative number (rectangle's height) in RAM[0]/

    @R0
    D=M // Loads contents of Memory[0] into data register D
    @n
    M=D // Loads contents of data register D (see above) into memory of variable "n", located at Memory[16]

    @i
    M=0 // Creates a variable "i" at Memory[17] and sets its contents equal to 0.

    @21600   //  This was originally @SCREEN; other than that, the program is identical to the one in the lecture.
    D=A  // Loads the contents of pre-loaded variable "SCREEN" (the numerical value 16834) into data register D
    @address
    M=D // Creates a variable "address" (at Memory[18]) and sets contents equal to 16834 (see above).
(LOOP)
    @i
D=M  //  Loads the current contents of variable "i" into data register D.
@n
D=D-M  // Subtracts contents of variable "n" from contents of variable "i" and loads result into data register D.
@END
D;JGT // If data register D has a value greater than 0, indicating that "i" (the incrementor) has passed "n" (number of desired loops)
     // goes to "end program" infinite loop
@address
A=M   // Loads current contents of "address" into data register A.
M=-1  // Sets contents of "address" to -1
@i
M=M+1 // Increments variable "i"
@32
D=A  // Sets numerical value 32 into data register D.
@address
M=D+M // Adds numerical value of data register D (32; see above) to value of "address" variable, and loads result into "address variable".
     // In short, increases value of "address" variable by 32.
@LOOP
0;JMP // Jumps back to beginning of LOOP
(END)
@END
0;JMP // program's end

On Tue, Jun 28, 2016 at 5:06 PM, cadet1620 [via Nand2Tetris Questions and Answers Forum] <[hidden email]> wrote:
I can't tell where you are going wrong form the code fragment.  Also, how are you running it?  Using Rect.tst?

Please post your complete program as text (so we can load it into the CPU simulator).  After you get it working, you can edit your post to remove the code.

--Mark



If you reply to this email, your message will be added to the discussion below:
http://nand2tetris-questions-and-answers-forum.32033.n3.nabble.com/Question-About-Screen-Memory-Map-tp4029966p4029969.html
To unsubscribe from Question About Screen Memory Map, click here.
NAML


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question About Screen Memory Map

cadet1620
Administrator
Sorry.  I was thinking about ComputerRect.tst from project 5...

The code you posted works for me.  Are you setting a value in RAM[0] before running it?  In my test I set RAM[0] to 10.

Where is it failing for you?



--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question About Screen Memory Map

Jatudrea
What I'm trying to figure out is how to color in parts of the screen that aren't at the far left.  As you see, while it's true that this code allows me to color in part or all of the leftmost column, it doesn't seem to enable me to color in the rest of the screen, or any part of the rest of the screen.

On Tue, Jun 28, 2016 at 5:41 PM, cadet1620 [via Nand2Tetris Questions and Answers Forum] <[hidden email]> wrote:
Sorry.  I was thinking about ComputerRect.tst from project 5...

The code you posted works for me.  Are you setting a value in RAM[0] before running it?  In my test I set RAM[0] to 10.

Where is it failing for you?



--Mark


If you reply to this email, your message will be added to the discussion below:
http://nand2tetris-questions-and-answers-forum.32033.n3.nabble.com/Question-About-Screen-Memory-Map-tp4029966p4029972.html
To unsubscribe from Question About Screen Memory Map, click here.
NAML

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question About Screen Memory Map

cadet1620
Administrator
Jatudrea wrote
What I'm trying to figure out is how to color in parts of the screen that
aren't at the far left.  As you see, while it's true that this code allows
me to color in part or all of the leftmost column, it doesn't seem to
enable me to color in the rest of the screen, or any part of the rest of
the screen.
Each screen row is 32 consecutive words of memory, so if you start at 16385 instead of SCREEN you will be drawing the rectangle at the top of the screen, 16 pixels to the right.

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question About Screen Memory Map

Jatudrea
You're right, that works, but I don't undertand how you calculated the number.

The textbook (page 70) says "Thus the pixel at row r from the top and column c from the left is mapped on the c%16 bit (counting from LSB to MSB) of the word located at RAM[16384 + r * 32 + c/16]."  How did you get from that sentence to the number 16385?

On Wed, Jun 29, 2016 at 1:52 PM, cadet1620 [via Nand2Tetris Questions and Answers Forum] <[hidden email]> wrote:
Jatudrea wrote
What I'm trying to figure out is how to color in parts of the screen that
aren't at the far left.  As you see, while it's true that this code allows
me to color in part or all of the leftmost column, it doesn't seem to
enable me to color in the rest of the screen, or any part of the rest of
the screen.
Each screen row is 32 consecutive words of memory, so if you start at 16385 instead of SCREEN you will be drawing the rectangle at the top of the screen, 16 pixels to the right.

--Mark


If you reply to this email, your message will be added to the discussion below:
http://nand2tetris-questions-and-answers-forum.32033.n3.nabble.com/Question-About-Screen-Memory-Map-tp4029966p4029980.html
To unsubscribe from Question About Screen Memory Map, click here.
NAML

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question About Screen Memory Map

cadet1620
Administrator
Jatudrea wrote
You're right, that works, but I don't undertand how you calculated the
number.

The textbook (page 70) says "Thus the pixel at row r from the top and
column c from the left is mapped on the c%16 bit (counting from LSB to MSB)
of the word located at RAM[16384 + r * 32 + c/16]."  How did you get from
that sentence to the number 16385?
Each word that is written to screen memory contains 16 pixels, so 16384 contains pixels 0-15 in line 0 (top) of the screen.
Row 0, pixel 16, word address (r=0, c=16) is:
screen: 16384
row:        0  r*32
word:       1  c/16
        -----
        16385
Row 12, pixel 345, word address (r=12, c=345) is:
screen: 16384
row:      384  r*32
word:      21  c/16
        -----
        16789
--Mark
Loading...