CPU in 3D

A standing 3D board showing the CPU instruction cycle: fetch, decode, execute and store blocks linked by arrows.Drag to turn

A central processing unit (CPU) is the chip that carries out the instructions of a program, one small step at a time. It reads binary instructions from memory, decodes them, and performs the arithmetic, logic and data movement they describe.

The main parts inside a processor

A CPU is built from billions of transistors, tiny electronic switches grouped into logic gates. These gates form a few main units. The arithmetic logic unit (ALU) does addition, comparison and bitwise operations. The control unit directs which part does what and when.

Registers are very small, very fast storage cells inside the CPU. They hold the values the CPU is working on right now. A special register called the program counter holds the memory address of the next instruction.

The fetch, decode, execute cycle

The CPU repeats one basic cycle. In the fetch step it reads the instruction at the address in the program counter. In the decode step the control unit works out which operation is requested and which registers or memory locations are involved. In the execute step the ALU or another unit performs the operation, and the result is stored.

The program counter then moves to the next instruction, usually by adding the size of the current one. Jump and branch instructions change the counter to a new address instead. This is how loops and if statements work at machine level.

A clock signal sets the pace. Each tick lets the circuits move one stage forward. A clock speed of 3 GHz means 3 billion ticks per second.

A worked example: adding two numbers

Suppose memory holds the value 5 at one address and 7 at another. A program loads 5 into register A and 7 into register B. It then issues an add instruction that sends both registers to the ALU.

The ALU computes 5 + 7 = 12 and writes 12 into register A. A store instruction copies 12 back to memory. That is four instructions: two loads, one add and one store. Each one passes through its own fetch, decode and execute cycle.

At 3 GHz, if each instruction took one tick, these four would need 4 / 3,000,000,000 seconds, about 1.3 nanoseconds. Real instructions often take more or fewer ticks, so this is only an illustration.

Common misconceptions

Clock speed alone does not decide how fast a CPU is. Work done per tick, the number of cores and memory delay also matter. A core is one complete processing unit, and many modern CPUs contain several.

The CPU does not understand programming languages directly. It runs machine code, which is binary instructions in the instruction set of that CPU design. Compilers and interpreters translate human-written code into that form.

Where CPU design shows up

Every phone, laptop and server relies on a CPU or a similar processor. Different families use different instruction sets, so a program built for one usually will not run unchanged on another. Techniques such as caches, which keep recently used data close to the CPU, and pipelining, which overlaps the stages of several instructions, make real processors much faster than the simple cycle suggests.

Key terms

ALU
The arithmetic logic unit, the circuit that performs arithmetic and logical operations.
Register
A tiny, fast storage cell inside the CPU that holds values being processed.
Program counter
A register holding the address of the next instruction to fetch.
Instruction set
The set of binary operations a particular CPU design can execute.
Clock speed
The number of clock ticks per second, measured in hertz.
Cache
A small, fast memory that stores recently used data near the CPU.

Common questions

What is the difference between a CPU and a core?

A core is one processing unit that can run its own instruction stream. A CPU chip may contain one core or several, which lets it work on multiple tasks at once.

Why do CPUs use binary?

Transistors work reliably as switches with two states, on and off. Those two states map to the digits 1 and 0, so binary suits the hardware.

How is a CPU different from a GPU?

A CPU has a few powerful cores suited to varied tasks. A GPU has many simpler cores suited to doing the same operation on large amounts of data.

Learn this with a tutor

Sidechair's AI tutor will teach this topic in 3D. Join the waitlist for early access.

We'll only email you about Sidechair. Read our privacy policy.