Mark wrote
I'm looking at the example BasicTestVME.tst, and notice that, for example, ARG is mapped to RAM location 400. Is this mapping choice arbitrary? In the specification, it says that RAM addresses 256-2047 are reserved for the stack, so are you not writing ARG onto the stack (albeit much higher up than the stack would ever reach)? Is this a good practice?
The values of ARG, LCL, THIS and THAT are arbitrary, although they have conventional uses by the compiler you will write in projects 10 and 11. As far as the VM translator is concerned, they are simply memory addresses that specify the beginning of the VM segments
argument,
local,
this and
that.
Another source of confusion, THIS is mapped to 3000, and THAT to 3010. Wouldn't this arrangement require that no more than 10 words be allocated to THIS before parts of THAT is overwritten?
This is just a test setup, so there really aren't any semantics to what THIS and THAT point to. If this situation was seen in compiler generated code, it's likely THIS is pointing to an object that is no larger that 10 words, or that THIS is pointing to an Array object and THAT is pointing to one of the Array's members.
I guess it's up to the programmer to decide where these segments start on the RAM, and how much space to allocate each?
In general, only the compiler writes programs in VM language. It uses ARG and LCL to access function arguments and local variables; THIS points to the current object (like the
this pointer in C++ and Java), and THAT is used for array indexing.
--Mark