Re: Setting A in C-instruction
Posted by eatmorepies on
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/Setting-A-in-C-instruction-tp4036936p4036957.html
Thanks for your comments. I took a break to read and work a bit on the Chapter 6 project and then I came back to this. I think I have a good understanding on what you're stating; would you be able to run through my reasoning to make sure?
Suppose the first program instruction is @17. The program counter's value is 0, which is sent to the ROM. The ROM outputs the aforementioned program instruction to the CPU.
In the CPU, the Mux16 outputs the program instruction to the a register, and loads it based on the leftmost instruction bit. This value is sent to the ROM, which outputs the m value at the corresponding a-value address and sends it to inM in the CPU. The PC is incremented and the CPU gets the next instruction.
Suppose our next instruction is to set D=A. Since the ALU hasn't calculated a value yet for this instruction, the leftmost Mux16 doesn't have anything to output to the a-register; thus, we begin by outputting the value of that register. Our A register outputs its value set in the PREVIOUS instruction, and the relevant bit in our instruction outputs the A register value to the ALU. The ALU outputs A, which is loaded into D. Our new D value is outputted on the next tick. The PC is incremented and the CPU gets the next instruction.
Suppose, then, our next instruction is A=D. Again, we start by outputting the a register. When we get to the ALU, it outputs the D register, which is sent to the leftmost Mux16. The Mux16 outputs this value to the A-register, and the value is set on the following tick.