From Light Bulbs to CPUs: Building Logic Gates, Adders, and an ALU from Scratch
This article walks through the step‑by‑step creation of digital logic primitives—starting with encoding messages using blinking bulbs, then constructing basic gates, half‑ and full‑adders, a clock oscillator, RAM storage, and finally an arithmetic‑logic unit and simple instruction set—illustrating how complex computation emerges from simple hardware.
1. Encoding and Circuits – Signal Conversion
The story begins with two teenagers who, unable to use their phones at night, devise a secret communication method by representing Chinese characters as sequences of light‑bulb on/off states, reading the bulb status once per second. This illustrates the concept of encoding physical signals into binary information.
2. Logic Gates – Signal Relations
By adding a second switch that must be closed together with the first for the bulb to light, they create a logical relationship between inputs and output, introducing the notion of a logic gate. The two switches act as inputs (0 = open, 1 = closed) and the bulb as the output.
Truth table for an AND gate:
Input A Input B Output
0 0 0
0 1 0
1 0 0
1 1 1They label the circuit as a AND gate and adopt binary notation (1 = connected, 0 = disconnected) for further abstraction.
3. Adders – Signal Computation
To perform arithmetic they explore binary addition. A single‑bit addition table (0+0=0, 0+1=1, 1+0=1, 1+1=10) leads to the design of a half‑adder using an XOR gate for the sum and an AND gate for the carry.
By cascading another half‑adder and an OR gate they obtain a full‑adder , capable of handling the carry from a previous bit.
4. Clock – Oscillating Signal
Adding a feedback loop where closing switch A pulls switch B down, which then opens the circuit and releases B to spring back, creates a self‑oscillating circuit. The alternating on/off pattern is called a clock , and the generated periodic signal is the clock signal .
5. RAM – Storing Signals
To retain data they design a 1‑bit latch: when the data input is 1 and a control pulse transitions from 0 to 1, the output becomes 1 and holds that value until the next control pulse. The same principle with 0 stores a 0. By chaining multiple latches with decoders and selectors they build an 8‑bit random‑access memory (RAM) capable of reading and writing arbitrary addresses.
6. Program – Automation
Introducing a 10‑bit counter (clock‑driven, with a clear input) provides sequential addresses (0‑5) that feed the RAM. Connecting the counter, the ALU, and the RAM enables an automatic accumulation of the stored numbers 1 through 7. The process is described step‑by‑step, showing how each counter value selects a datum, adds it to the running total via the ALU, and stores the intermediate result in the latch.
7. Instruction Set and Control Unit
To make the system programmable they add a second RAM that holds instruction codes. Three instructions are defined:
add – accumulate the value at the current data address.
nop – no operation (disable latch write).
halt – stop the counter (disable count enable).
By mapping instruction RAM addresses to data RAM addresses, the control unit can enable or disable the latch and counter based on the fetched opcode, allowing selective summation and early termination.
With this instruction set, any sequence of add , nop , and halt commands can be programmed to perform arbitrary arithmetic tasks, illustrating the fundamental principles of digital computation, from low‑level hardware to simple software.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
