Search the courses, subjects, tracks, games and features, or jump straight to a page.
Learn it your way
A short class with Sarah and her students. The other ways are under More.
Sign up free to listen. Transcripts are free to read.
People call the CPU the brain of the computer. But which part of it actually adds two numbers?
The arithmetic logic unit. It also does comparisons, like checking whether one number is bigger than another.
Right. And who decides what the ALU should do next?
The control unit. It decodes the instruction and sends signals to the other parts.
Good. While they work, the CPU needs somewhere very fast to keep what it is using. Where?
In registers, like the program counter and the accumulator.
Exactly. Registers are tiny but they are the fastest storage in the whole computer.
Suppose the program counter holds the address 100. What happens first in the fetch stage?
The address 100 is copied into the MAR, and the instruction at address 100 comes from memory into the MDR.
Then it is copied into the instruction register. What happens to the program counter?
It goes up to 101, so it points to the next instruction.
Correct. In the decode stage, the control unit splits the instruction into what?
The opcode, which says what to do, and the operand, which says what to do it with.
And in execute the ALU does the work. Then the whole cycle repeats, billions of times a second.
A processor is advertised as 3 GHz, quad-core. What do those two numbers mean?
3 GHz means 3 billion clock cycles every second, and quad-core means it has four cores.
Good. Will a quad-core processor always run a program four times faster than a single core?
Only if the program can be split into four parts that run at the same time.
Exactly. And why does the CPU have cache memory when there is already RAM?
Because RAM is slower, so cache keeps the instructions and data the CPU is likely to need next close at hand.
Well done. Clock speed, cores and cache together decide how fast a CPU really is.
The ALU calculates and compares, the control unit directs, and registers hold the work in progress.
PC (next address), MAR (address being used), MDR (data from memory), IR (current instruction) and ACC (result).
Every instruction is fetched, decoded and executed, and the cycle repeats billions of times a second.
The address bus carries addresses, the data bus carries data both ways, and the control bus carries signals; n address lines reach 2ⁿ locations.
Clock speed, the number of cores and cache memory together decide how fast a processor is.
CISC uses many complex instructions (x86 PCs); RISC uses fewer, simpler instructions (ARM phones).
A small Java simulation of the machine cycle, with a program counter, an instruction register and an accumulator, runs a five-instruction program and finishes with 120 in the accumulator:
public class TinyCPU {
public static void main(String[] args) {
// A program in memory: each instruction is an opcode and an operand
String[] memory = { "LOAD 25", "ADD 17", "SUB 2", "MUL 3", "HALT 0" };
int pc = 0; // Program Counter: address of the next instruction
int acc = 0; // Accumulator: holds the working result
String ir; // Instruction Register: the instruction being executed
boolean running = true;
while (running) {
ir = memory[pc]; // FETCH the instruction at address pc
pc = pc + 1; // point to the next instruction
String[] parts = ir.split(" "); // DECODE: separate opcode and operand
String opcode = parts[0];
int operand = Integer.parseInt(parts[1]);
switch (opcode) { // EXECUTE (the ALU does the arithmetic)
case "LOAD": acc = operand; break;
case "ADD": acc = acc + operand; break;
case "SUB": acc = acc - operand; break;
case "MUL": acc = acc * operand; break;
case "HALT": running = false; break;
}
System.out.println("IR = " + ir + " | PC = " + pc + " | ACC = " + acc);
}
}
}Every arithmetic, comparison and bitwise operator in Java is finally carried out by the ALU; with 12 (1100) and 10 (1010), AND gives 1000, OR gives 1110 and XOR gives 0110:
public class ALUDemo {
// Shows a number as 4 binary digits, keeping leading zeros
static String bits(int x) {
String s = Integer.toBinaryString(x);
while (s.length() < 4) {
s = "0" + s;
}
return s;
}
public static void main(String[] args) {
int a = 12, b = 10; // 12 = 1100 and 10 = 1010 in binary
System.out.println("Arithmetic: " + (a + b) + " " + (a - b) + " " + (a * b) + " " + (a / b) + " " + (a % b));
System.out.println("Comparison: a > b is " + (a > b) + ", a == b is " + (a == b));
System.out.println("AND: 1100 & 1010 = " + bits(a & b));
System.out.println("OR: 1100 | 1010 = " + bits(a | b));
System.out.println("XOR: 1100 ^ 1010 = " + bits(a ^ b));
}
}Java can report how many processors (cores, or hardware threads) the computer makes available to it; the number printed depends on the computer that runs the program:
public class Cores {
public static void main(String[] args) {
int n = Runtime.getRuntime().availableProcessors();
System.out.println("Processors available to Java on this computer: " + n);
}
}Fetch it, decode it, execute it right; the clock keeps the rhythm all day and night.
In a busy kitchen, the head chef (control unit) reads each order slip (instruction) brought from the order rack (RAM), the cook (ALU) chops and mixes, the counter by the stove (registers) holds today's ingredients, and the small fridge beside it (cache) saves trips to the storeroom.
Please Make My Instructions Accurate: PC, MAR, MDR, IR, ACC, in the order the fetch and execute stages use them.
F.D.E.: Fetch, Decode, Execute, the machine cycle that never stops.
Term
Which register holds the address of the next instruction?
Click to flip
Term
What are the three stages of the machine cycle?
Click to flip
Term
What does the ALU do?
Click to flip
Term
What does a clock speed of 3 GHz mean?
Click to flip
Term
Why does a CPU have cache memory?
Click to flip
The part of the computer that fetches, decodes and executes program instructions.
The part of the CPU that performs arithmetic and logical operations, including comparisons.
The part of the CPU that decodes instructions and directs the other parts with control signals.
A very small, very fast storage location inside the CPU.
The register that holds the address of the next instruction to be fetched.
The fetch-decode-execute cycle that the CPU repeats for every instruction.
The number of clock cycles a CPU completes every second, measured in hertz (for example, 3 GHz).
Small, very fast memory inside the CPU that keeps copies of recently used instructions and data.
The Central Processing Unit (CPU) fetches, decodes and executes the instructions of every program; it is built from the arithmetic logic unit, the control unit and registers, and its speed depends on its clock speed, number of cores and cache.
The CPU, or processor, is the part of the computer that actually runs programs. This lesson looks inside it: the arithmetic logic unit (ALU) that calculates and compares, the control unit (CU) that directs every step, and the registers (PC, MAR, MDR, IR and accumulator) that hold what the CPU is working on. It then follows one instruction through the fetch-decode-execute cycle, explains the address, data and control buses, and shows how clock speed, cores and cache memory decide performance, ending with single-core and multi-core processors and the CISC and RISC designs.
The CPU, also called the processor, carries out the instructions of every program. In a modern computer it is a single chip, a microprocessor, mounted on the motherboard. It works hand in hand with main memory (RAM): programs and data are loaded into RAM, and the CPU fetches them from there, one instruction at a time.
The cycle then begins again with the next instruction, billions of times every second.
The CPU is connected to memory and to other devices by groups of wires called buses:
The width of the address bus fixes how many memory locations the CPU can reach. With n address lines it can address 2ⁿ locations, so a 32-bit address bus can reach 2³² = 4,294,967,296 locations, which is 4 GB when each location holds one byte.