Buggy Fill.asm?

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

Buggy Fill.asm?

William DesLauriers
This post was updated on .
(LOOP)  //this loop checks to see if a key is pressed
__________________________________
       
Deleted by the Author.  Sorry!
_________________________________
       
       

At lines 16 and 37; Destination is M but A=24577 is an illegal memory address.  Do you have any idea on this one?

Thanks,
Wm
Reply | Threaded
Open this post in threaded view
|

Re: Buggy Fill.asm?

cadet1620
Administrator
I see this pattern several places in the code:
    @KBD
    D=A
    @keyboard
    M=M-D  //keyboard=KBD address
The M=M-D is wrong here. This is subtracting the KBD address from variable keyword, rather than setting the variable.

Remember this patterns.
After @variable, M refers to the value of the variable. Remember these patterns.
    @variable
    M=D        // set the variable from D (or 0, 1, -1, expression)

    @variable
    D=M         // read the variable into D (or A)

    @variable
    M=M...      // modify the variable

    @variable
    M=...M      // modify the variable

Side note: the value of variable keyboard should never change. Why not just use @KBD to get that value?
    @screen_address
    D=M
    @KBD
    D=D-A
    @LOOP
    D;JEQ
--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Buggy Fill.asm?

William DesLauriers
This post was updated on .
After I tried to adjust my program, then ran it through CPU Emulator.  No black screen with any key pressed yet.  I am still stumped.

Buggy file smashed forever!

Also, I printed a website of yours, "Introduction to Hack Assembly Language".

Thanks,
Wm
Reply | Threaded
Open this post in threaded view
|

Re: Buggy Fill.asm?

cadet1620
Administrator
Your POST_ loops are missing to very important things.
  1)  The don't ever set the screen to white or black,
  2)  The don't increment screen_address.

Your earlier code had both of these, but they seem to have gone AWOL.
(POST_WHITE)
        @screen_address
        A=M
        M=0  //clear in current address
        @screen_address
        M=M+1  //increment address to be filled in
        D=M
        @keyboard
Fix these two bugs and your code works.

Debugging hint:
It can be quite hard to tell if your program is turning the white screen white 8-).  A simple thing that you can do for debugging is to change the M=0 to M=1.  This will make the white loop draw vertical lines instead of all white.  You can change it back to M=0 when the program is working.

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

Re: Buggy Fill.asm?

William DesLauriers
Good news, the program is running very beautiful!

I hate to repeat a message.  But, I just printed out a website of yours," Introduction to Hack Assembly Language".

I edited these 3 "files".tst so I can run them with the two files.asm instead of files.hack.

I took the "buggy" file off the forum right away.

Thanks,
Wm