The Processor: CPU Components and the Fetch-Decode-Execute Cycle

Every program in this course, from a one-line printf to a 2-bit counter, eventually runs on a processor. The processor, or CPU (central processing unit), is the part of the computer that fetches instructions from memory, decodes them and carries them out. In this lesson you will meet the main parts of the CPU named in the syllabus, the special registers that move addresses and data, and the fetch–decode–execute cycle that turns a stored program into action. A tiny one-address machine, written in C, will run the same cycle you step through by hand.

What you will learn

  • The jobs of the ALU and the control unit.
  • The five registers CAPE expects you to name: PC, MAR, MDR, IR and the accumulator, plus what each one holds.
  • How an instruction moves from memory into the IR, and how the PC is updated.
  • The three stages of the fetch–decode–execute cycle, traced on a short program.
  • How the same machine can be written as a C program.

Part 1: The parts of the CPU

A simple processor has two large blocks and a handful of registers:

  • The arithmetic logic unit (ALU) does the arithmetic (add, subtract) and the logical operations (AND, OR, NOT) you met in earlier lessons. It takes values from registers and writes a result back, often also setting flags such as zero or overflow.
  • The control unit (CU) is the director. It inspects the current instruction and sends the signals that tell the ALU, the registers and the memory what to do, and in which order.

The registers that sit around those two blocks each have a specialised job. Learn them as a set:

RegisterHoldsUsed when
Program counter (PC)The address of the next instructionFetch; also written by a jump
Memory address register (MAR)The address of the location being read or writtenAny memory access
Memory data register (MDR)The bits travelling to or from memoryAny memory access
Instruction register (IR)The instruction that has just been fetchedDecode, and during execute
Accumulator (ACC)A data value the ALU is working onLOAD, ADD, STORE in a one-address machine

A useful way to keep them apart: the MAR always holds an address, the MDR always holds data (which might be an instruction during fetch), the IR holds the current instruction, and the PC holds the next address. The accumulator is just a convenient data register; some processors have several general-purpose registers instead of a single accumulator. All of these registers are built from flip-flops, as in D and JK Flip-Flops, Registers and Counters, and they are the fastest storage in the machine (see Memory Types and Features).

Try it 1CPU parts

Tap a unit or register. The box explains what it holds and when it is used.

Part 2: The fetch–decode–execute cycle

A stored program is just numbers in memory. The CPU runs it by repeating three stages, once per instruction:

  • Fetch. The address in the PC is copied to the MAR. Memory reads that location and places the bits in the MDR. Those bits are copied into the IR. The PC is then increased so that it points at the next instruction (PC ← PC + 1 in a machine whose instructions are all one word long).
  • Decode. The control unit inspects the IR, splits it into an opcode (what to do) and, if there is one, an address or operand (where the data is). It sets up the paths the execute stage will need.
  • Execute. The operation is carried out. That might mean a memory read or write, an ALU operation, or a write to the PC (a jump). Then the cycle starts again at fetch, unless the instruction was HALT.

A short example will make the transfers concrete. We will use a one-address machine whose instructions are two decimal digits: the tens digit is the opcode (1 = LOAD, 2 = ADD, 3 = STORE, 0 = HALT) and the units digit is a memory address. The program and its data sit in an 8-cell memory:

AddressContentsMeaning
014LOAD 4
125ADD 5
236STORE 6
30HALT
43data
55data
60result (starts empty)

The program means: put 3 into the accumulator, add 5, store 8 at address 6, and stop. Follow LOAD all the way through:

  • Fetch: PC is 0, so MAR ← 0, MDR ← 14, IR ← 14, PC ← 1.
  • Decode: 14 means opcode 1 (LOAD) and address 4.
  • Execute: MAR ← 4, MDR ← mem[4] = 3, ACC ← 3.

Then ADD 5 leaves ACC = 8, STORE 6 writes 8 into mem[6], and HALT ends the cycle. Try it 2 steps this exact program, and highlights the memory row that the MAR is pointing at.

Try it 2Fetch–decode–execute stepper

A tiny one-address machine running LOAD 4, ADD 5, STORE 6, HALT. Tap Next step to walk through every stage. The highlighted memory row is the address in the MAR.


Part 3: The same machine in C

The program below is the stepper in Try it 2, written out in C. Each instruction is stored as 10 * opcode + address, so ir / 10 gives the opcode and ir % 10 gives the address (the remainder after dividing by 10). The accumulator, the PC and the memory are ordinary variables and an array.

#include <stdio.h>

/* A tiny one-address CPU.
   Opcode 1 = LOAD  (ACC = mem[ad])
          2 = ADD   (ACC = ACC + mem[ad])
          3 = STORE (mem[ad] = ACC)
          0 = HALT
   Program at 0..3; data at 4, 5, 6. */
int main(void)
{
    int mem[8] = {14, 25, 36, 0,
                  3, 5, 0, 0};
    int pc = 0, acc = 0;
    int ir, ad, op, step;

    for (step = 1; step <= 4; step++) {
        /* FETCH */
        ir = mem[pc];
        op = ir / 10;
        ad = ir % 10;
        printf("Fetch  PC=%d IR=%d\n",
               pc, ir);
        pc = pc + 1;
        /* DECODE and EXECUTE */
        if (op == 1) {
            acc = mem[ad];
            printf("  LOAD %d, ACC=%d\n",
                   ad, acc);
        } else if (op == 2) {
            acc = acc + mem[ad];
            printf("  ADD  %d, ACC=%d\n",
                   ad, acc);
        } else if (op == 3) {
            mem[ad] = acc;
            printf("  STORE %d, mem=%d\n",
                   ad, mem[ad]);
        } else {
            printf("  HALT, mem[6]=%d\n",
                   mem[6]);
        }
    }
    return 0;
}

