question related to pointer and A instruction

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

question related to pointer and A instruction

ajksdf
From the lecture slide, I saw the following hack language which confused me.

I don't understand when you @arr, M equals to the address of 'arr'. Shouldn't it be the value of arr which is RAM[arr] (the value 100)???

From my understanding, @sth will have the follow effects:
1. A = sth
2. M = RAM[sth]  // should be the value stored in the address?

Thank you very much
Reply | Threaded
Open this post in threaded view
|

Re: question related to pointer and A instruction

WBahn
Administrator
Ar you saying that you think that the code on the slide is wrong, or that the descriptions are wrong?

As you say, when you do

@fred

then A = fred and M = RAM[fred]. Note that the value of 'fred' MUST be known at assembly time.

Here, you have @arr. The value of 'arr' is 16 and 16 is the address of the variable 'arr'. M is the value stored in the variable 'arr', it is NOT the address of 'arr' -- the address if 'arr' is 16.

It happens that 'arr' is a variable being used as a pointer, meaning that M is the address of where something is stored in memory. In this case that something has no name, so let's call is 'array', and it is stored (or at least starts) at memory address 100.


I think the slide is sloppy in its notation.

I disagree with the statement that both 'arr' and 'i' are pointers. While 'arr' is a pointer (i.e., the value stored there is interpreted as a memory address), the variable 'i' is not. It is an index or an offset.
Reply | Threaded
Open this post in threaded view
|

Re: question related to pointer and A instruction

ajksdf
This makes more sense if the value of arr is acting as a pointer, it is pointing the CPU to get the value of located in RAM[100]. Now I get it. Thank you very much.