I think you are confusing the
address of a variable and the
value of a variable.
The address of a variable is assigned by the assembler and cannot be changed. You can load this program into the CPU simulator and step through it to see how it works.
// Here's how to set var1=123
@123
D=A // 123 now in D-reg
@var1 // ADDRESS of var1 in A-reg
// This is what sets the VALUE of var1 to 123
M=D // memory[A-reg] = D-reg
// The same sequence sets var2=456
@456
D=A
@var2
M=D
// Compute var3=var1+var2.
@var1
D=M
@var2
D=D+M
@var3
M=D
@HALT
(HALT)
0;JMP
For Fill.asm, you will need a variable whose
value is the
address of the screen location you want to change. A variable used this way is called a
pointer.
To use a pointer variable, you need to load its value into the A-register. Then M will read or write using the address stored in the pointer.
--Mark