// 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. //キーボードのアドレスおよび、スクリーンの終わり+1のアドレス @24576 //jに代入 D=A @j M=D (LOOP) @16384 D=A //ポインタiを用意して16384を代入 @i M=D //キーボードの状態を取得 @j A=M D=M @WHITE D;JEQ @BLACK D;JNE @LOOP 0;JMP (BLACK) //ポインタの位置に-1を代入 @i A=M M=-1 //ポインタ移動 @i M=M+1 //Mが24576になったら描画終わり D=M @j D=M-D @LOOP D;JLE @BLACK 0;JMP (WHITE) //ポインタの位置に0を代入 @i A=M M=0 //ポインタ移動 @i M=M+1 //Mが24576になったら描画終わり D=M @j D=M-D @LOOP D;JLE @WHITE 0;JMP