Brad wrote
In Chapter 7, when we implement the VM translator, what are the valid ranges of the segments.
I know some of them have a fixed number of entries. And constant is from 0 to 32767. But, for example, what about a segment like argument?
For the dynamically allocated segments, should we just (for now) assume that correct indices will be used, or is there some range I should be looking for? Are these segments allocated in the heap perhaps?
Thanks.
For normal usage, ARG and LCL are allocated on the stack; they are part of the stack frame for the current function. THIS is a pointer to an object that was allocated from the heap, and THAT is a pointer used to access array elements that may be anywhere in memory. There is no easy way to know the upper bound for any of these segments except LCL.
For Nand2Tetris, there is no expectation for range checking. You may assume that the input you are processing is error free.
--Mark