Computer Science › Section C · Data manipulation › Topic C.1

Computer architecture: CPU and stored programs

Storing bits is only half of computing; something has to change them. This topic opens up the processor, shows how it trades data with memory over a bus, and explains the idea that made modern computers possible: keeping the program itself in memory.

From storing data to changing it

Section B showed how a computer stores numbers, text and images as bits. Storage alone does nothing useful, though: a spreadsheet has to add its columns. The circuitry that does this work is the central processing unit, or CPU, usually just called the processor. Early CPUs filled whole cabinets. Today a laptop processor is a small chip plugged into the main circuit board, the motherboard. Because it is so small it is called a microprocessor. In a phone the CPU usually shares one chip with other parts such as graphics circuitry, a design called a system on a chip.

The three parts of a CPU

A CPU has three main parts. The arithmetic/logic unit (ALU) holds the circuits that actually compute: adding, subtracting, comparing, and combining bits with AND, OR and XOR. The control unit coordinates everything, deciding which circuits act and in what order. The register unit holds registers, small storage cells inside the CPU that work like main memory cells but are far faster. General-purpose registers hold the values being worked on: the inputs fed to the ALU and the results it produces. Special-purpose registers have fixed jobs, such as remembering where the program has reached; the topic "Program execution and the machine cycle" meets two of them.

The bus: how the CPU talks to memory

The CPU and main memory are joined by a bus, a set of parallel wires or circuit-board traces. To read a cell, the CPU puts the cell's address on the bus together with a signal meaning "read", and memory answers by sending back the bit pattern stored there. To write, the CPU sends the address, the data and a "write" signal, and memory stores the data in that cell. You can think of the bus as having address lines, data lines and control lines. The ALU never works on memory directly: values must first be copied into registers, and results copied back out.

Worked example: applying a discount

A shop's program must compute a sale price. The original price is in one memory cell, the discount in another, and the answer belongs in a third. What must the CPU do? 1. Read the price from memory over the bus and place it in a general-purpose register. 2. Read the discount into a second register. 3. Tell the ALU to subtract the second register from the first, putting the result in a third register. 4. Write the third register into the answer cell. 5. Stop. Check: the single subtraction is only step 3. Steps 1, 2 and 4 are data transfers across the bus, which is why moving data costs as much attention as computing with it.

The von Neumann model

Most computers follow the same overall plan, usually called the von Neumann model. It has four parts: a CPU; a main memory that holds both programs and the data they work on; input and output devices such as keyboards, screens and drives; and buses connecting them. The CPU repeatedly takes its next instruction from memory and carries it out. Two features matter most. Memory is a single store of numbered cells that does not care whether a cell holds an instruction or a number. And everything the CPU needs, instructions and data alike, travels over the same connection, which later topics show can become a bottleneck.

Programming by rewiring

The first electronic computers did not work this way. ENIAC, which began operating at the University of Pennsylvania around the end of the Second World War, was set up for each new problem by plugging cables between its units and turning banks of switches. The steps of the computation were built into the wiring, not stored as data. Changing from one calculation to another meant physically rearranging the machine, a job that could take days. The program was part of the hardware; only the numbers lived in memory.

The stored-program concept

The breakthrough was to realise that a program is information too, so it can be encoded as bits and kept in main memory beside the data. If the control unit can fetch instructions from memory, decode them and carry them out, then running a different program means only changing memory contents, not wires. This is the stored-program concept, and almost every computer since has used it. The idea was first set out in John von Neumann's 1945 draft report on a planned machine called EDVAC, but it grew from work with J. Presper Eckert, John Mauchly and others, so historians generally argue that the credit should be shared. A small Manchester machine became the first to run a stored program, in 1948.

Registers, cache, memory and mass storage

A computer keeps data at several levels, each trading speed for size. Registers hold the handful of values in use right now. Main memory holds programs and data needed soon. Mass storage, such as an SSD or hard disk, holds everything else, including files not in use. Between registers and main memory sits cache memory, met in the topic "Main memory": a small, very fast memory on the processor chip that keeps copies of recently used memory contents. Many processors have several levels, often called L1, L2 and L3, each larger and slower than the one before, so the CPU looks in the closest level first.

Worked example: where does each item live?

A photo editor is brightening one image while a library of 2,000 photos sits on the SSD. Where is each piece of data most likely to be? 1. The single pixel value the ALU is adding to right now must be in a register, because the ALU takes its inputs only from registers. 2. The nearby pixels in the same row were just fetched together, so copies of them are likely in cache. 3. The whole image being edited is in main memory, since the program needs it soon. 4. The other photos are in mass storage until opened. Check: each level is slower and larger than the last, and data moves upward only when it is about to be used.

Common mistakes to avoid

First, thinking the ALU can add two memory cells directly: in this model the values are copied into registers first. Second, confusing registers with main memory; registers are inside the CPU, few in number and much faster. Third, saying that a "transfer" erases the original; reading a cell copies its pattern and leaves the cell unchanged. Fourth, giving von Neumann sole credit for the stored-program idea, when it came out of a team. Fifth, treating cache as extra storage: it only holds copies of data that also belong in main memory.

Key takeaways

The CPU has an ALU that computes, a control unit that coordinates, and registers that hold the values in use. It reads and writes main memory over a bus by sending an address and a read or write signal. Data must be in registers before the ALU can use it. The von Neumann model has a CPU, one memory for programs and data, input/output devices and buses. The stored-program concept replaced rewiring: change the memory, change the program. Registers, cache, main memory and mass storage form a hierarchy from small and fast to large and slow.

Flashcards

Flashcard

CPU

Central processing unit: the circuitry that manipulates data

Also called the processor.

Test your understanding

Question 1 of 5

A program must add two numbers stored in main memory and save the sum in memory. Which sequence matches how the CPU does it?

Question 2 of 5

What is the stored-program concept?

Question 3 of 5

When the CPU writes a value to a memory cell over the bus, what must it send?

Question 4 of 5

Which statement about cache memory is correct?

Question 5 of 5

Who should get credit for the stored-program concept, according to most historians?

← Previous topicNext topic →