impera Open Impera

A levels Computer Science · Computer systems

Processor architecture and the fetch-execute cycle

1The von Neumann architecture

In the von Neumann architecture, programs and data are stored together in the same memory, and the processor fetches instructions one at a time.

The von Neumann architecture. The CPU's control unit, ALU and registers are linked to main memory by the address, data and control buses.

ComponentJob
control unit (CU)decodes instructions and sends control signals to coordinate the other parts
arithmetic logic unit (ALU)does calculations and logical comparisons
registersvery fast storage locations inside the CPU
clocksends regular pulses that keep every part in step
main memory (RAM)holds the program and data being used
Check yourself

What does the von Neumann architecture store in the same memory?

  • Only data

  • Only instructions

  • Both program instructions and data

  • Only the operating system

Show the answer

Both program instructions and data

Stored-program concept.

2Registers

RegisterHolds
program counter (PC)the address of the next instruction to fetch
memory address register (MAR)the address about to be read from or written to
memory data register (MDR)the data or instruction just read from memory, or about to be written
current instruction register (CIR)the instruction being decoded and executed
accumulator (ACC)the results of calculations in the ALU
status registerflags such as overflow, zero and negative
Check yourself

Which register holds the address of the next instruction?

  • The MDR

  • The CIR

  • The accumulator

  • The program counter

Show the answer

The program counter

PC points ahead.

3Buses

A bus is a set of parallel wires that carries signals between the CPU, memory and input/output controllers.

BusCarriesDirection
address busmemory addressesone-way: CPU to memory
data busdata and instructionstwo-way
control bussignals such as read, write, clock and interrupttwo-way

The width of the address bus sets how much memory can be addressed: with n lines, 2ⁿ addresses. A 32-bit address bus can address 2³² = about 4.3 billion locations (4 GiB of bytes).

The width of the data bus sets how many bits move in one go: a wider bus moves more data each clock cycle.

Check yourself

Why is the address bus one-way?

  • It is faster that way

  • Memory has no addresses

  • Only the CPU sends addresses to memory

  • Data travels on it in both directions

Show the answer

Only the CPU sends addresses to memory

CPU chooses where.

4The fetch-decode-execute cycle

The CPU repeats this cycle billions of times a second. [X] means "the contents of X".

  1. Fetch: MAR ← [PC]. The address of the next instruction goes to the MAR.
  2. The address is sent along the address bus, and a read signal along the control bus.
  3. MDR ← [Memory[MAR]]. The instruction comes back along the data bus into the MDR.
  4. PC ← [PC] + 1, so it points to the next instruction.
  5. CIR ← [MDR]. The instruction is copied to the CIR.
  6. Decode: the control unit splits the instruction into opcode (what to do) and operand (what to use).
  7. Execute: the instruction is carried out, for example the ALU adds a value to the accumulator, or data is loaded or stored. A jump instruction changes the PC.
Check yourself

When is the program counter increased?

  • Only when a branch instruction changes the flow of the program

  • During the execute stage only, after the instruction runs

  • During the fetch stage, after its value is copied to the MAR

  • Before its value is copied to the MAR

Show the answer

During the fetch stage, after its value is copied to the MAR

Points to the next one.

5Interrupts

An interrupt is a signal to the CPU that something needs attention, such as a key press, a printer running out of paper, a timer, or an error.

  1. At the end of each fetch-decode-execute cycle, the CPU checks for interrupts.
  2. If there is one with a higher priority than the current task, the CPU saves the contents of its registers (on a stack).
  3. It runs the interrupt service routine (ISR) for that interrupt.
  4. It restores the saved registers and carries on where it left off.

Interrupts let the CPU respond quickly to events without constantly checking every device (polling).

Check yourself

Why does the CPU save its registers before running an interrupt service routine?

  • To delete the old program so that it does not run again

  • So it can carry on the interrupted task exactly where it stopped

  • To speed up the ISR by giving it empty registers to use

  • To free up memory for the interrupt service routine to use

Show the answer

So it can carry on the interrupted task exactly where it stopped

Return afterwards.

6Performance and other architectures

Factors that affect performance:

  • Clock speed: more cycles per second, so more instructions per second.
  • Number of cores: several instructions can run at once, but only if the program can be split into parallel tasks.
  • Cache: small, very fast memory on the CPU holding frequently used data, reducing slow trips to RAM.
  • Word length: the number of bits processed in one go.
  • Bus width: more bits moved per cycle; a wider address bus allows more memory.

Pipelining overlaps stages: while one instruction executes, the next is decoded and the one after is fetched. A jump can force the pipeline to be flushed.

The Harvard architecture keeps instructions and data in separate memories with separate buses, so both can be fetched at the same time. It is used in embedded systems and digital signal processors, and inside CPU caches.

Check yourself

Why does doubling the number of cores not always double the speed?

  • Cores slow each other down every time they share the same cache

  • Some tasks cannot be split into parts that run at the same time

  • Software cannot use more than one core at the same time

  • All cores share one clock, so they cannot run faster together

Show the answer

Some tasks cannot be split into parts that run at the same time

Not all work is parallel.

Now test yourself

This lesson has a 8-question quiz and 5 exam-style questions with mark schemes in Impera. Free, with your progress saved.

Practise in Impera