From 9542deeb483a00b6fabed7574720926ce97d7511 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Tue, 16 Aug 2022 11:54:23 +0800 Subject: Projects, 01-06 completed --- projects/04/fill/Fill.asm | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 projects/04/fill/Fill.asm (limited to 'projects/04/fill/Fill.asm') diff --git a/projects/04/fill/Fill.asm b/projects/04/fill/Fill.asm new file mode 100644 index 0000000..1b69de1 --- /dev/null +++ b/projects/04/fill/Fill.asm @@ -0,0 +1,60 @@ +// 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 -- cgit v1.2.3