// This file is part of www.nand2tetris.org // and the book "The Elements of Computing Systems" // by Nisan and Schocken, MIT Press. // File name: projects/04/Fill.asm // Runs an infinite loop that listens to the keyboard input. // When a key is pressed (any key), the program blackens the screen, // i.e. writes "black" in every pixel; // the screen should remain fully black as long as the key is pressed. // When no key is pressed, the program clears the screen, i.e. writes // "white" in every pixel; // the screen should remain fully clear as long as no key is pressed. // Put your code here. @8192 D=A @words M=D // words = 8192 (KBD_LOOP) @KBD D=M @FILL_WHITE D;JEQ // if (KBD == 0) goto FILL_WHITE @color M=-1 // color = 0xffff (black) @FILL 0;JMP (FILL_WHITE) @color M=0 // color = 0x0000 (white) @FILL 0;JMP (FILL) @i M=0 // i = 0 @SCREEN D=A @pos M=D // pos = &SCREEN (DRAW) @color D=M @pos A=M M=D // *pos = color @pos M=M+1 // pos++ @i M=M+1 // i++ D=M // D = i @words D=D-M // D = i - words @KBD_LOOP D;JEQ // if (i - words == 0) break @DRAW 0;JMP