University of Wales Trinity Saint David
ACCA4021 - Introduction to Computer Systems

Registers

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:

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?

Registers are part of the CPU’s own circuitry. Reaching main memory means sending a request along the bus and waiting for the reply.

If registers are so fast, why does a computer not just have millions of them instead of main memory?

Every register is built into the CPU. Space on the CPU chip is limited and expensive, so CPUs have a small number of registers backed by much larger, slower memory.

Task 2 - The special-purpose registers

RegisterFull nameWhat it holds
PCProgram CounterThe address of the next instruction to be fetched
MARMemory Address RegisterThe address of the memory location about to be read or written
MDRMemory Data Register (also called the MBR, Memory Buffer Register)The value just read from memory, or about to be written to it
CIRCurrent Instruction RegisterThe instruction currently being decoded and executed
ACCAccumulatorThe 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?

The Program Counter always points at the next instruction.

Which register is the only one connected to the address bus?

Every address the CPU sends to memory goes out through the MAR.

Which register is the only one connected to the data bus?

Every value read from or written to memory passes through the MDR.

Which register holds the instruction that is being carried out right now?

The Current Instruction Register keeps the instruction while the control unit decodes and executes it.

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?

Every bit of the MAR drives one wire of the address bus. If the MAR were narrower, some address wires would never be used and part of memory could not be reached. If it were wider, the extra bits would have no wires to go out on.

Why does the CPU need both a PC and a MAR? Could the PC be connected straight to the address bus instead?

The address bus is not only used to fetch instructions. When an instruction reads or writes data, the address of the data has to go out on the bus while the PC keeps pointing at the next instruction. Having a separate MAR means the PC never has to be overwritten just to reach a piece of data.

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.

TransferMeaning
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] + 1Add 1 to the PC
CIR ← [MDR]Copy the MDR into the CIR
MAR ← operandCopy 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.

No. Once MAR ← [PC] has been done, the MAR already holds the address being fetched, so changing the PC does not affect the read. It only matters that the PC is incremented after its value has been copied into the MAR. If the PC were incremented first, the CPU would fetch from the wrong address.

Task 5 - Check your understanding

The PC holds 7. Which statement is true?

The PC holds the address of the next instruction to fetch.

What does ACC ← [MDR] mean?

The arrow points to the register being written. The square brackets mean "the contents of".

Which pair of registers sits between the CPU and the buses to memory?

The MAR drives the address bus and the MDR connects to the data bus. Every memory access goes through these two.