How a Processor Works: From Transistor to Program
A processor is the most complex device in your computer, yet it can be built from very simple parts. In this article we walk the whole path: from a transistor that can only switch current on and off, to a program the processor executes instruction by instruction. In the Ershov Computer simulator, you can walk this path in practice — level by level.
The transistor: the atom of a computer
It all starts with the transistor — a tiny switch with three terminals. When voltage is applied to the control terminal, the transistor opens and lets current through. Remove it, and the transistor closes, blocking current. No magic: two stable states, "on" and "off".
We label these states 1 and 0 — logical one and zero. This is how binary code is born, the language of all digital technology. Learn more about why machine language is made of zeros and ones in 0 and 1: Machine Language.
One transistor stores one bit. Your processor is built from billions of such switches — but fortunately, a few dozen are enough to understand the principles.
Logic gates: transistors learn to think
Transistors alone are useless. Engineers combine them into logic gates — circuits that decide by rules what to do with the signals on their inputs:
- NOT inverts a signal: 0 → 1, 1 → 0.
- AND outputs 1 only when both inputs are 1.
- OR outputs 1 when at least one input is 1.
- XOR (exclusive OR) outputs 1 when the inputs differ.
- NAND and NOR are the negations of AND and OR.
A remarkable property of gates: they work in parallel. A signal changing on an input propagates through the whole circuit instantly — there is no execution queue. This is why processors handle billions of operations per second. Basic gates are covered in Logic Gates AND, OR, NOT, and their truth tables in the datasheets.
The adder: gates learn to count
The next step is arithmetic. To add two bits you need two gates: XOR produces the sum, AND produces the carry. That is a half adder. Add a third input for the carry from the lower bit — and you get a full adder, which adds three bits and outputs the sum and carry.
Chain eight full adders and you get an 8-bit adder that adds bytes: 01100101 + 00011010 = 01111111. Arithmetic looks like bit-by-bit mechanics, but this is exactly how processors have been adding numbers for decades. For the circuit breakdown, see Adder Anatomy.
The ALU: the heart of mathematics
An adder can add, but a processor needs more: subtraction, logical operations, comparison. Combine an adder, some logic gates and a multiplexer that selects the operation — and you get an arithmetic-logic unit (ALU).
The ALU is the processor's chief mathematician. It takes two bytes and an operation code, and outputs a result plus status flags — for example, a zero flag the processor uses to decide whether to take a conditional jump. For the ALU's construction, see ALU: Heart of Math.
Memory: flip-flops, registers, RAM
Logic circuits instantly forget their inputs. To remember, you need a feedback element — an SR latch made of two gates, then a D flip-flop that stores one bit on the clock edge. Eight D flip-flops form an 8-bit register — a tiny one-byte warehouse.
Registers are the processor's ultra-fast memory. Next comes RAM — an array of cells addressed by number. In the Ershov Computer simulator, RAM is 256 bytes, and you can access a cell by its address. How latches and flip-flops become memory — in Feedback Magic (SR Latch) and Registers: First Byte of Memory.
The clock generator: the orchestra conductor
Circuits run in parallel and uncoordinated. To make a processor work as one, it needs a common rhythm — set by the clock generator. It emits a sequence of pulses, and each pulse ("tick") synchronizes every element.
Why does this matter? D flip-flops capture a value strictly at the clock edge. All processor operations run by ticks: on one tick the circuit computes, on the next the result is "latched" into registers. Details in Clock and D Flip-Flop and Timing Diagram.
The program counter and the decoder
A program is a sequence of bytes in memory. But how does the processor know which instruction to execute? The program counter (PC) is a register holding the address of the current instruction. After each instruction the PC increments by one, moving to the next; on a jump instruction the PC is overwritten with the destination address.
An instruction is one byte: the high 4 bits are the opcode, the low 4 bits are the operand (for example, a memory address). The decoder turns the opcode into a set of control signals: "read memory", "enable addition in the ALU", "write to the register". This is how the processor knows what to do. Both devices are covered in Program Counter and Instruction Decoder.
Buses and program memory
A processor talks to memory over buses — bundles of wires. The address bus says which cell to access, the data bus carries the bytes, the control bus indicates the direction (read or write). Eight data-bus wires carry one byte at a time.
A classic design keeps instructions and data in one memory. The Harvard architecture used by the simulator's computer separates them: ROM stores the program, RAM stores data. This simplifies and speeds things up. Learn more in Harvard Architecture: Divide and Conquer.
Assembly: the processor's language
Writing programs in raw bytes is inconvenient. That's why assembly was invented — mnemonic names for instructions. LDA 5 means "load into the accumulator the value from RAM[5]", ADD 3 — "add RAM[3]", JZ 7 — "jump to address 7 if the accumulator is zero".
Assembly is the most honest language: every line of a program directly controls the hardware. Programs in assembly are executed by the processor exactly like high-level programs — only there a compiler does the translation. For a language overview, see Assembly: The Most Honest Language and the assembler manual.
The instruction cycle: how it all works together
Now let's put it all together. A processor's work is an endless repeating loop called the instruction cycle:
- Fetch. The program counter outputs an address; program memory returns the instruction byte.
- Decode. The decoder turns the opcode into control signals.
- Execute. The ALU performs the operation (e.g. addition); memory provides or accepts data.
- Write back. The result is latched into the accumulator register.
- Next. The program counter increments by one — and it all repeats.
In the Ershov Computer simulator, one tick is half an instruction cycle: on the clock rising edge the fetch and execution happen, on the falling edge the result is latched. That's why instructions appear on odd ticks in the assembler log.
Build a processor yourself
Now that you understand the processor's internals, it's time to build one with your own hands. In the logic circuit simulator the path takes 47 levels: wire → half adder → 8-bit adder → D flip-flop → ALU → a processor with assembly → Snake on your own processor. The course curriculum shows how much time each stage takes.
Test yourself
How does every processor operation begin?
By reading an instruction from program memory: the program counter provides the address, the decoder deciphers the opcode.
Why does a processor need a clock generator?
It sets the common rhythm: within one tick the circuit settles, and all blocks act in step.
Why is the ALU called the heart of mathematics?
All arithmetic and logic (addition, AND, OR, and so on) is performed by the ALU; the rest of the machine brings data to it and the results back.
FAQ
How many transistors are in a processor?
Modern processors contain tens of billions of transistors. But the principle hasn't changed since the first 4-bit chips: transistors form gates, gates form logic, logic forms a processor.
Why is a processor so fast?
First, circuits run in parallel — all bits are processed at once. Second, clock frequencies of modern chips reach gigahertz, meaning billions of ticks per second. Each tick covers part of an operation.
Where should I start learning?
The best path is practice: start with the first simulator level and read library articles in parallel. In Ershov Computer, theory and practice go hand in hand.