Created
October 10, 2016 06:02
-
-
Save ashtonx/79c91b3c7f126246e3a468c64b5777d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. When no key is pressed, the | |
// program clears the screen, i.e. writes "white" in every pixel. | |
(CHECK) //check if key is pressed | |
@SCREEN //screen adressing | |
D=A | |
@addr | |
M=D | |
@KBD //keypress check | |
D=M | |
@CLEAN | |
D;JEQ //clean if not pressed | |
@FILL | |
D;JGT //fill if pressed | |
(FILL) | |
@addr | |
A=M //jump to addres | |
M=-1 //fill | |
@addr | |
M=M+1 //increase address | |
//END OF SCREEN CHECK | |
D=M | |
@KBD | |
D=D-A | |
@FILL //if addr < KBD | |
D;JLT | |
@CHECK //if addr=KBD | |
D;JEQ | |
(CLEAN) | |
@addr | |
A=M //jump to addres | |
M=0 //clean | |
@addr | |
M=M+1 //increase address | |
//END OF SCREEN CHECK | |
D=M | |
@KBD | |
D=D-A | |
@CLEAN //if addr<KBD loop | |
D;JLT | |
@CHECK //if addr=KBD end loop | |
D;JEQ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment