KS5H446 1.1.1 40 min read 10 question quiz 25 exam marks

Structure and Function of the Processor

The full fetch decode execute cycle with every register and bus, pipelining, and the architectures you must be able to compare at A Level depth.

Components and registers

The core components

ComponentFunction
ALUPerforms all arithmetic and logical operations, and the shifts used in multiplication and division
Control UnitDecodes instructions, generates control signals, synchronises components to the clock and directs data flow
RegistersExtremely fast storage inside the processor holding values currently in use
CacheSmall, very fast memory holding recently and frequently accessed instructions and data
ClockGenerates the regular pulse that synchronises all operations

The registers you must know

RegisterContents
PC Program CounterAddress of the next instruction to be fetched
MAR Memory Address RegisterThe address currently being read from or written to
MDR Memory Data RegisterThe data or instruction transferred to or from memory
CIR Current Instruction RegisterThe instruction currently being decoded and executed
ACC AccumulatorThe result of ALU operations
Status registerFlags such as zero, negative, carry and overflow set by the last operation
A Level goes beyond GCSE by adding the CIR

At GCSE the instruction sits in the MDR. At A Level it is copied from the MDR into the CIR so that the MDR is free for the data the instruction needs.

Buses

  • Address bus. Unidirectional, carrying memory addresses from the processor. Its width determines the maximum addressable memory: an n bit address bus can address 2n locations.
  • Data bus. Bidirectional, carrying data and instructions. Its width determines how much data moves per transfer, so a wider data bus increases throughput.
  • Control bus. Bidirectional, carrying control signals such as read, write, clock, interrupt request and bus request.

A 32 bit address bus can address 232 locations, which is about 4 GB. This is precisely why 32 bit systems could not use more than 4 GB of RAM.

Components of the CPU and the three busesThe central processing unit contains a control unit which decodes instructions and coordinates the other components, an arithmetic logic unit which performs calculations and comparisons, a set of registers holding the program counter, memory address register, memory data register, current instruction register and accumulator, and cache holding recently used data and instructions. The CPU connects to main memory and to input and output devices through three buses. The address bus carries addresses one way out of the processor, the data bus carries data and instructions in both directions, and the control bus carries control signals in both directions.CENTRAL PROCESSING UNITControl Unitdecodes and coordinatesArithmetic Logic Unitcalculates and comparesREGISTERSPCMARMDRCIRACCCacheMain memoryRAMInput and outputdevicesAddress busone way, out of the CPUData bustwo wayControl bustwo way
The address bus is one way because addresses only ever travel out of the processor. The data bus is two way because data travels in both.
The fetch decode execute cycle inside the processorThe processor on the left, with main memory on the right, joined by three buses. Inside the processor are the program counter, the memory address register, the memory data register, the current instruction register, the control unit and the arithmetic logic unit. The cycle runs like this. The program counter holds the address of the next instruction, here 0x04A. That address is copied into the memory address register and sent to memory along the address bus, which is one way. Memory sends the contents of that address, here the instruction LDA 7, back along the data bus into the memory data register, and it is copied to the current instruction register. The control unit decodes the instruction and works out what has to happen, sending signals along the control bus when memory is involved. The arithmetic logic unit carries it out, and the program counter moves on by one.CENTRAL PROCESSING UNITPCprogram counter0x04AMARmemory address0x04ACIRcurrent instructionLDA 7MDRmemory dataLDA 7CUcontrol unitdecodesALUarithmetic logic unitadds, compares, ANDsaddress busdata buscontrol busMain memory (RAM)0x049ADD 30x04ALDA 70x04BSTA 90x04CJMP 2a real memory module12345
  1. The program counter holds the address of the next instruction.
  2. That address goes to memory along the address bus.
  3. The instruction comes back along the data bus and lands in the MDR.
  4. The control unit decodes it and works out what has to happen.
  5. The ALU executes it, and the program counter moves on by one.
Address out, data back, control alongside. The address bus is one way: memory never sends an address to the CPU.
A processor, from above and from belowA processor chip lying face up out of its socket, with the heat spreader on top and hundreds of gold contact pads covering the underside.topunderneaththe metal lid is a heat spreaderthe silicon is a few millimetres wide, beneath ithundreds of gold contact padsthey press onto the socket's pinspin 1 marker
The metal lid is a heat spreader, not the processor. The silicon doing the work is a square a few millimetres across underneath it.Drawn illustration

