Overview
A register is a tiny storage location inside the CPU. This worksheet explains why registers exist and introduces the five special-purpose registers every Von Neumann CPU uses to fetch and run instructions: the PC, MAR, MDR, CIR and ACC. In the final task you take the place of the control unit and move values between registers by hand. Work through the tasks in order, and try each question before checking it.
Learning Objectives
By the end of this lab you will be able to:
- Explain what a register is and why registers are faster than main memory
- State the full name and purpose of the PC, MAR, MDR, CIR and ACC
- Distinguish registers that hold addresses from registers that hold data or instructions
- Use register transfer notation to describe moving a value between registers
Concept
Main memory is large but, compared with the CPU, slow. Every trip along the bus to memory costs time. A register holds a single value, often just one word of 8, 32 or 64 bits, but it is built into the CPU itself, right next to the ALU and the control unit, so reading or writing it is almost instant.
Some registers are general-purpose, and programs can use them for anything. Others are special-purpose, and each has one fixed job in fetching and running instructions. This worksheet is about the special-purpose ones.
Moving a value between registers is written in register transfer notation. The arrow points to the register being written, and square brackets mean "the contents of".
MAR ← [PC] copy the contents of the PC into the MAR
Tasks
Task 1 - Why registers are fast
The chart below compares how long it takes the CPU to reach a value in different kinds of storage. The scale is logarithmic, so each grid line is 10 times further than the last. Switch to the human scale view to get a feel for the differences.
Why are registers faster to reach than main memory?
If registers are so fast, why does a computer not just have millions of them instead of main memory?
Task 2 - The special-purpose registers
| Register | Full name | What it holds |
|---|---|---|
| PC | Program Counter | The address of the next instruction to be fetched |
| MAR | Memory Address Register | The address of the memory location about to be read or written |
| MDR | Memory Data Register (also called the MBR, Memory Buffer Register) | The value just read from memory, or about to be written to it |
| CIR | Current Instruction Register | The instruction currently being decoded and executed |
| ACC | Accumulator | The result of the most recent calculation by the ALU |
The CPU also has a status register that holds the ALU’s flags, such as Z (zero) and V (overflow), which you met in the ALU worksheet.
The diagram below shows a simple CPU part-way through running a program. Click each register to see what it does and which paths it uses to move values around. Then try the two Show buttons.
Which register holds the address of the next instruction to fetch?
Which register is the only one connected to the address bus?
Which register is the only one connected to the data bus?
Which register holds the instruction that is being carried out right now?
Task 3 - Addresses or data?
Use the Show buttons in Task 2 to see which registers hold addresses and which hold data or instructions. In this CPU, memory has 16 locations, so an address needs 4 bits, and each memory location holds 8 bits.
The two registers that hold addresses are the and the .
In this CPU the PC is bits wide, because it only ever holds an address.
In this CPU the MDR is bits wide, because it holds a whole memory location.
The diagram shows the CIR holding 0011 0110, which is the instruction ADD .
Why must the MAR be exactly as wide as the address bus?
Why does the CPU need both a PC and a MAR? Could the PC be connected straight to the address bus instead?
Task 4 - You are the control unit
Each button below performs one register transfer. Complete the three challenges by choosing the right transfers in the right order. Try to use the fewest transfers you can. If you get stuck, press Start again.
| Transfer | Meaning |
|---|---|
MAR ← [PC] | Copy the PC into the MAR |
MDR ← [Memory[MAR]] | Read the memory location whose address is in the MAR, and put its contents in the MDR |
PC ← [PC] + 1 | Add 1 to the PC |
CIR ← [MDR] | Copy the MDR into the CIR |
MAR ← operand | Copy the address part of the instruction in the CIR into the MAR |
ACC ← [MDR] | Copy the MDR into the accumulator |
To fetch an instruction, the first transfer is MAR ← [].
After MDR ← [Memory[MAR]], the instruction is copied into the so it can be decoded.
To carry out LOAD 5, the CPU copies the operand into the MAR, reads memory into the MDR, then copies the MDR into the .
In challenge 1, does it matter whether you do PC ← [PC] + 1 before or after MDR ← [Memory[MAR]]? Explain your answer.
Task 5 - Check your understanding
The PC holds 7. Which statement is true?
What does ACC ← [MDR] mean?
Which pair of registers sits between the CPU and the buses to memory?