assemblykeyboard-eventsnand2tetrislow-level-code

Nand2tetris Project4- Test failed - of Fill.asm: Comparison failure at line 3


Not mentioning much about the Nand2tetris course and uploading the assembly file which interacts with the keyboard.

Basically what this program does is when a key is pressed on the keyboard the screen turns black i.e. every pixel of the screen is supposed to turn black and when the keyboard is idle the screen stays white .

Here is my code and it works well on my computer's hardware simulator but fails when I upload it for submission on coursera.

@place
M=0

(LOOP)
@KBD
D=M
@WHITE
D; JEQ
@BLACK
0; JMP


(WHITE)

@place
D=M
@LOOP
D; JLT
@place
D=M
@SCREEN
A=A+D
M=0
@place
M=M-1
@LOOP
0;JMP


(BLACK)

@place 
D=M
@LOOP
D; JGE
@SCREEN
A=A+D
M=-1
@place
M=M-1
@LOOP
0; JMP

Where am I getting wrong ? What is the reason for comparison failure and how can I sort it out ? Thanks in advance


Solution

  • I'm sorry, but the solution you posted does not solve the problem. I think this is why coursera is rejecting it.

    When I run your solution through an assembler and then a cpu emulator I do not see the behavior required of Fill.asm. I'm comparing your solution to a solution I know to be correct and I am seeing different behavior.

    Here's a screenshot of the cpu emulator while pressing the keyboard using your solution:

    enter image description here

    Here's what I expect to see:

    enter image description here

    I suggest reviewing your solution.

    Hint Something missing from your solution is code to fill the screen.

    Here's why I think it's missing:

    1. Line 19 M=0 of your solution is where I believe the color is set to white
    2. I change line 19 to M=-1, setting the white color to black
    3. I expect to see the screen always painted black, but instead, I see only a small line of black in the top left corner of the emulator screen as seen below

    enter image description here

    Hint: You have one loop ((LOOP)) that repeatedly listens for the keyboard. I expect to see another loop ((FILL), or whatever) which fills the entire section of memory dedicated to the SCREEN with white or black.

    Good luck.