Skip to content
IGCSE·Tuition
Computer Science · Lessons

Trace a simplified instruction cycle

Knowing the words fetch, decode and execute is easy, until a question asks what each register holds after every step.

On this page
  1. What happens in each stage?
  2. Worked example
  3. The mistake to watch for
  4. Check yourself
  5. Where this leads next

A processor runs a program by repeating one cycle: fetch the next instruction from memory, decode it, then execute it. A trace of this cycle shows what the registers hold after each step.

This skill belongs to hardware and processing. It is the foundation for the next lesson on what each register is for, and it links closely to trace tables in algorithm questions.

What happens in each stage?

We use a simplified model with five registers: the program counter (PC), memory address register (MAR), memory data register (MDR), current instruction register (CIR) and accumulator (ACC).

Fetch

  1. The address in the PC is copied to the MAR.
  2. The PC is increased by 1, so it points at the next instruction.
  3. The contents of the memory location in the MAR are copied to the MDR.
  4. The contents of the MDR are copied to the CIR.

Decode. The control unit works out what the instruction in the CIR means: which operation, and which address.

Execute. The instruction is carried out. A load copies a value into the ACC, an arithmetic instruction uses the arithmetic logic unit (ALU) and leaves the result in the ACC, and a store copies the ACC to memory.

In pseudocode, the fetch looks like this:

MAR ← PC
PC ← PC + 1
MDR ← Memory[MAR]
CIR ← MDR

Worked example

Memory holds this program and data. LDA 200 loads the value at address 200 into the ACC, ADD 201 adds the value at address 201 to the ACC, STO 202 stores the ACC at address 202, and END stops.

AddressContents
100LDA 200
101ADD 201
102STO 202
103END
2007
2015
2020

The PC starts at 100. The ACC is empty at the start, shown as a dash.

StepPCMARMDRCIRACC
Start100----
Fetch 1101100LDA 200LDA 200-
Execute 11012007LDA 2007
Fetch 2102101ADD 201ADD 2017
Execute 21022015ADD 20112
Fetch 3103102STO 202STO 20212
Execute 310320212STO 20212
Fetch 4104103ENDEND12

Check the key values twice. In Execute 2 the ALU adds 7 + 5 = 12. In Execute 3 the value 12 is written to address 202, so location 202 changes from 0 to 12.

Each fetch reads the address the PC held before it increased: 100, 101, 102, 103.

The same cycle in Python, using a dictionary as memory:

memory = {100: "LDA 200", 101: "ADD 201", 102: "STO 202", 103: "END",
          200: 7, 201: 5, 202: 0}
pc = 100
acc = 0
while True:
    mar = pc
    pc = pc + 1
    mdr = memory[mar]
    cir = mdr
    op = cir.split()[0]
    if op == "END":
        break
    address = int(cir.split()[1])
    if op == "LDA":
        acc = memory[address]
    elif op == "ADD":
        acc = acc + memory[address]
    elif op == "STO":
        memory[address] = acc
print(memory[202])   # 12

This is a teaching model, not how a real processor is built, and the safe Python reasoning sandbox lets you run small examples like it.

The mistake to watch for

A frequent slip is to update the PC after the execute stage, or to leave it at the address of the instruction being run.

Mistaken Fetch 1 row: PC 100, MAR 100, MDR LDA 200, CIR LDA 200

The student kept the PC at 100 because “that is where the instruction is”.

The PC is increased during the fetch, so after Fetch 1 it already holds 101. The mistake spreads: every later MAR is then wrong by one, and the whole trace fails. Fix it by writing the PC increase as the second line of every fetch.

Check yourself

1. At the start of a fetch the PC holds 300. Write the values of MAR and PC after the first two steps of the fetch.

Show answer

Step 1 copies the PC into the MAR, so MAR = 300. Step 2 increases the PC, so PC = 301.

2. Which register holds the instruction while the control unit decodes it?

Show answer

The CIR (current instruction register). The MDR only holds it briefly on its way from memory.

3. An instruction JMP 150 is stored at address 120. State the PC after its fetch and after its execute.

Show answer

After the fetch, PC = 121. Executing a jump overwrites the PC with the new address, so after the execute PC = 150. The next fetch uses MAR = 150.

Where this leads next

Now that you can trace the cycle, relate each register to its role and then try the hardware and processing practice set. The restricted pseudocode trace trainer is useful for the same habit of stepping through values.

Some students follow a trace in class but lose the thread alone on a blank page. A teacher in online one-to-one Computer Science tuition can trace with you, one register at a time, until the pattern holds.

Questions people ask

In which order do PC, MAR, MDR and CIR change during a fetch?

In the simplified model: the address in the PC is copied to the MAR, the PC is increased by 1, the instruction at that address is copied into the MDR, and then it is copied to the CIR. Always show the PC moving on during the fetch, before the instruction is executed.

Why does the PC not hold the address of the instruction being executed?

Because the PC is updated during the fetch so it already points at the next instruction. While the current instruction executes, the PC holds the next address. A jump instruction is different: it overwrites the PC with a new address, so the next fetch happens somewhere else.

Do I need to learn a real assembly language for this?

No. Questions give you the small set of instructions they use, or describe them in words. Your job is to apply the cycle consistently and show each register. Check the Cambridge subject page for how the current syllabus words this topic, and answer with the instruction names given in the question.

Sources

  1. Cambridge IGCSE Computer Science 0478 syllabus page

Updated:

Your next step

If your trace tables drift off by one row or one register, a one-to-one teacher can watch you work through a program live and catch the exact step where the values go wrong.

Paid one-hour trial at your assigned teacher’s confirmed rate, starting from RM80. Other fees, schedules and ongoing arrangements are confirmed directly with your teacher after the trial class.

Tuition is arranged with a parent or guardian. Send them this page on WhatsApp and they can enquire for you.

Parent or guardian? Enquire here

9,000+ students helped through our service