Build a CPU From Logic Chips: The 4-Bit TD4 Self-Made CPU Explained

Most people who build electronics kits end up with a blinking LED and a vague sense of accomplishment. The TD4 4-bit CPU kit gives you something fundamentally different: after you finish soldering, you will understand — at the gate level — exactly how a computer executes a program. Not metaphorically. Literally, because every functional block of the CPU is a physical chip on the board in front of you.

The design originates from Kaoru Tonami's Japanese book How to Build a CPU, and this RetroMakerKits edition brings it to English-speaking makers with full documentation, tested components, and a PCB that makes the architecture visible rather than hiding it.

TD4 4-bit CPU kit assembled PCB showing CPU board and ROM board with DIP switches
The assembled TD4 kit: CPU board (left) and ROM board (right) with 16 rows of 8-bit DIP switches. Each switch is one bit of one instruction.

Why Build a CPU From Logic Gates?

Modern processors run at 3–5 GHz and contain billions of transistors. That's impressive, but it's also completely opaque. You can read about registers and ALUs in a textbook, but nothing in a textbook replicates the moment when you single-step a program through the TD4 and watch the LED output change exactly as your mental model predicted — because you set every instruction by hand, and you can trace every signal path back to a physical chip.

The TD4 operates at roughly 1–10 Hz (you can hear it "thinking"), uses a 4-bit data bus, has 16 bytes of ROM, and runs a 16-instruction machine language. Compared to a modern CPU, it's absurdly underpowered. Compared to any other way of learning how a CPU works, it's unbeatable.

What's Inside: 14 Chips, One CPU

The entire machine is built from nine 74HC-series logic chip types — the same medium-scale integrated circuits used in 1970s and 1980s digital electronics. Here's what each one does:

  • 74HC161 × 4 — 4-bit synchronous presettable binary counters. Three serve as general-purpose registers (A, B, C) and one acts as the program counter (D). The LOAD (~LD) pin on each register is the key control signal: when the instruction decoder asserts it, that register captures the current ALU output.
  • 74HC153 × 2 — Dual 4-input multiplexers. Together they form a 4-bit 4-channel data selector, choosing which operand (register A, register B, input switches, or nothing) feeds into the adder. The selection lines are part of the control bus output from the instruction decoder.
  • 74HC283 × 1 — 4-bit binary full adder. This is the entire ALU. It adds two 4-bit values and produces a sum and a carry-out. There is no subtraction, no multiplication, no logic operations — just addition. The instruction set is designed around this constraint.
  • 74HC74 × 1 — Dual D flip-flop. One flip-flop captures the carry-out from the adder on each clock edge, creating a persistent carry flag that the JNC (Jump if No Carry) instruction can test.
  • 74HC138 × 2 — 3-to-8 line decoders. Cascaded to create a 4-to-16 decoder: the 4-bit program counter address uniquely activates one of 16 output lines (active-low), selecting one row of the ROM.
  • 74HC540 × 1 — Octal buffer/line driver. Buffers the ROM data outputs to protect the DIP switches from being driven by multiple sources simultaneously.
  • 74HC14 × 1 — Hex Schmitt-trigger inverter. Two inverters with an RC network form the clock oscillator. Two more handle RESET button debouncing. Schmitt hysteresis is what makes the RC oscillator stable and the buttons reliable.
  • DIP switches (16 × 8-bit) — The ROM. 16 rows of 8 switches each. Every switch is one bit of one instruction word. You program the machine by flipping switches.

How the Fetch-Decode-Execute Cycle Works on This Board

TD4 CPU complete circuit schematic showing all 74HC chips and their interconnections
Complete circuit schematic. Every signal path is traceable to a physical chip pin.

On every rising clock edge, three things happen in sequence:

  1. Fetch: The program counter (register D, a 74HC161) outputs its current 4-bit value as an address. The two 74HC138 decoders convert this address into a single active-low signal on one of 16 lines, selecting exactly one row of DIP switches.
  2. Decode: The selected row presents an 8-bit value on the data bus. The upper 4 bits (D7–D4) go to a combinational decoder made from NAND gates. Together with the carry flag, these bits produce four control outputs: the ~LD signals for each register, and the A/B select lines for the multiplexers.
  3. Execute: The multiplexers route the correct operand through the adder. The adder computes a sum. Whichever register has its ~LD asserted will latch that sum on the clock edge. If the opcode is JMP or JNC (and the carry condition is met), the program counter loads a new value instead of incrementing.

The Instruction Set in Plain English

The lower 4 bits of each instruction word (D3–D0) are always an immediate value — a literal number embedded directly in the instruction. Here's what the 12 usable instructions do:

  • MOV A, Im — Load register A with the immediate value
  • MOV B, Im — Load register B with the immediate value
  • ADD A, Im — Add immediate to A; result in A, carry flag updated
  • ADD B, Im — Add immediate to B; result in B, carry flag updated
  • MOV A, B — Copy B into A
  • MOV B, A — Copy A into B
  • IN A — Read the 4-bit input DIP switches into A
  • IN B — Read the 4-bit input DIP switches into B
  • OUT Im — Drive the 4 output LEDs with the immediate value
  • OUT B — Drive the 4 output LEDs with register B
  • JMP Im — Unconditional jump to address Im
  • JNC Im — Jump to address Im only if the carry flag is clear

