# How does the cpu get inM at the first time?

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

## How does the cpu get inM at the first time?

 Assume that the cpu gets an instruction to increment a memory location by 1, M=M + 1. We know that the memory outM depends on the CPU addressM. So when the CPU executes the instruction M=M + 1 (1111110111001000), before it execute the instruction it needs the value at the memory location A which is M. But to do that the CPU must pass the addressM before executing the instruction. So does the value of inM valid, won't it have a garbage value(a value which is not what we want). If I miss any concept let me know please.
Reply | Threaded
Open this post in threaded view
|

## Re: How does the cpu get inM at the first time?

 Administrator When you execute M = M+1 it uses the value currently stored in the A register as the address at which to read and write from RAM. The instruction itself has no means of including the desired memory location. Which means that you need to first store the desired address in the A register before executing this instruction. So if you want to increment the value stored at RAM address 1234, you need to do @1234 M = M+1 If you wanted to do something like x = y + 1; you would use the following @y D = M @x M = D + 1 or @y D = M + 1 @x M = D What about if you wanted x = y + 2 Normally if you wanted to add a constant you would do something like @2 D = M @y D = D+M @x M = D For the special case of the constant being 2 (or -2), do you see how you could do it in just four instructions.
Reply | Threaded
Open this post in threaded view
|

## Re: How does the cpu get inM at the first time?

 That is clear, first setting the address using the A instruction instructs the RAM to fetch the memory address at that location, which is the input to the second instruction(M=M+1).