Output:

Fetch  PC=0 IR=14
  LOAD 4, ACC=3
Fetch  PC=1 IR=25
  ADD  5, ACC=8
Fetch  PC=2 IR=36
  STORE 6, mem=8
Fetch  PC=3 IR=0
  HALT, mem[6]=8

The printed trace should match the last visit to each Execute stage in Try it 2. Try this: change the data at addresses 4 and 5, recompile, and check that address 6 receives the new sum. Then add a new opcode 4 meaning SUB (subtract mem[ad] from ACC) and a fifth instruction that uses it.

Try it 3CPU and cycle drill

Name the register or unit, or name the stage of the cycle. In name mode, the three-letter (or two-letter) abbreviation is enough.

Summary

IdeaKey points
ALUArithmetic and logical operations on values in registers.
Control unitDecodes the IR and issues the control signals for each step.
PCAddress of the next instruction. Increased during fetch; overwritten by a jump.
MAR and MDRThe gateway to memory: MAR holds the address, MDR holds the data.
IRHolds the instruction being decoded and executed.
AccumulatorA data register; the implied operand in a one-address instruction.
The cycleFetch (IR ← mem[PC], PC ← PC + 1), decode (CU inspects the IR), execute (do it). Repeat until HALT.

Practice questions

1. Name the register that holds (i) the next instruction address, (ii) the instruction being decoded, (iii) the address of a data location about to be read.

Show answer

(i) PC, (ii) IR, (iii) MAR.

2. During fetch, list the transfers that involve the MAR, the MDR, the IR and the PC, in order.

Show answer

MAR ← PC; MDR ← mem[MAR]; IR ← MDR; PC ← PC + 1.

3. A one-address ADD uses address 12. Where do the two numbers being added come from, and where does the result go?

Show answer

One number is already in the accumulator; the other is in mem[12] (brought into the MDR, then the ALU). The result is written back to the accumulator.

4. Why does the CPU copy the fetched instruction into the IR, rather than leaving it in the MDR?

Show answer

The MDR will be needed again if the execute stage has to read or write data in memory. The IR keeps the instruction safely so the control unit can keep referring to it.

5. What does the control unit do in the decode stage of STORE 6, and what memory transfers happen in execute?

Show answer

Decode: it recognises STORE and the address 6, and prepares a write. Execute: MAR ← 6, MDR ← ACC, mem[6] ← MDR.

6. A jump instruction writes 20 into the PC during execute. What is fetched next, and why is this different from a normal cycle?

Show answer

The next fetch uses address 20, not the address after the jump instruction. That is how a program can branch rather than run in address order.

7. In the C program, the first instruction is stored as 14. Explain how the program recovers the opcode and the address.

Show answer

14 / 10 = 1 (LOAD) and 14 % 10 = 4 (the address). The tens digit is the opcode and the units digit is the address.

Homework

  1. From memory, draw a block diagram of a simple CPU with the ALU, the control unit, the PC, MAR, MDR, IR and ACC, and arrows for the address and data paths to memory. Label every box.
  2. On paper, trace LOAD 4, ADD 5, STORE 6 through the cycle, writing the value of PC, IR, ACC, MAR and MDR after every stage. Check against Try it 2.
  3. Modify fde.c so that the program computes 10 − 3 (you will need a SUB opcode, or you can LOAD 10 and add a stored −3). Print mem[6] at the end.
  4. Read 2009 U1 Q2 Part C and 2024 U1 Q1, then try those questions yourself before looking at the solutions.

Exam tips

Specimen Unit 1 Paper 01 (2021), Item 6. A short item asking what the program counter is for. The expected idea is that the PC holds the address of the next instruction to be fetched, not the data being worked on.

Specimen Unit 1 Paper 01 (2021), Items 12 and 13. Matching or multiple-choice items that ask which of the ALU, the control unit, the registers or RAM carries out a given task. Be precise: the ALU computes, the CU directs, registers hold values inside the CPU, and RAM is main memory outside the CPU's register file.

Specimen Unit 1 Paper 02 (2021), Question 2(c). Asks you to explain how the fetch, decode and execute cycle runs an instruction. Write the three stages in order and, in each one, name the registers that are used. A labelled sequence (MAR ← PC, and so on) scores well.

2009 Unit 1 Paper 02, Question 2 and 2024 Unit 1 Paper 02, Question 1 both ask about CPU registers and the fetch of an instruction, including the IR, MAR and MDR. Worked solutions: 2009 U1 Q2 Part C and 2024 U1 Q1.

General advice: if a question says "name the register", give the abbreviation and the full name; if it says "explain the cycle", write the three headings and the transfers under each. More worked answers are on the CS Solutions page.

Previous: Multiplexers, Encoders and Decoders. Next: Instructions: Formats, Types and Instruction Sets. See also: 2009 U1 Q2 Part C, 2024 U1 Q1 and Memory Types and Features.

Syllabus link: CAPE Computer Science (CXC A19/U2/21), Unit 1, Module 1: Computer Architecture. Specific Objective 5: describe the main characteristics of a processor (CPU components: ALU, CU, registers; instruction fetch, decode and execute).

Video search terms

Search YouTube for: "CPU registers PC MAR MDR IR explained", "fetch decode execute cycle step by step", "accumulator and ALU".

Try it 4Quick quiz

Tap an answer. All eight questions are self-checks on this lesson.

Updates

2026/11/23

- Removed the Print this lesson button.

- Published.

© 2026 Vedesh Kungebeharry. All rights reserved.

Leave a Reply