M register == RAM[A], Why?

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

M register == RAM[A], Why?

igaloly
As I understand:

- M register sits in the main memory (RAM)
- A register is a CPU register
- D register is a CPU register
- M register is RAM[A] - That means the value of RAM in the address of A

As I understand, we need it to be able to access the value of A because of the lack of instruction bits.

So why don't we have some register to access D value? It seems like we are able to do operations with D value, for example, D = D+M, but not with A value.

I'll be happy to get an explanation to fill the lack of my understanding.
Reply | Threaded
Open this post in threaded view
|

Re: M register == RAM[A], Why?

WBahn
Administrator
I don't understand the question. What do you mean by a register to access D value?

As you will see in the next chapter, the architecture has one input of the ALU tied to the D register. The other input of the ALU can have EITHER the value in the A register OR the value from the RAM (at the locations whose address is in the A register). So there's no way to feed BOTH the A and the M values to the ALU.

They could have altered the architecture to make it possible, but the instances when you would want to add a memory locations contents to its address are few. Having said that, it would have some advantages for working with arrays, but they decided that those advantages weren't worth the added complexity of the architecture.
Reply | Threaded
Open this post in threaded view
|

Re: M register == RAM[A], Why?

igaloly
Excuse me, I'll paraphrase myself.

What is this M  and why do we use it?
Reply | Threaded
Open this post in threaded view
|

Re: M register == RAM[A], Why?

WBahn
Administrator
You said it yourself, M is RAM[A], the RAM cell located at the address whose contents are in the A register.

We use it because we would like to be able to read and write information to more than just two locations, namely D and A.
Reply | Threaded
Open this post in threaded view
|

Re: M register == RAM[A], Why?

igaloly
Why can we write RAM[A]?
Reply | Threaded
Open this post in threaded view
|

Re: M register == RAM[A], Why?

WBahn
Administrator
igaloly wrote
Why can we write RAM[A]?
Why couldn't or shouldn't we?

It is nothing more than a convention.

Why can we write D or A? Because it is agreed (meaning that the authors defined it this way) that when we write D we are referring to the contents of the D register, while when we write A it is agreed we are referring to the contents of the A register. The same for PC with regards to the contents of the program counter.

So when we write RAM[135] it is agreed that we are referring to the contents of the Memory that is at location 135. From there it's natural, even inevitable, to talk about RAM[A] as referring to the contents of the Memory that is at the location whose value is stored in the A register, since if A = 135, then

RAM[A] = RAM[135]

It is further agreed that the M 'register' refers to RAM[A].

To be sure, we "could" write RAM[D] and understand that to be the contents of the Memory at the location whose address is currently in the D register. As an abstraction or shorthand, it might even have some utility (in the same sense that RAM[base+offset] would have), but we have to recognize that we have no way, with the Hack architecture, of accessing RAM[D] directly.
 
Reply | Threaded
Open this post in threaded view
|

Re: M register == RAM[A], Why?

igaloly
Thank you very much!!!!