The fetch decode execute cycle in full

Fetch

  1. The address in the PC is copied into the MAR.
  2. The PC is incremented.
  3. The address in the MAR is placed on the address bus and a read signal is sent on the control bus.
  4. The instruction at that address is returned on the data bus into the MDR.
  5. The instruction is copied from the MDR into the CIR.

Decode

  1. The Control Unit splits the instruction in the CIR into its opcode and operand.
  2. The opcode identifies the operation. The operand is the data or the address of the data.
  3. Control signals are generated for the units that will carry it out.

Execute

  1. The instruction is carried out: an ALU operation with the result in the accumulator, a transfer to or from memory, or a change to the PC in the case of a jump.
  2. The status register flags are updated.

The cycle then repeats.

Interrupts

An interrupt is a signal from a device or program requesting the processor's attention.

At the end of each cycle the processor checks the interrupt register. If an interrupt of higher priority than the current task is present:

  1. The contents of the registers are copied to a stack, saving the current state
  2. The relevant interrupt service routine is loaded and executed
  3. When it completes, the previous state is popped from the stack back into the registers
  4. Execution resumes exactly where it left off

Because a stack is used, interrupts can nest, so a higher priority interrupt can interrupt an interrupt service routine.

Interrupts are examined every year

Learn the sequence, including that the check happens at the end of a cycle and that the stack is what makes nesting possible.

The fetch decode execute cycleA seven stage walk through the fetch decode execute cycle. In fetch, the address in the program counter is copied into the memory address register, the program counter is incremented, the address travels out on the address bus to main memory, and the instruction returns on the data bus into the memory data register and then the current instruction register. In decode, the control unit splits that instruction into an opcode saying which operation to perform and an operand giving the data or its address. In execute, the instruction is carried out and any result from the arithmetic logic unit is placed in the accumulator with the status flags updated. Control then returns to fetch and the whole cycle repeats, around three billion times a second on a 3 gigahertz processor.CENTRAL PROCESSING UNITPCMARMDRCIRControl Unit + ALUMAIN MEMORY0x04A ADD 120x04B STA 20address busdata busPC → MARPC = PC + 1address out on the address businstruction back on the data bus → MDR → CIRopcode + operandcarry it out, update the flagsrepeat
Step through the cycle. Naming the registers and buses in this order is what turns a one mark answer into a full mark one.

Performance and architectures

Factors affecting performance

FactorEffect
Clock speedMore cycles per second means more instructions per second, but heat and power rise sharply
Number of coresGenuine parallel execution, limited by whether software is multi threaded and by Amdahl's law
Cache size and levelsHigher hit rate means fewer slow accesses to main memory
Word lengthLonger words mean more data processed per operation
Bus widthA wider data bus increases throughput, a wider address bus increases addressable memory

Pipelining

Instructions are broken into stages, and while one instruction is being executed the next is being decoded and a third is being fetched.

Cycle 1: Fetch A Cycle 2: Fetch B Decode A Cycle 3: Fetch C Decode B Execute A Cycle 4: Fetch D Decode C Execute B

Throughput rises to roughly one instruction per cycle even though each instruction still takes three cycles.

The problem is branching. When a conditional jump is taken, the instructions already in the pipeline are wrong and must be discarded, which is a pipeline flush. Processors use branch prediction to guess which way a branch will go and reduce this cost.

Von Neumann against Harvard

Von NeumannHarvard
MemoryOne shared memory for instructions and dataSeparate memories, and separate buses
BusesOne set, sharedTwo sets, one for each memory
SpeedSlower, because instructions and data compete for the same bus, the von Neumann bottleneckFaster, since an instruction and data can be fetched simultaneously
Cost and complexityCheaper and simplerMore expensive and more complex
Typical useGeneral purpose computersEmbedded systems and digital signal processors

Many real processors are hybrid: von Neumann in main memory, Harvard at the cache level with separate instruction and data caches.

RISC against CISC

RISCCISC
Instruction setSmall, simple instructionsLarge, complex instructions
Instruction lengthFixedVariable
Cycles per instructionUsually oneSeveral
Instructions per taskMoreFewer
PipeliningStraightforward, because instructions are uniformDifficult, because instruction lengths vary
ComplexityIn the compiler and the softwareIn the hardware
Power useLowerHigher
ExamplesARMx86

