|
(RESTART)
//set pointer i=0
@i
M=0
//set n, as in number of screen registers
@8191
D=A
@n
M=D
//set screen to be stored in address value
@SCREEN
D=A
@ADDR
M=D
//checking if a key is pressed
@KBD
D=M
//if KBD=0, go to LOOPWHITE
@LOOPWHITE
D; JEQ
//if KBD not 0, go to LOOPBLACK
@LOOPBLACK
D; JNE
// if KBD=0, then the screen is white
//going through the screen and turning it white
(LOOPWHITE)
// if i==n goto RESTART
@i
D=M
@n
D=D-M
@RESTART
D; JEQ
//set RAM [screen +i)= 0 to make screen white
@ADDR
A=M //pointer to the correct row
M=0 // setting the value of that row to zero so that the screen is white
//incrementing i
@i
M=M+1
//incrementing to next register
@ADDR
M=M+1
@LOOPWHITE
0; JMP
// if KBD not 0, then the screen is black
//going through the screen and turning it white
(LOOPBLACK)
// if i==n goto END
@i
D=M
@n
D=D-M
@RESTART
D; JEQ
//set RAM [screen +i)= -1 to make screen black
@ADDR
A=M // pointer to the correct row
M=-1 // setting the value of that row to -1 so that the screen is black
//incrementing i
@i
M=M+1
//incrementing to next row
@ADDR
M=M+1
@LOOPBLACK
0;JMP
@RESTART
0;JMP
|