The 4-Bit Machine

You didn't just wire circuits. You built a brain. Here is the conceptual guide to how sand becomes software.

From Hardwired to Programmable

In Labs 1-3, you built circuits that did one thing (like an adder). To change what they did, you had to rewire them.

In Lab 4, you built a General Purpose Computer. By changing the numbers in memory (software), the same physical hardware can add, subtract, count, or make decisions without moving a single wire.

The "Von Neumann" Architecture

You built a classic architecture consisting of three pillars:

  • CPU: The worker (ALU + Registers)
  • Memory: The storage (RAM)
  • I/O: The communication (Bus)

The Anatomy of Your Processor

1. The Controller

The Boss

It reads instructions (numbers like 0, 1, 2) and converts them into electrical signals. It tells the other components when to work. It uses a Microcode ROM (a cheat sheet) to know which wires to turn on for each instruction.

2. The Datapath

The Muscle

Includes the ALU (Arithmetic Logic Unit) and the Accumulator. It doesn't decide what to do; it just blindly adds, subtracts, or stores numbers when the Controller tells it to.

3. The Memory

The Library

RAM: Holds your program (the list of instructions).
MAR: (Memory Address Register) holds the address of the specific shelf in the library we want to read from.

The "Heartbeat" of the Machine

Every computer, from this 4-bit chip to the laptop you are using right now, runs in a continuous loop called the Fetch-Decode-Execute cycle. Here is what happened in your simulation every time you clicked the clock.

1

Fetch (Step 0)

The Program Counter (PC) points to the next line of code in RAM. The Controller says "Read RAM!" and pulls that number into the Instruction Register (IR).

2

Decode (Microcode Lookup)

The Controller looks at the number in the IR (e.g., "1"). It checks its internal ROM to see what "1" means. It sees that "1" means "ADD".

3

Execute (Step 1+)

The Controller fires the control signals. It turns on the ALU (arith=1), opens the gates to the Accumulator (load_acc=1), and the math happens. The result is saved.

The "Magic" Secret: Microcode

How does the number "1" physically cause an addition?

You created a translator. The ROM is just a lookup table. When you "programmed" the controller, you basically wrote a list of switch settings.

// Inside the Controller's Brain

IF Instruction == 1 (ADD) THEN:

Turn on ALU Add Wire

Turn on RAM Read Wire

Turn on Accumulator Write Wire

The Control Bus

10 Wires controlling the whole system