// Program: Rectangle.asm
// Draws a filled rectangle at the screen's top left corner.
// The rectangle's width is 16 pixels, and its height is RAM[0].
// Usage: put a non-negative number (rectangle's height) in RAM[0]/
@R0
D=M // Loads contents of Memory[0] into data register D
@n
M=D // Loads contents of data register D (see above) into memory of variable "n", located at Memory[16]
@i
M=0 // Creates a variable "i" at Memory[17] and sets its contents equal to 0.
@21600 // This was originally @SCREEN; other than that, the program is identical to the one in the lecture.
D=A // Loads the contents of pre-loaded variable "SCREEN" (the numerical value 16834) into data register D
@address
M=D // Creates a variable "address" (at Memory[18]) and sets contents equal to 16834 (see above).
(LOOP)
@i
D=M // Loads the current contents of variable "i" into data register D.
@n
D=D-M // Subtracts contents of variable "n" from contents of variable "i" and loads result into data register D.
@END
D;JGT // If data register D has a value greater than 0, indicating that "i" (the incrementor) has passed "n" (number of desired loops)
// goes to "end program" infinite loop
@address
A=M // Loads current contents of "address" into data register A.
M=-1 // Sets contents of "address" to -1
@i
M=M+1 // Increments variable "i"
@32
D=A // Sets numerical value 32 into data register D.
@address
M=D+M // Adds numerical value of data register D (32; see above) to value of "address" variable, and loads result into "address variable".
// In short, increases value of "address" variable by 32.
@LOOP
0;JMP // Jumps back to beginning of LOOP
(END)
@END
0;JMP // program's end