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.
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.
| Instruction | Number | Register write | Memory write |
|---|---|---|---|
| LDI | 0110 | 1 | 0 |
| LOAD | 1000 | 1 | 0 |
| STORE | 1001 | 0 | 1 |
| MOVE | 0000 | 1 | 0 |
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.
| Instruction | Number | Value to write |
|---|---|---|
| LDI | 0110 | Immediate |
| LOAD | 1000 | Memory |
| STORE | 1001 | · |
| MOVE | 0000 | Register |
The register to write is usually the instruction’s Rd, but LOAD always writes R0.
| Instruction | Number | Register to write |
|---|---|---|
| LDI | 0110 | Rd |
| LOAD | 1000 | R0 |
| STORE | 1001 | · |
| MOVE | 0000 | Rd |
STORE always reads R0 and writes it to memory.
| Instruction | Number | Register to read |
|---|---|---|
| LDI | 0110 | · |
| LOAD | 1000 | · |
| STORE | 1001 | R0 |
| MOVE | 0000 | · |
Here are the four combined.
| Instruction | Number | Register write | Memory write | Value to write | Register to write | Register to read |
|---|---|---|---|---|---|---|
| LDI | 0110 | 1 | 0 | Immediate | Rd | · |
| LOAD | 1000 | 1 | 0 | Memory | R0 | · |
| STORE | 1001 | 0 | 1 | · | · | R0 |
| MOVE | 0000 | 1 | 0 | Register | Rd | · |
First, let’s pick the row. Decoding the job number with a decoder makes only that number’s row 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.
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.
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.
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.
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.