Segment Index Ranges

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Segment Index Ranges

Brad
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.
Reply | Threaded
Open this post in threaded view
|

Re: Segment Index Ranges

cadet1620
Administrator
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
Reply | Threaded
Open this post in threaded view
|

Re: Segment Index Ranges

Brad
Thanks for the reply.  For the VM and even the Assembler projects, I kept getting caught up in doing a bunch of error checking, and it seemed to be slowing me down.  I guess it is best I just make the things work first.  Maybe someday I can come back and make it better.