Looping through screen memory locations

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Looping through screen memory locations

Tkkemo
So, I can turn any pixel black if a key is pressed. However, the screen is made up of 8192 memory locations starting at 16384, how can I go through and set all of those to -1 without having to write every memory location and setting M=-1... I was thinking I could increment the A registers location and loop through but I can't seem to come up with anything.
Reply | Threaded
Open this post in threaded view
|

Re: Looping through screen memory locations

cadet1620
Administrator
You are correct, you need to come up with a loop that writes -1 or 0 to all the screen locations.

In pseudo-code, ignoring the key up/down changing what gets written, the loop needs to look like
    addr = 16384
    while (addr < 24576) {
        RAM[addr] = -1
        addr = addr + 1
        }
The A register in the Hack computer is a very busy register since it must be used for all memory accesses and to load all constants. It is not possible to keep addr in A and do the loop end address comparison. A also needs to be used when you add the keyboard check to the loop.

addr needs to be a variable in memory. It is accessed just like R0, R1 and R2 were in Mult.asm. (The Rn registers are really just memory variables with fixed addresses.)

Ask if you need more help.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Looping through screen memory locations

Tkkemo
In reply to this post by Tkkemo
Nevermind, I figured it out. I was just confusing how to access memory locations and values for A.

Wow, you already responded. I figured it would take a while. The forums for the course have been amazingly helpful, thanks for the quick response, loving the course so far.