Standard mapping for argument-, local- and pointer segment?

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

Standard mapping for argument-, local- and pointer segment?

Manu T.
As there is no specific range declared, where these segments should reside in RAM. Is it preferable to place them somewhere in the range of the stack or the heap?
Why did Schocken and Nisan decide not to mention their placement at all, or did I just miss it?

From size considerations, I would pick the heap.
Reply | Threaded
Open this post in threaded view
|

Re: Standard mapping for argument-, local- and pointer segment?

cadet1620
Administrator
The "pointer" segment is fixed at RAM address 3. "pointer 0" is THIS and "pointer 1" is THAT.

"argument" and "local" segments are based on the memory addresses in ARG and LCL, just like "this" and "that" segments are based on the memory addresses in THIS and THAT.

You might like to look ahead to figures 8.3 and 8.4 to see how the stack frames work and where the "argument" and "local" segments are on the stack and how they move based on the currently active function.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Standard mapping for argument-, local- and pointer segment?

Manu T.
So, RAM[1] upcluding RAM[4] point to random base addresses, until chapter 8 is reached?
Reply | Threaded
Open this post in threaded view
|

Re: Standard mapping for argument-, local- and pointer segment?

cadet1620
Administrator
I wouldn't say "random", but rather that they are set to known values for testing purposes.

For example, BasicTest.tst set them this way
set RAM[0] 256,
set RAM[1] 300,
set RAM[2] 400,
set RAM[3] 3000,
set RAM[4] 3010,

After the test ASM code runs, the test then checks RAM locations that should have been set to specific values.
|RAM[256]|RAM[300]|RAM[401]|RAM[402]|RAM[3006|RAM[3012|RAM[3015|RAM[11] |
|    472 |     10 |     21 |     22 |     36 |     42 |     45 |    510 |

You can look at the BasicTest.vm code to see where it should write.
// Executes pop & push commands using the virtual memory segments.
push constant 10
pop local 0         RAM[300+0]
push constant 21
push constant 22
pop argument 2      RAM[400+2]
pop argument 1      RAM[400+1]
push constant 36
pop this 6          RAM[3000+6]
...

--Mark