yeolyi.comSeongyeol's CS

Control Unit

The moving data post grew the instructions to four, but the machine from machine code still only knows LDI. That’s because the instruction’s immediate is always wired to the register’s IN.

Memory slot 1 holds MOVE R1, R3. Change CLK to 1 and back to 0, twice over. R1 gets not R3’s 0, but 3, read from the last 2 bits 11 as an immediate.

Control unit

Each instruction asks the machine for something different, so we need a part that takes the job number and drives the parts to match. This is the control unit. The signals it sends are control signals. Let’s write down in a table which control signals to send for each job number.

First, where to write. Only STORE writes to memory, and the other three write to a register.

InstructionNumberRegister writeMemory write
LDI011010
LOAD100010
STORE100101
MOVE000010

We also need to choose what to write. LDI writes the immediate, LOAD the value brought from memory, and MOVE the value read from a register. A signal like this, which picks one of several instead of turning something on or off, is called a select signal.

InstructionNumberValue to write
LDI0110Immediate
LOAD1000Memory
STORE1001·
MOVE0000Register

The register to write is usually the instruction’s Rd, but LOAD always writes R0.

InstructionNumberRegister to write
LDI0110Rd
LOAD1000R0
STORE1001·
MOVE0000Rd

STORE always reads R0 and writes it to memory.

InstructionNumberRegister to read
LDI0110·
LOAD1000·
STORE1001R0
MOVE0000·

Here are the four combined.

InstructionNumberRegister writeMemory writeValue to writeRegister to writeRegister to read
LDI011010ImmediateRd·
LOAD100010MemoryR0·
STORE100101··R0
MOVE000010RegisterRd·

From table to circuit

First, let’s pick the row. Decoding the job number with a decoder makes only that number’s row 1.

Change OP3~OP0 to 1000. Only LOAD becomes 1.

Next, for each control signal, we OR together the rows of the instructions where that signal is 1. For example, REG W must be 1 for LDI, LOAD, and MOVE, so we OR those three rows, and MEM W is 1 only for STORE, so we wire the STORE row straight to it. Select signals work the same way once we number the choices.

Enter a number that isn’t in the table, like 0001. No row of the OP DECODER turns on, so every signal is 0.

Abstraction

As instructions grow, we just add to it the same way, so from now on let’s draw this circuit as a single CONTROL box.

Each time you change CLK to 1 and back to 0, the next instruction in memory goes into CONTROL. Compare the signals that come out with the table.

A machine that does all four

Let’s attach CONTROL to the machine. The job number (OP) goes into CONTROL, and the MUX in front of IN picks the immediate (IMM), the value read from memory (MEM), or the value read from a register (REG) according to SRC. For LOAD and STORE, the memory’s data ports (DADDR, DOUT, IN) are wired up, and MUXes in front of the register numbers to write and read can pick R0 instead of Rd.

Change CLK to 1 and back to 0, four times over. The 5 in slot 13 is loaded into R0 and moved to R1, then 2 is put into R0 and stored in slot 14.

Wrapping up

Now the machine picks what to do by looking at the job number. But it still only moves numbers and can’t compute. In the next post, let’s make instructions that compute with register values.

Challenge

To simplify the control unit, we removed the register-to-write (WA) signal. Now every instruction that writes a register writes the register named by the first 2 of the last 4 bits, the Rd position. Of the 16 instructions LOAD 0 through LOAD 15, how many still put their value into R0 as before? Answer with a number.