Skip to content

B3 · Registers and Interrupts

Spec reference: Section B3 - Computer Architecture Key idea: Understand the purpose of CPU registers and how interrupts allow the CPU to respond to events.


Registers

Registers are small, extremely fast storage locations inside the CPU. They hold data that the CPU is currently working with.

General purpose registers

Used to hold temporary data, operands, and results during calculations. The programmer or compiler can use these freely.

Special purpose registers

Each has a specific, fixed role in controlling the CPU:

RegisterNamePurpose
PCProgram CounterHolds the memory address of the next instruction to be fetched. Automatically increments after each fetch.
IRInstruction RegisterHolds the instruction that has just been fetched from memory and is being decoded/executed.
MARMemory Address RegisterHolds the address in memory that the CPU wants to read from or write to.
MDRMemory Data RegisterHolds the data that has just been read from memory, or data waiting to be written to memory. Acts as a buffer between the CPU and RAM.
ACCAccumulatorHolds the result of arithmetic and logic operations performed by the ALU.

How registers work together in the instruction cycle

  1. Fetch: PC sends address to MAR. Memory sends instruction to MDR. MDR copies instruction to IR. PC increments.
  2. Decode: CU decodes the instruction in IR.
  3. Execute: ALU performs the operation. Result stored in ACC. MAR/MDR used if memory access is needed.

The role of interrupts

An interrupt is a signal sent to the CPU to indicate that an event requires immediate attention. Interrupts allow the CPU to respond to events without constantly checking (polling) for them.

How interrupts work

  1. A device or software sends an interrupt signal to the CPU.
  2. The CPU completes its current instruction.
  3. The CPU saves its current state (registers, PC) to the stack.
  4. The CPU looks up the appropriate Interrupt Service Routine (ISR) in the interrupt vector table.
  5. The ISR runs and handles the event.
  6. The CPU restores its saved state and resumes where it left off.

Types of interrupt

TypeCauseExample
Hardware interruptTriggered by a hardware deviceKeyboard key pressed, mouse click, printer finished
Software interruptTriggered by a programRequesting OS services, system calls
ExceptionError condition in the CPUDivision by zero, illegal memory access

Interrupt priority

Interrupts have priority levels. Higher priority interrupts can interrupt lower priority ISRs. For example, a critical hardware failure will interrupt a routine keyboard handler.

Exam point

The exam often asks you to describe what happens when an interrupt occurs. Remember to mention: saving the current state, looking up the ISR, executing the ISR, and restoring the state.


Summary

TermMeaning
PC (Program Counter)Holds address of the next instruction to fetch
IR (Instruction Register)Holds the instruction currently being decoded
MARHolds the memory address being accessed
MDRHolds data being transferred to/from memory
AccumulatorHolds the result of ALU operations
InterruptA signal asking the CPU to pause and handle an event
ISRInterrupt Service Routine: the code that handles the interrupt

Test Yourself

Ad

PassMaven - revision made simple.