Confused about SimpleAdd implementation concept

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

Confused about SimpleAdd implementation concept

ajksdf
This post was updated on .
I have a question while I was doing project 7 SimpleAdd just got very confused. Hope that someone can give me some hints. Thank you very much.


I come across some project7-related posts, some of them mentioned AM=M-1. I tried to search in the book but in vain. I found a post by 'cadet1620' which include some examples. Do the same logic apply to AM=M-1?

eg. AD=A+1  Increment A register and set D register to incremented value.
     //AM=M-1 Decrement M register and set M register to decremented. Nothing to do with the A register

Reply | Threaded
Open this post in threaded view
|

Re: Confused about SimpleAdd implementation concept

WBahn
Administrator
If AD=A+1 increments the A register, why would it be reasonable to conclude that AM=M-1 has no effect on the A register?

It looks like you don't understand how the CPU works, so let's review it.

Here's the basic format for a C-type instruction:

dest = comp; jump

The 'comp' mnemonic tells the CPU what operation to perform and this results in a value appearing at the output of the ALU. This is completely independent of any other part of the instruction.

The 'dest' writes the output of the ALU into some combination of three locations, A, D, and/or M.

The 'jump' either jumps to the instruction whose ROM address is currently in the A register or not, based solely on the output of the ALU.

Reply | Threaded
Open this post in threaded view
|

Re: Confused about SimpleAdd implementation concept

ajksdf
This post was updated on .
Thank you for clearing the mental fog in how the C-instruction works. Let see the following sequence of execution makes more sense for AM=M-1.

1. compute M-1(let say M is originally 5)
2. assign '4' to the RAM[A] (based on the fact that RAM[A] equals to M)
3. assign '4' to register A (hence the M will change accordingly as well)

* I wonder both step 2 and 3 will take effect in the next flip-flop cycle at the same time. Just like the CPU we implemented in previous chapter. The ALU output send to related A/M/D registers
Reply | Threaded
Open this post in threaded view
|

Re: Confused about SimpleAdd implementation concept

WBahn
Administrator
Yes, all operations apply to the values of the registers at the end of the prior clock cycle and the values in registers don't change until the end of the current clock cycle.
Reply | Threaded
Open this post in threaded view
|

Re: Confused about SimpleAdd implementation concept

ajksdf
Therefore when we are writing assembly code, we can ASSUME that each line of the code is synchronous(coz CPU running speed is way faster than we can perceive) ?

eg.

```
@SP  //assume original is 291
M=M-1
A=M  //when run though this line, M is already 290
```

Reply | Threaded
Open this post in threaded view
|

Re: Confused about SimpleAdd implementation concept

WBahn
Administrator
It has nothing to do with the speed of the CPU. However slow the clock is, the next line of code does not get executed until all of the effects of the prior line of code have been applied.

Having said that, this does take some time to happen, and that is what puts an upper limit on how fast our clock can be -- it has to be slow enough that all of the effects of the prior line have time to settle before we start executing the next line.
Reply | Threaded
Open this post in threaded view
|

Re: Confused about SimpleAdd implementation concept

ajksdf
OK got it. So we can see each line of code is synchronous. Just thought that there may be some asynchronous problem simliar to high level code.

Thank you for the clear explanation.