OCR H446, section 1.1.1 (a)
The central processing unit (CPU) carries out the instructions of a program. It is built from a few main parts, which work together using registers and buses.
The main parts of the processor
Arithmetic logic unit (ALU)
The ALU does the calculations and comparisons:
- arithmetic operations: add, subtract (and multiply and divide, in many processors);
- logical operations: AND, OR, NOT, XOR;
- shifts and comparisons, such as "is this value zero or positive?"
It takes its input from registers, and puts the result back in a register (usually the accumulator).
Control unit (CU)
The control unit is the manager of the processor. It:
- fetches each instruction from memory, and decodes it;
- sends control signals to the ALU, the registers, memory and I/O to carry the instruction out;
- keeps everything in step with the clock.
Registers
A register is a very small, very fast store inside the processor, holding one value. The registers you need to know are these.
| Register | Name | What it holds |
|---|---|---|
| PC | Program counter | The address of the next instruction to be fetched |
| ACC | Accumulator | The result of calculations done by the ALU, and the data currently being worked on |
| MAR | Memory address register | The address of the memory location being read from or written to |
| MDR | Memory data register | The data or instruction that has just been read from memory, or is about to be written to it |
| CIR | Current instruction register | The instruction being decoded and executed |
The MAR and MDR are the gateway to memory: every access starts by putting an address in the MAR, and the data passes through the MDR.
The buses
A bus is a set of parallel wires that carries signals between components. Each wire carries one bit, so the width of a bus is how many bits it carries at once.
| Bus | Carries | Direction |
|---|---|---|
| Address bus | The address of the memory location (or device) to use | One way: from the processor to memory |
| Data bus | The data and instructions being transferred | Two way: to and from the processor |
| Control bus | Control signals: read, write, clock, interrupt requests | Two way |
- The width of the address bus decides how much memory can be addressed: locations for lines. A 16-bit address bus can address locations.
- The width of the data bus decides how much data moves in one transfer.
How this relates to assembly language programs
Each assembly instruction makes the processor use these registers and buses. For example, an assembly instruction such as LDA 10 (load) means "load the value at address 10 into the accumulator". Here is what happens:
- The address 10 is placed in the MAR, and put on the address bus.
- A read signal is sent on the control bus.
- Memory puts the contents of location 10 on the data bus, and it arrives in the MDR.
- The value is copied from the MDR into the ACC.
The same pattern works for STA (store), with the data going the other way. (Writing and following whole programs in the Little Man Computer's assembly language comes in 1.2.4 (c).)
Worked example
Task: the instruction STA 25 is executed when the accumulator holds 40. Describe what happens in the registers and buses.
- The operand 25 is placed in the MAR and sent along the address bus.
- The value 40 is copied from the ACC into the MDR.
- The control unit sends a write signal on the control bus.
- The value 40 travels from the MDR along the data bus, and is stored in memory location 25.
- The ACC still holds 40, because storing copies the value and doesn't erase it.
Exam tip: keep the registers distinct. PC is the address of the next instruction, MAR is an address, MDR is data, CIR is the instruction being executed and ACC holds ALU results. For buses, give the direction: the address bus is one way.
Check yourself
What does the program counter hold?
The address of the next instruction to be fetched.
What is the difference between the MAR and the MDR?
The MAR holds the address of the memory location being accessed. The MDR holds the data (or instruction) being transferred to or from that location.
Which bus is one-way, and what does it carry?
The address bus. It carries the address of the memory location from the processor to memory.
How many memory locations can a 12-bit address bus address?
.