5.1.12 · D3Instruction Set Architecture (ISA)

Worked examples — Instruction-level semantics and exceptions

3,329 words15 min readBack to topic

First, the words we lean on the whole page: commit and retire

Before any example, we must define one idea the parent note only hinted at, because every "which PC?" answer secretly depends on it.

Figure — Instruction-level semantics and exceptions

Two model conventions we fix up front so nothing later is ambiguous:


The scenario matrix

Here is the full grid of case-classes this topic can throw at you. The figure right after it is the same grid drawn as a coloured map, so you can see at a glance how the nine cases partition the space of behaviours (by return-PC rule on one axis, cause on the other).

# Case class The distinguishing question Covered by
A Fault on a memory access Return to same instruction Ex 1
B Trap (deliberate) Return to next instruction Ex 2
C Abort (unrecoverable) No return at all Ex 3
D Zero / degenerate input (÷0) Fault triggered by data, not address Ex 4
E Tie-break — two faults same cycle Report the program-order-oldest Ex 5
F Asynchronous interrupt Not tied to one instruction; where to insert it Ex 6
G Speculative / squashed instruction faults A fault that must be thrown away Ex 7
H Word problem (real syscall trace) Chain several rules together Ex 8
I Exam twist — branch delay / limiting PC Which PC when the faulting instr also changes PC? Ex 9
Figure — Instruction-level semantics and exceptions

Two ideas repeat across every cell, so pin them now:

Recall The one number that decides everything: the return PC

Which PC does the handler save into the Exception PC (EPC)? Fault ::: the address of the faulting instruction itself (retry it) Trap ::: the address of the next instruction (we already did the job) Abort ::: no return — the program is killed Interrupt ::: the address of the next instruction not yet committed (resume where we paused)

Assume a fixed-length ISA: every instruction is 4 bytes, so "next instruction" means "current address " unless a branch says otherwise.


Ex 1 — Cell A · Fault on a load

The figure below places this fault vs a trap on the same picture so the EPC arithmetic is visual.

Figure — Instruction-level semantics and exceptions

Ex 2 — Cell B · Trap (deliberate)


Ex 3 — Cell C · Abort (no return)


Ex 4 — Cell D · Zero / degenerate input (÷0)


Ex 5 — Cell E · Two faults, same cycle (tie-break)

Figure — Instruction-level semantics and exceptions

Ex 6 — Cell F · Asynchronous interrupt (with masking & priority)


Ex 7 — Cell G · Speculative instruction that faults, then gets squashed

Figure — Instruction-level semantics and exceptions

Ex 8 — Cell H · Word problem (chained rules, real trace)


Ex 9 — Cell I · Exam twist: the faulting instruction is itself a branch

Figure — Instruction-level semantics and exceptions

Wrap-up recall

Recall Reconstruct the whole matrix from one question

"Did the instruction commit, and did it want to finish?" Fault (not committed, must retry) → EPC ::: address of the faulting instruction Trap (committed its job) → EPC ::: address of the next instruction Abort (uncorrectable) → EPC ::: none; process killed Interrupt (external, paused cleanly, maskable) → EPC ::: next uncommitted instruction Squashed speculative fault → reported? ::: never — it never committed Two faults same cycle → report which? ::: the program-order-oldest one Interrupt + exception same cycle → who wins? ::: the synchronous exception (interrupt stays pending)

Back to the parent topic · this whole page is the practical face of the hardware–software contract.