I see this pattern several places in the code:
@KBD
D=A
@keyboard
M=M-D //keyboard=KBD address
The
M=M-D is wrong here. This is subtracting the KBD address from variable
keyword, rather than setting the variable.
Remember this patterns.
After @variable, M refers to the value of the variable. Remember these patterns.
@variable
M=D // set the variable from D (or 0, 1, -1, expression)
@variable
D=M // read the variable into D (or A)
@variable
M=M... // modify the variable
@variable
M=...M // modify the variable
Side note: the value of variable
keyboard should never change. Why not just use @KBD to get that value?
@screen_address
D=M
@KBD
D=D-A
@LOOP
D;JEQ
--Mark