The trade off is where the complexity sits. RISC pushes it into the compiler, CISC builds it into the hardware. RISC dominates mobile devices because of its power efficiency and its suitability for pipelining.

Co-processors and parallel systems

  • A GPU has thousands of simple cores optimised for performing the same operation on large amounts of data at once, which suits graphics, machine learning and scientific simulation.
  • Multicore systems run genuinely parallel threads.
  • Parallel processing speeds up work only to the extent that the task can be divided. Amdahl's law states that the maximum speedup is limited by the fraction of the task that must remain sequential.
Von Neumann architecture compared with Harvard architectureTwo architectures side by side. In von Neumann, one CPU connects through a single shared bus to one memory holding both instructions and data, so instructions and data compete for that bus, which is the von Neumann bottleneck. In Harvard, one CPU connects through two separate buses to two separate memories, one holding instructions and one holding data, so an instruction and its data can be fetched at the same time.Von NeumannCPUHarvardCPUMemorycode + dataone shared businstructions and data compete for the busInstructionmemoryDatamemorytwo busesan instruction and data can be fetched at once
Harvard is faster because an instruction and data can be fetched simultaneously. Von Neumann is cheaper and more flexible.
Three instructions with and without a pipeline: nine cycles against fivePipelining shown on a grid of clock cycles. Every instruction has three stages: fetch, decode and execute. Without a pipeline, instruction 1 finishes all three stages before instruction 2 starts, and so on, so three instructions take 9 cycles. With a pipeline the stages overlap: in cycle 2 instruction 1 is being decoded while instruction 2 is fetched, and in cycle 3 instruction 1 executes while instruction 2 is decoded and instruction 3 is fetched. All three instructions finish in 5 cycles, which saves 4. One instruction still takes three cycles, so the gain is in throughput, close to one instruction per cycle. When a conditional jump is taken, the instructions already in the pipeline are the wrong ones and are discarded, which is a pipeline flush, so processors use branch prediction.No pipeline: one at a timecycle123456789Instruction 1FetchDecodeExecuteInstruction 2FetchDecodeExecuteInstruction 3FetchDecodeExecute9 cycles in allWith a pipeline: stages overlapcycle123456789Instruction 1FetchDecodeExecuteInstruction 2FetchDecodeExecuteInstruction 3FetchDecodeExecute5 cycles in all4 cycles saveda taken branch flushes it,so branches are predicted123
  1. Without a pipeline each instruction finishes fetch, decode and execute before the next one starts: 3 instructions take 9 cycles.
  2. With a pipeline the stages overlap, so while one instruction executes the next is decoded and the one after is fetched: 5 cycles.
  3. One instruction still takes 3 cycles. The gain is throughput. A taken branch flushes the pipeline, which is why branches are predicted.
Pipelining does not make one instruction faster. It raises throughput by keeping every stage busy at once.

Key terms you must be able to define

ALU
Arithmetic Logic Unit, performing all arithmetic and logical operations.
Control Unit
The component that decodes instructions and generates control signals to coordinate the processor.
CIR
Current Instruction Register, holding the instruction currently being decoded and executed.
Status register
A register holding flags such as zero, carry, negative and overflow set by the last operation.
Opcode
The part of an instruction identifying which operation to perform.
Operand
The part of an instruction giving the data or the address of the data to operate on.
Interrupt
A signal requesting the processor's attention, checked at the end of each cycle.
Interrupt service routine
The code executed in response to a particular interrupt.
Pipelining
Overlapping the fetch, decode and execute stages of consecutive instructions to increase throughput.
Pipeline flush
Discarding instructions already in the pipeline after a branch is taken.
Von Neumann bottleneck
The limit imposed by instructions and data sharing a single bus and memory.
Harvard architecture
An architecture with separate memories and buses for instructions and data.
RISC
Reduced Instruction Set Computer, using a small set of simple, uniform instructions.
CISC
Complex Instruction Set Computer, using a large set of powerful, variable length instructions.
Amdahl's law
The principle that speedup from parallelism is limited by the sequential fraction of a task.

Flashcards

Say the definition out loud before you flip the card. Retrieving it from memory is what builds recall, reading it again is not.

