Computer Science I / The Instruction Execution Cycle
Practice question · Put in order

A program executes ADD R1, R2 followed by JMP 200. Order what the CPU does, from the start of the first instruction to the moment the jump takes effect.

Hints
  1. The PC advances during fetch, before the instruction is understood.
  2. The last step is what makes a jump a jump.
Show the answer
  1. The PC's address is used to read the ADD instruction from memory.
  2. The PC advances to point at the JMP instruction.
  3. ADD is decoded and the ALU adds the two registers.
  4. The JMP is fetched, and the PC advances again to the instruction after it.
  5. JMP executes and writes 200 into the PC, discarding that advance.
Why

The sequence shows why incrementing the PC during fetch costs nothing. After the ADD is fetched, the PC advances to the JMP - which is exactly right, and no extra work was needed to arrange it.

The JMP is then fetched and the PC advances again, to whatever follows it. That advance is immediately discarded when the jump executes and writes 200 into the PC.

So a jump is not special sequencing hardware; it is one register write that happens to overwrite a value the fetch phase had speculatively set. Everything the CPU does about control flow reduces to what number ends up in the PC when the cycle comes round again - which is also why a corrupted PC is so catastrophic, and why buffer overflows that overwrite a return address are able to redirect execution anywhere.

Read the lesson: The Instruction Execution Cycle →

Practise The Instruction Execution Cycle

The app has 8 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.

More questions on The Instruction Execution Cycle