Not able to finish Fill.asm

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

Not able to finish Fill.asm

wajde
been working on it for serval days now , cant see what is it that im missing here, i will be glad for some help
Thank you


(Loop)
    //1: reset all values
    @KBD
    M=0
    @8192           // 8192 pixels screen
    D=A        
    @count            // variables start at address 16 in Hack language
    M=D               // stored 8192 in count @16, RAM[16] = 8192
   
    //2: get the screen addres
    @SCREEN
    D=A
    @screen         //@17
    M=D             // address = 16384 (base address of the Hack screen)    

    // //3: reset i = 0   // @18
    // @i
    // M=0

    //4: check color and update screen value
    @color // default color is zero
    M=0
   
   
    @KBD
    D=M // GET VALUE PRESESD // value will be
        // anything but 0 when clicked there for
        // if there a key pressed set R0 to -1
    @FILL
    D;JEQ   // If D = 0 jump to FILL_SCREEN and fill with white
 
    // we didnt jump to fill screen with white
    // so i update the color to black (-1) and the next presedure
    // wil be fill screen
    @color
    M=-1 ;

    (FILL)
        // FILL SCREEN ADDRES WITH THE COLOR    
        @color
  D = M
            @screen
            A = M // writing to memory using a pointer:
            M = D // RAM[address] = color (16 pixels)
       
       
        // // increase I by one
        // @i
        // D=M
        // D=D+1
        // M=D
       
        @count
        M=M-1 // Decrease count by one
               
        // check condtion  if count == 0 go to end
        // @count
        D=M
        @Loop
        D;JEQ
   
        // update screen Pointer for the next iteration
        @screen
        M=M+1
        // D=M
        // D=D+1
        // @screen
        // M=D
   
        @FILL
        0;JMP

   
   
   
Reply | Threaded
Open this post in threaded view
|

Re: Not able to finish Fill.asm

ivant
As far as I remember the Fill.asm task is a bit under-specified. This is because it's not an important problem by itself, but rather a way to get a feel of how to program in HACK assembly.

That said, you do need to specify what you expect to happen when you press a key while the screen is being filled up. Are you just switching the color and continuing from the current position in the screen? Or perhaps you're switching the color and starting from the beginning? Or something else? Without knowing this, we don't know how your program is expected to work, so it's hard to "fix" or "finish" it for you.

That said, I guess that it doesn't change the color when you press a key. Think of when are you checking if a key is pressed. And what happens if the key is pressed at any other time?
Reply | Threaded
Open this post in threaded view
|

Re: Not able to finish Fill.asm

WBahn
Administrator
In reply to this post by wajde
It will really help if you tell us the behavior you expect to see and the behavior you are actually seeing.