yeolyi.comSeongyeol's CS

Instructions

Let’s build the machine from the stored programs post with the parts we’ve made. So far, a person had to change the circuit’s inputs by hand at every step.

Let’s start with the simplest case. The only part is a register file, and the job is to write 0 or 1 into one register at each step. The inputs a person used to set are four: the write address WA1·WA0, Write, and IN. Try it yourself. The value in each register is shown inside the box.

  1. Write 1 into register 1. Change WA1·WA0 to 01, IN and Write to 1, then change CLK to 1. R1 becomes 1.
  2. Next, write 1 into register 2. Lower CLK and Write to 0, change WA1·WA0 to 10, then change Write and CLK back to 1. R2 becomes 1.

Each step takes three or four switch changes by hand. Let’s hand this work to the machine.

Writing the job as numbers

Each input is either 0 or 1, so the inputs for one step can be written as a few bits. One job for the machine written as bits is called an instruction. The machine in this post only ever writes, so we fix Write at 1 and write down only the address and IN, which change from step to step. “Write 1 into register 1” has the address WA1·WA0 = 01 and IN = 1, so it’s 01 1.

Instruction (tap to change)
WA1WA0INR1value 1

01 1: write 1 to register 1

Tap the bits to change them. The three bits tell which register to write and what to write.

We put these instructions into memory in order, starting at slot 0. Then at each step, we just read that step’s slot. Which slot to read is decided by a counter. Feeding the counter value into the memory address gives that slot’s instruction, and wiring those bits to the register file’s address and IN lets the memory give the inputs instead of a person. The counter goes up with every clock, so the machine moves to the next instruction by itself.

Counter0
Memory (tap to change)
AddressIN
0
1
2
3
Register file
R00
R10
R20
R30

Press Next to start reading from slot 0.

  1. Press Next. The machine writes into a register as the slot the counter points to says, and the counter goes up by 1 to point to the next slot.
  2. Tap bits in memory to change them and run it again. The circuit stays the same, but what it does changes.

Now a person only has to write instructions into memory. These instructions written in memory are the program we saw in stored programs.

Building the circuit

Now let’s wire this machine as a circuit. The counter value goes into the memory’s address, and the memory outputs that slot’s three bits at once. This 3-bit signal is drawn as a single line. The faint number next to the slash (/) on the line is the number of bits, and next to it is the current value. The narrow bar on the right (SPLIT) splits the 3-bit signal into three lines: WA1, WA0, and IN.

Change CLK to 1 and back to 0, four times over. The highlighted slot in memory moves down one at a time: R1 and R3 become 1, R1 goes back to 0, and then R0 becomes 1.

Wrapping up

With the counter counting steps and the memory giving that step’s instruction, the machine works on its own without human hands. But for now, this machine can only put preset values into registers. How should we write instructions to give it jobs that need other parts, like adding? Let’s find out in the next post.

Challenge

The post's instruction is 3 bits: a 2-bit address and a 1-bit IN. If we grow to 16 registers and make the value to write (IN) 8 bits, how many bits is one instruction? Answer with a number.