That's it. The only arithmetic operation is addition. Subtraction, comparison, and bitwise operations don't exist as opcodes — you implement them through clever sequencing of what's available. Working within these constraints is itself a valuable exercise in understanding what a minimal stored-program computer actually requires.

The ROM: Your DIP Switches Are Your Assembler

There is no software toolchain. No assembler, no IDE, no USB download. You write a program by deciding what each of the 16 instruction slots should do, converting each instruction to its 8-bit binary representation, and flipping the corresponding switches. Row 0 is address 0x0 (the reset vector), row 15 is address 0xF.

The diodes in series with each DIP switch pole are essential: without them, selecting one ROM address would inadvertently pull down data lines through adjacent unselected rows. The diodes enforce one-way current flow, making each row electrically independent from its neighbors.

Clock and Reset: Why Schmitt Triggers Matter

The clock oscillator is a two-inverter RC circuit. Charging the capacitor through the resistor slowly raises the voltage on the first inverter's input. When it crosses the upper Schmitt threshold, the output switches, beginning the discharge phase. When it crosses the lower threshold, the output switches back. This oscillation period works out to approximately T = 2.2 × R × C. Schmitt hysteresis is what prevents the output from chattering during the slow voltage transitions — a plain inverter would oscillate erratically in the threshold region.

The same principle applies to the reset and clock buttons: the RC network slows down the voltage transitions enough that the Schmitt trigger sees a clean edge even when the mechanical switch bounces 10–20 times in a millisecond.

Try the Simulator Before You Build

TD4 CPU online simulator at vanya.jp.net showing animated signal flow with red and blue wires
The online TD4 simulator at vanya.jp.net/td4. Red wires carry high signals (5 V), blue wires carry low (0 V). You can watch the fetch-decode-execute cycle happen in real time.

Before ordering a kit, spend 20 minutes with the online simulator. Load a simple program, set the clock to slow, and step through it manually. By the time you watch the program counter increment, the decoder activate a ROM row, and a register latch a result, you'll have already started understanding how the hardware works. That understanding makes the physical build far more satisfying.

Specs at a Glance

Comparison table showing TD4 CPU specs versus modern CPUs - data width, clock speed, instructions
TD4 versus modern CPUs. The point isn't the numbers — it's that every single aspect of the TD4's operation is visible and understandable at the circuit level.

What You Can Build With It

With 12 instructions, a 4-bit data path, and 16 bytes of ROM, you can still write meaningful programs:

  • LED binary counter — MOV B, Im followed by ADD B, Im in a JMP loop. Watch the output LEDs count in binary.
  • Knight Rider scanner — A sequence of OUT Im instructions with specific bit patterns, looped with JMP. Each step shifts the lit LED one position.
  • Input reader — IN A reads the physical input DIP switches. Combine with ADD and JNC to branch based on what the switches say.
  • Carry-based state machine — Use ADD to count toward overflow, then JNC to branch when carry clears. Implement simple sequences and timed patterns.

Who Should Build This

This kit is the right choice if any of these describes you:

  • You're taking a computer architecture or digital electronics course and want something to reinforce the theory with tangible hardware
  • You've read about flip-flops, multiplexers, and decoders but never connected them into a working system
  • You're a teacher who wants a demonstration that shows fetch-decode-execute without a single line of software
  • You built retro computers and want to understand what's under the hood at the most fundamental level

If you've never soldered before, this is not an ideal first project — it's a second or third project. The soldering itself is entirely through-hole (no SMD), but there are a lot of joints and the build will go much better if you're already comfortable with the iron.

Kit Contents

  • PCB — professionally manufactured, all components through-hole, suitable for beginners with prior soldering experience
  • 74HC ICs: 4× 74HC161, 2× 74HC153, 1× 74HC283, 1× 74HC74, 2× 74HC138, 1× 74HC540, 1× 74HC14
  • 16× 8-position DIP switches (ROM programming)
  • 4× input DIP switch (IN A / IN B)
  • Resistors, capacitors, diodes, LEDs
  • IC sockets for all ICs
  • USB-A power input (5 V, ~100 mA)
  • English assembly guide with circuit explanation

All ICs are individually tested before shipping. A defective gate in any chip stops the whole machine — we test every chip's logic function before it ships, because a dead IC in a 14-chip build is the most demoralising possible outcome.

Build Order and Tips

  • Install IC sockets first, then passive components (resistors, capacitors, diodes), then the DIP switches, then the LEDs. Insert the ICs last.
  • Before inserting any IC: power the bare board and verify 5 V between VCC and GND at each IC socket. Fix any shorts before proceeding.
  • Insert and test one functional block at a time. Start with the clock (you should see the LED flash). Then add reset. Then the ROM decoder. Then register A only — verify that MOV A, Im works before connecting the remaining registers.
  • The most common build error is a wrong DIP switch setting. If the board runs but produces wrong output, re-verify your ROM program before suspecting a soldering fault.
  • Unexpected behaviour on JNC almost always traces to the 74HC74 carry flag — check that its D input (connected to the adder carry-out) and CLK input (connected to the system clock) are both correctly soldered.

Resources

  • GitHub Repository — KiCad schematics, PCB layout, BOM, and full Chinese-language technical tutorial with circuit diagrams
  • Online Simulator — Animated fetch-decode-execute cycle, runs in your browser
  • AllDatasheet — Full datasheets for all 74HC parts used in this kit
  • RetroMakerKits Docs — English assembly documentation and errata

→ Shop the TD4 4-Bit CPU Kit

Back to blog