Permalink
Browse files

04 fill project

  • Loading branch information...
taw committed Oct 7, 2012
1 parent 5de645d commit 131c6288f4a12f346cecccfa71a5cd758f779146
Showing with 111 additions and 0 deletions.
  1. +65 −0 04/fill/Fill.asm
  2. +35 −0 04/fill/Fill.hack
  3. +11 −0 04/fill/Fill.tst
View
@@ -0,0 +1,65 @@
+// This file is part of the materials accompanying the book
+// "The Elements of Computing Systems" by Nisan and Schocken,
+// MIT Press. Book site: www.idc.ac.il/tecs
+// 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 screen should be cleared.
+
+// Put your code here.
+
+// R0 - loop counter
+(loop)
+@16384
+D=A
+@0
+M=D
+
+@24576
+D=M
+@keypressed
+D;JNE
+
+(nokey)
+// [R0] = 0
+@0
+D=A
+@0
+A=M
+M=D
+
+// R0 += 1
+D=A+1
+@0
+M=D
+
+@24576
+D=D-A
+@nokey
+D;JNE
+
+@loop
+0;JMP
+
+(keypressed)
+
+// [R0] = 0xFFFF
+D=-1
+@0
+A=M
+M=D
+
+// R0 += 1
+D=A+1
+@0
+M=D
+
+@24576
+D=D-A
+@keypressed
+D;JNE
+
+@loop
+0;JMP
View
@@ -0,0 +1,35 @@
+0100000000000000
+1110110000010000
+0000000000000000
+1110001100001000
+0110000000000000
+1111110000010000
+0000000000010110
+1110001100000101
+0000000000000000
+1110110000010000
+0000000000000000
+1111110000100000
+1110001100001000
+1110110111010000
+0000000000000000
+1110001100001000
+0110000000000000
+1110010011010000
+0000000000001000
+1110001100000101
+0000000000000000
+1110101010000111
+1110111010010000
+0000000000000000
+1111110000100000
+1110001100001000
+1110110111010000
+0000000000000000
+1110001100001000
+0110000000000000
+1110010011010000
+0000000000010110
+1110001100000101
+0000000000000000
+1110101010000111
View
@@ -0,0 +1,11 @@
+// This file is part of the materials accompanying the book
+// "The Elements of Computing Systems" by Nisan and Schocken,
+// MIT Press. Book site: www.idc.ac.il/tecs
+// File name: projects/04/fill/Fill.tst
+
+load Fill.hack;
+echo "First, make sure that 'No Animation' is selected. Then, select the Keyboard, click on any key and check the screen.";
+
+repeat {
+ ticktock;
+}

0 comments on commit 131c628

Please sign in to comment.