DefineALU
AnswerArithmetic Logic Unit, performing all arithmetic and logical operations.
DefineControl Unit
AnswerThe component that decodes instructions and generates control signals to coordinate the processor.
DefineCIR
AnswerCurrent Instruction Register, holding the instruction currently being decoded and executed.
DefineStatus register
AnswerA register holding flags such as zero, carry, negative and overflow set by the last operation.
DefineOpcode
AnswerThe part of an instruction identifying which operation to perform.
DefineOperand
AnswerThe part of an instruction giving the data or the address of the data to operate on.
DefineInterrupt
AnswerA signal requesting the processor's attention, checked at the end of each cycle.
DefineInterrupt service routine
AnswerThe code executed in response to a particular interrupt.

Reach the top grade on this topic

A Level answers on this topic must go beyond the GCSE version in three specific ways.

Include the CIR and the status register. A cycle description that stops at MDR is a GCSE answer. The instruction moves MDR to CIR, and the flags update on execute.

Explain the mechanism of the interrupt, including the stack. Registers are pushed to a stack, the ISR runs, the registers are popped back. The stack is what permits nesting, and saying so shows genuine understanding.

Quantify where you can. An n bit address bus addresses 2n locations. A 32 bit bus therefore reaches 4 GB, which explains a real historical limitation.

On comparisons, give the underlying cause. RISC pipelines well because its instructions are fixed length and take a uniform number of cycles. Harvard is faster because an instruction and its data can be fetched simultaneously rather than competing for one bus.

  • Write the full ten step cycle from memory, naming every register and bus
  • Describe the interrupt sequence including the stack and nesting
  • Explain pipelining, the branching problem and branch prediction
  • Compare RISC and CISC and Harvard and von Neumann with causes, not just properties

Mistakes that cost marks here

Avoid these
  • Giving the GCSE five step cycle at A Level, with no CIR and no status register.
  • Saying interrupts are checked continuously. They are checked at the end of each cycle.
  • Omitting the stack from an interrupt answer, which loses the explanation of nesting.
  • Saying RISC is 'simpler so faster'. It executes more instructions per task but pipelines far better.
  • Confusing the address bus and data bus roles when explaining addressable memory.
Fun fact

Pipelining is why a modern processor completes roughly one instruction per cycle despite each instruction taking several cycles to finish. It is the same idea as a production line: nobody waits for the first car to be finished before starting the second.

Knowledge check

0 of 10 answered
1Which register holds the instruction currently being decoded?
2A processor has a 36 bit address bus. How many memory locations can it address?
3When are interrupts checked?
4What is stored on the stack when an interrupt occurs?
5What is a pipeline flush?
6What is the von Neumann bottleneck?
7Which is characteristic of RISC?
8Why is a GPU well suited to machine learning?
9What does Amdahl's law state?
10Which flag in the status register indicates a result of zero?
Score 0 / 10

Exam-style questions

Five written questions in the style of the real paper. Write a full answer, then let the marker check it against the mark scheme.

25 marks
1Describe the fetch stage of the fetch decode execute cycle, referring to the registers and buses involved.5 marks
Describe

Mark scheme0 / 5
  • LThe address in the Program Counter is copied to the MAR
  • LThe Program Counter is incremented
  • LThe address is placed on the address bus
  • LA read signal is sent on the control bus
  • LThe instruction returns on the data bus into the MDR and is then copied to the CIR
Model answer

The address of the next instruction, held in the Program Counter, is copied into the Memory Address Register, and the Program Counter is then incremented so that it points at the following instruction. The address held in the MAR is placed on the address bus and a read signal is asserted on the control bus. Main memory responds by placing the contents of that location onto the data bus, from where it is loaded into the Memory Data Register. The instruction is then copied from the MDR into the Current Instruction Register, leaving the MDR free for any data the instruction subsequently requires.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
2Explain how a processor handles an interrupt.5 marks
Explain

Mark scheme0 / 5
  • LInterrupts are checked at the end of each fetch decode execute cycle
  • LThe priority of the interrupt is compared with that of the current task
  • LThe contents of the registers are pushed onto a stack to save the current state
  • LThe relevant interrupt service routine is loaded and executed
  • LAfterwards the saved state is popped back and execution resumes where it left off
Model answer

