bader wrote
conclusion: its ok that there is: pair1 <L_COMMAND, address1> and pair2 <variable, address2>
where: ROM address == address1 == address2 == memory location.
example: <loop, 2> and <R2,2>.
Your conclusion is correct; it's OK for ROM and RAM symbols with the same address to be stored in the symbol table.
and here comes my problem: if the my conclusion is correct why what is written in section 6.1 holds :
""note that the variable allocation assumption implies that the largest program that we can run is 1,024 instructions
long. Since realistic programs (like the operating system) are obviously much larger,
the base address for storing variables will normally be much farther""
This comment applies to computers that store both program code and data in RAM. In that case, if the variables were allocated at addresses that conflicted with where the program is stored, writing to the variables would change the program.
Since the Hack computer has separate code ROM and data RAM the differentiation between code and data addresses only occurs when they are used.
@FOO
M=D // uses FOO as a RAM address
@FOO
0;JMP // uses FOO as a ROM address
It is up to the programmer to make sure that he uses the symbol FOO correctly.
its confusing cuz if the L_COMMANDS addresses and the variable addresses can intersect, does it really matter which address do we start saving variables. i think the main thing that they are saved in consecutive memory blocks. right ??!!!
The reason to start allocating allocating RAM variables at 16 is so that RAM addresses 0-15 are reserved for special uses. The SP, LCL, etc. symbols will make more sense when you get to the Virtual Machine chapter.
--Mark