7 messages
Open this post in threaded view
|

 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
Open this post in threaded view
|

 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.
Open this post in threaded view
|

 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
Open this post in threaded view
|

 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.
Open this post in threaded view
|

 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 ```