At the end of each fetch decode execute cycle the processor checks the interrupt register to see whether any interrupt has been raised. If one has, its priority is compared with that of the task currently executing, and if it is lower the interrupt is left pending. If it is higher, the processor saves its current state by pushing the contents of all its registers, including the Program Counter, onto a stack. The address of the appropriate interrupt service routine is then loaded into the Program Counter and that routine is executed. When it finishes, the saved register contents are popped from the stack and restored, so the interrupted program continues from exactly the point where it was suspended. Because a stack is used, an interrupt service routine can itself be interrupted by a higher priority interrupt and each state is restored in the correct reverse order.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
3Explain how pipelining improves processor performance and describe one situation in which its benefit is reduced.5 marks
Explain

Mark scheme0 / 5
  • LInstructions are divided into stages such as fetch, decode and execute
  • LDifferent instructions occupy different stages at the same time
  • LThroughput approaches one instruction completed per cycle
  • LA conditional branch may mean the instructions already fetched are the wrong ones
  • LThe pipeline must then be flushed, wasting the work already done
Model answer

Pipelining divides instruction processing into separate stages, typically fetch, decode and execute, and allows different instructions to occupy different stages at the same time. While one instruction is being executed, the next is being decoded and a third is being fetched, so although each individual instruction still takes three cycles to complete, one instruction finishes on every cycle once the pipeline is full, which raises throughput substantially without any increase in clock speed. The benefit is reduced when a conditional branch is encountered. The processor has already fetched and begun decoding the instructions that follow sequentially, but if the branch is taken those are not the instructions that should execute next. The pipeline must therefore be flushed and refilled from the branch target, discarding several cycles of completed work. Processors mitigate this using branch prediction, which guesses the likely outcome based on previous behaviour and speculatively fills the pipeline accordingly.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
4Compare the von Neumann and Harvard architectures.6 marks
Compare

Mark scheme0 / 6
  • LVon Neumann uses a single memory for both instructions and data
  • LHarvard uses separate memories for instructions and data
  • LVon Neumann uses one set of buses, Harvard uses separate buses for each memory
  • LHarvard can fetch an instruction and data simultaneously, so it is faster
  • LVon Neumann suffers from the bottleneck of instructions and data competing for one bus
  • LVon Neumann is cheaper and simpler, Harvard is used in embedded and DSP systems
Model answer

The von Neumann architecture stores both instructions and data in a single shared memory, accessed through one set of address, data and control buses. The Harvard architecture uses physically separate memories for instructions and for data, each with its own set of buses. This leads directly to the key performance difference: in a Harvard system an instruction can be fetched at the same time as data is read or written, whereas in a von Neumann system both must use the same bus and therefore compete, producing what is known as the von Neumann bottleneck. The compensating advantages of von Neumann are cost and flexibility. Only one memory and one bus set are needed, which makes the hardware cheaper and simpler, and because instructions and data occupy the same memory the division between them can be varied freely, which suits general purpose computers running unpredictable workloads. Harvard architecture is more expensive and less flexible, since the split between instruction and data memory is fixed by the hardware, so it is used chiefly in embedded systems and digital signal processors where the program is fixed and predictable performance matters more. Many modern processors are hybrid, presenting a von Neumann model at the level of main memory while using separate instruction and data caches internally to gain the Harvard speed advantage.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
5Explain how the width of the address bus and the width of the data bus each affect the performance and capability of a processor.4 marks
Explain

Mark scheme0 / 4
  • LThe address bus width determines how many memory locations can be addressed
  • LAn n bit address bus can address 2 to the power n locations
  • LThe data bus width determines how much data is transferred in one operation
  • LA wider data bus increases throughput, so fewer transfers are needed for the same data
Model answer

The width of the address bus determines the size of the address space, because each line carries one bit of the address. An n bit address bus can therefore specify 2 to the power n distinct locations, which is why a 32 bit address bus limits a system to approximately 4 GB of addressable memory and why moving to 64 bit addressing was necessary. The width of the data bus determines how many bits are transferred between the processor and memory in a single operation. A 64 bit data bus moves eight bytes per transfer where a 32 bit bus moves four, so for the same volume of data half as many transfers are required, which directly increases throughput and reduces the time the processor spends waiting for memory.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
Machine mark 0 / 25