Basic Bits

You only need one bit to build a functional CPU. It doesn’t make for a particularly useful CPU; you can flip a bit and that’s pretty much it. But it is the simplest CPU you can build and an excellent starting point for figuring out how a CPU works.

The 1-bit CPU is a 1-bit CPU because its ALU can only do calculations on 1-bit numbers and the register only stores a 1-bit number.

Clock

Goes tick-tock at a steady rate, allowing the processor to synchronize all memory reads and writes

Press to get the clock going. Or click to pulse the clock manually. If you want it to run at 1 MHz, just click very fast.

Any part of the circuit that stores a bit of memory needs a clock to tell it when to store the input value. Both the program control unit and the register use a flip-flop, so they need the signal from the clock.

That signal goes 0, 1, 0, 1, 0, 1, and on, and on. It does this at a steady rate, called the clock rate. The clock rate tells you how often per second the clock shows a 0 and a 1. If the clock rate spends half a second being 0 and then flips to 1 for half a second, the clock rate is 1 Hz, because the clock will show each value once per second. If the clock rate spends a quarter being 0, then flips to 1 for a quarter second, then back to 0, and back to 1, the clock rate is 2 Hz, because the clock shows each value twice per second.

The 1-bit processor runs at 0.5 Hz, so it spends one second being 0 and one second being 1. Now, don’t you accuse it of being slow! It could do 10 Hz, or 1000 Hz, or even many MHz, but you wouldn’t be able to see what’s going on. It’s just trying to be helpful.

Program control unit (PCU)

Keeps track of where you are in the running program by storing the address of the next instruction and increasing it by one every time the clock ticks.

The 1-bit processor has a grand total of two instructions that it can store. The PCU keeps track of which instruction will be executed next. If the flip-flop is set to 0, then the processor will execute the first instruction next, if it’s set to 1, the processor will execute the second instruction next.

Every tick of the clock, the PCU will increase the program counter by 1. First, 0 + 1 = 1, then 1 + 1 = 10. This being a 1-bit processor, we can’t actually store all the bits of that second increase. That’s fine. We’ll just throw away that bit at the front. The result is that the program counter alternates between 0 and 1. That’s what the not-gate is doing.

Memory controller

Receives the program counter from the PCU and outputs the instructions at the address specified by the program counter.

You can program the processor by clicking on the two toggles. Since the program counter is 1-bit, it can only point to instruction 0 and instruction 1, so any more instructions than that we wouldn’t be able to address. The instructions themselves are also 1-bit, meaning we can only have two instructions.

  • 0: NOP - Don’t do anything.
  • 1: FLIP - Flip the bit in the register. (Make it 1 if it’s 0, make it 0 if it’s 1.)

Great, we only have two instructions and one of them is: do nothing. There’s a limited number of things you can do with only one bit. Flipping the bit is really the only interesting operation and we’ve got that one!

There’s an and-gate tied to each instruction. The left input to the and-gate determines whether the instruction is selected. So, for instruction 0, the left input of the and-gate is 1 if the program counter is 0. For instruction 1, the left input of the and-gate is 0 if the program counter is 1. That’s how the memory controller determines which instruction to pass on. Because of the and-gate, the other instruction will be 0, so or-ing the output of the and-gates will give you the value of the selected instruction.

Register

Stores the result of a calculation after executing an instruction. The next instruction can fetch the content of the register and change it some more.

The register is a flip-flop and that’s it. The output of the arithmetic logic unit is the input for the flip-flop. The flip-flop stores that input on every tick of the clock.

The register also servers as input to the arithmetic logic unit. That’s how you can take the value of the register and do some calculation on it.

Arithmetic logic unit (ALU)

When you need to calculate the result of an instruction, you can count on the arithmetic logic unit.

The ALU receives two inputs: the data in the register, and the current instruction. Since the ALU supports two different instructions, there are two paths through the ALU. The ALU doesn’t select which path to take at the beginning. Instead, the data goes through both paths and at the end the ALU decides which result to keep. In other words, both instructions are executed simultaneously, but one of the results is discarded.

The FLIP instruction is executed by the not-gate on the right. A not-gate flips its input, which is exactly what we want, so this single gate is all we need.

The NOP instruction is executed by the wire going into the left and-gate. Running data through a wire doesn’t look much like executing an instruction, but remember, NOP is supposed to do nothing. If you want a different instruction, you would put it in place of the wire.

The and-gates select which result will be passed on. The left and-gate outputs the result of NOP, but only if the current instruction is 0. The right and-gate outputs the result of FLIP, but only if the current instruction is 1. The output of the and-gate that isn’t selected will always be 0 and is filtered out by the or-gate.