The Part That Follows Instructions
The central processing unit, or CPU, is the part of a computer that carries out a program’s instructions. Memory holds the instructions and data, storage keeps them for the long term, and input and output devices connect to people, but the CPU is where the actual stepping through a program happens. It is sometimes called the processor.
An analogy is a cook following a recipe. The recipe is the program, the ingredients are the data, and the cook is the CPU. The cook reads one line, does what it says, then reads the next. A computer does the same thing, except that each step is tiny and the pace is very fast.
The Fetch-Decode-Execute Cycle
The CPU repeats three main steps.
Fetch. The CPU keeps track of which instruction comes next using a small storage location called the program counter. It asks main memory for the instruction at that address and brings it in.
Decode. An instruction is a pattern of bits, and part of it says which operation to perform while other parts say which values to use. The CPU interprets the pattern to work out what is being asked, for example “add these two numbers” or “copy this value from memory.”
Execute. The CPU carries out the operation. That may be arithmetic, a comparison, moving data, or changing which instruction comes next.
Then the program counter moves on, normally to the next instruction in memory, and the cycle repeats. This loop depends on the stored-program concept, in which instructions and data share memory so the CPU can fetch both.
Jumps Make Programs Flexible
If the CPU only ever moved to the next instruction, programs could not do much. Some instructions instead change the program counter, causing a jump to a different place, and often this happens only if a condition holds, such as one number being larger than another. These conditional jumps allow repetition and decisions. Without them, a program would simply run through a fixed list once.
What Is Inside
A CPU is usually described as having a few main parts.
- The control unit directs the cycle, deciding which circuits to enable at each step.
- The arithmetic logic unit (ALU) performs calculations such as addition and subtraction and logical tests such as comparing values. It is built from logic gates.
- Registers are a small number of very fast storage locations inside the CPU holding the values it is working on right now. Getting data from registers is much quicker than going out to main memory.
Modern processors add more, such as small fast memories called caches, and may contain several processing cores on one chip. These additions mostly aim to reduce waiting and to do more things at once, and the exact designs differ widely.
An Instruction Is Very Small
Each instruction does something modest. A machine’s full set of instructions, its instruction set, may include operations to add, subtract, compare, move data, jump and a few other basic actions. High-level programs in human-readable languages are translated, by compilers and interpreters, into long sequences of these small instructions. A single line in a program may become many instructions.
Different families of processors use different instruction sets, which is why software built for one kind of processor generally cannot run directly on another.
How the Physical Form Changed
The CPU’s job has stayed fairly constant, but its construction has not. The earliest electronic computers built the processing circuits from vacuum tubes, filling cabinets and rooms. In the 1950s and 1960s, transistors replaced tubes, and circuits shrank. Through the 1960s, mainframe computers often spread their processor over many circuit boards.
A major step came in the early 1970s, when the first microprocessors put a whole CPU on a single chip, one of the integrated circuits that were by then common. This made computing inexpensive enough for personal computers in the late 1970s and 1980s. Since then, processors have continued to gain more transistors, though the details of how performance grew are complex and should not be reduced to a single number.
Speed Is Only Part of the Picture
People often judge processors by clock speed, the rate at which an internal timing signal ticks. The clock coordinates the steps of the cycle, and a faster clock means more steps per second. But clock speed alone does not describe how much work gets done. Some processors complete more per tick than others, memory can be a bottleneck, and software design matters as much as hardware. Comparing machines fairly is hard, and any simple ranking should be treated cautiously.
The CPU Is Not the Whole Computer
The CPU depends on everything around it. Operating systems decide which programs get to use it and for how long, so that several tasks appear to run at once. Other chips, such as graphics processors, handle specialized work. Still, the fetch-decode-execute loop remains the core idea, and it is as true for a modern phone as it was for the earliest stored-program machines.