Fundamentals 13 min read

How Simple Logic Gates Build a CPU: From Diodes to 4‑Bit Adders

This article explains how basic semiconductor concepts and diode‑based logic gates can be combined into simple arithmetic circuits, registers, and a minimal instruction set to construct a functional 4‑bit CPU, illustrating each step with diagrams and historical context.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How Simple Logic Gates Build a CPU: From Diodes to 4‑Bit Adders

Semiconductor Basics

A semiconductor is a material whose conductivity lies between that of a conductor and an insulator; diodes are a common example, allowing current to flow in one direction while blocking it in the opposite direction.

Diodes as Logic Elements

When the anode (A) is at a higher voltage than the cathode (C), the diode conducts; otherwise it behaves as an open circuit. This property can be interpreted as a binary "1" (conducting) or "0" (non‑conducting).

Diode symbol and behavior
Diode symbol and behavior

Logic Gates Using Diodes

By arranging diodes, we can implement basic gates:

AND gate : output is low only when both inputs are high.

OR gate : output is low only when both inputs are low.

NOT gate : inverts the input voltage.

XOR gate : output is high when exactly one input is high.

These gates can be drawn with simplified symbols for easier analysis.

Logic gate symbols
Logic gate symbols

Building Simple Adders

A half‑adder adds two single‑bit numbers, producing a sum (S) and a carry (C). Extending this, a full‑adder adds three bits (two operands plus a carry‑in) and yields a sum and a carry‑out. By chaining four full‑adders we obtain a 4‑bit adder capable of adding numbers up to 15 (binary 1111).

4‑bit adder diagram
4‑bit adder diagram

Multiplication by Shifting

Multiplying a binary number by two is equivalent to shifting it left by one position and inserting a zero at the least‑significant bit. Multiplying by three can be achieved by a left shift (×2) followed by an addition of the original number, and similarly for other small constants.

Flip‑Flops and Registers

A flip‑flop (FF) stores a single bit of data. The RS‑type FF has two inputs: Reset (R) clears the stored bit to 0, and Set (S) stores a 1. By connecting multiple FFs in parallel we form a register capable of holding multi‑bit values (e.g., 4‑bit or 8‑bit registers).

RS flip‑flop schematic
RS flip‑flop schematic

Multiplexers (MUX)

A multiplexer selects one of several input lines based on a selector signal (sel). For a 2‑to‑1 MUX, sel=0 routes input i0 to the output, while sel=1 routes input i1. Larger MUXes can select among more inputs, such as a 4‑to‑1 selector.

Multiplexer diagram
Multiplexer diagram

Designing a Minimal CPU

The prototype CPU uses eight input pins: four for the instruction word and four for data. Three instructions are defined: 0100 – Load data into the register. 0001 – Add the data to the register and store the result. 0010 – Shift the register left by one bit (multiply by 2).

Each instruction activates the corresponding module (register, adder, or shifter) via an enable pin. Execution proceeds in three stages: fetch the instruction, perform the operation, and write back to the register.

Instruction Execution Steps

A simple CPU follows the three‑step cycle described above, whereas a classic RISC pipeline expands this to five stages: Instruction Fetch (IF), Instruction Decode (ID), Execute (EX), Memory Access (MEM), and Write‑Back (WB). Real‑world x86 CPUs may involve up to twenty micro‑operations for a single instruction.

Historical Note

In 1970, the collaboration between Japan’s BUSICOM and Intel produced the world’s first microprocessor, the Intel 4004, which demonstrated that a CPU could be implemented as a programmable, reusable chip rather than a bespoke, hard‑wired circuit.

Putting It All Together

By combining the described components—diode‑based gates, adders, shifters, flip‑flops, registers, and a small instruction set—we can assemble a functional 4‑bit CPU capable of executing expressions such as (1+4)×2+3. The binary program for this computation is: 01000001000101000010000000010011 Loading this sequence into the CPU demonstrates how machine code (a series of 0s and 1s) directly controls hardware to perform arithmetic operations.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CPUcomputer architectureSemiconductorsdigital electronicslogic gatesaddersflip-flops
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.