1

I'm building a CPU in the nand2tetris course and I'm kind of stuck. Do I have to check if the instruction is an A or C instruction?

In the A instruction guide it only shows the first control bit. The MSB controls the output of the first Mux. What controls the load of the A register if it's an A instruction?

If it's an A instruction the load of the A register should always be 1 im pretty sure. A instruction

If it's a C instruction there are lots of control bits but I can't use the same control bits for A instructions. C instruction

So should I be checking if the instruction coming in is a C or A instruction and then setting the control bits accordingly? Here's a another picture that might be useful. C and A instruction bits

Tricky
  • 3,791
  • 3
  • 10
  • 23
elonma1234
  • 11
  • 2
  • Since A and C instructions are different, you need to check which one it is, of course. Why do you think you can omit the check? – the busybee Jun 21 '22 at 09:35

1 Answers1

0

Here's one way to think about it:

In a C-instruction, there are a lot of bits (accccccdddjjj, plus the most significant bit that says it's a C-instruction) that determine what the various parts of the machine do. So if you are presented with a C-instruction, you just have to route those bits as appropriate to control the machine.

The A-instruction, on the other hand, doesn't have the control bits, it just has the instruction type bit. So in this instance, you have to generate the control bits so that there are no changes to the machine state other than storing the 15 bits into the A register (and incrementing the PC, of course).

You have to do something similar to handle Reset.

MadOverlord
  • 1,034
  • 6
  • 11
  • ok thank you, I have another question. If you look at the C instruction picture, the first mux's selector is 1, and it outputs the upper input (ALU output), but the second mux's selector is 0, and it also outputs the upper input. Is that a mistake in the picture or? – elonma1234 Jun 21 '22 at 11:45
  • The mux elements just show you that there are two inputs, one output, and a control bit. They don't associate control=1 with (for example) the upper input, because that would mean the schematic would have a lot of crossing paths. I agree it would be a bit clearer if the mux inputs were labelled with a 0 or 1, but this has apparently been left as an exercise for the student. – MadOverlord Jun 22 '22 at 12:14