where stuff goes...

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

where stuff goes...

moobles
Little bit lost.  Dont know where to put STATIC, LOCAL etc.  So for example  RAM[3] holds address of the base of THIS.  But where should RAM[3] point?  Will the compiler have to figure out how to arrange for THIS not to run out of room?  Or is there a standard?

Should I be thinking of compiler running through a program to get information on how big stuff has to be before hand.. and then putting things .... in what? the 'heap' from 2048 to 16483?  So if I decided to do THIS and THAT first then I would have to know that let's say THIS is going to need at most 10 places.  So I would set RAM[3] to 2048 and RAM[4] to 2058?

By the way love this course!  It's daunting but very exciting too:)
Reply | Threaded
Open this post in threaded view
|

Re: where stuff goes...

ybakos
You're not as lost as you may think.

moobles wrote
RAM[3] holds address of the base of THIS.  But where should RAM[3] point?
You've answered your own question here, but let's clarify. RAM[3] has a handy nickname: THIS. The THIS register stores the base address of the this memory segment. Hence, THIS points to this.

If you have programmed with object-oriented languages, you should be able to infer that THIS really is a pointer to an object, and the this segment does indeed represent the memory occupied by that object.

THAT and that are similar, but these are used by the Jack language for arrays.

Note that the that segment does not necessarily come right after the this segment on the heap. They can be anywhere in the heap.

If THIS points to address 3000, and the object stored there has three member variables, how big is the this memory segment? What addresses does it occupy?
Reply | Threaded
Open this post in threaded view
|

Re: where stuff goes...

moobles
RAM[3] holds 0000101110111000 (binary for 3000)
RAM[3000], RAM[3001] and RAM[3002] hold 16*3 bits of whatever data
RAM[3003] is potentially available for something else.
A variable can be only as large as 2's complement can handle in 16 bits.
Is this right?
Reply | Threaded
Open this post in threaded view
|

Re: where stuff goes...

ybakos
You got it.