How to actually use pointer values in assembly?

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

How to actually use pointer values in assembly?

greenwhat
I want to know where each pointer actually points, but how can I know this after it changes from its initial position? Until FibonnacciSeries I had been using a function from a class that I implemented that would return this location.

For example,

return "@" + memory.getTHAT(int fromBase) + "\nD=M\n";

The formula was (THAT = RAM[4] + fromBase), but this no longer works because the base position of THAT changes during each loop.

My ideas:

1) Find a way to access RAM[4] in assembly and then use what I find there to access the position of THAT.
OR
2) Forget loops, write the whole assembly program as one continuous segment.


I don't like the second, and I need guidance for the first.
Reply | Threaded
Open this post in threaded view
|

Re: How to actually use pointer values in assembly?

cadet1620
Administrator
greenwhat wrote
I want to know where each pointer actually points, but how can I know this after it changes from its initial position? Until FibonnacciSeries I had been using a function from a class that I implemented that would return this location.

For example,

return "@" + memory.getTHAT(int fromBase) + "\nD=M\n";

The formula was (THAT = RAM[4] + fromBase), but this no longer works because the base position of THAT changes during each loop.
I don't understand what loops have to do with anything.

The value of the THAT pointer changes whenever a "pop pointer 1" VM command occurs.

The code that is generated for "push that 17" is independent of the actual value of the THAT pointer. Your translator needs to write asm code that does something like this:
    @THAT
    D=M
    @17
    A=A+D
The A register now has the target RAM address for THAT[17]. Load M into D and do whatever you need to do to push D.

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

Re: How to actually use pointer values in assembly?

greenwhat
I apparently had a poor understanding of how the A register works.

Thank you. The problem is resolved.