5.1.3 · D3Instruction Set Architecture (ISA)

Worked examples — Addressing modes

2,844 words13 min readBack to topic

This is a Deep Dive child of 5.1.3 Addressing modes. The parent gave you the formulas. Here we exhaust them — every mode, every degenerate case, every trap an exam can set. If a scenario exists, it lives in the matrix below and gets a fully worked example.

Before anything, five plain-word reminders (we will not use a symbol we have not re-earned):


The scenario matrix

Every worked example below is tagged with the cell it covers. The goal: no reader ever meets a case we skipped.

Cell What makes it tricky Covered by
C1 — zero memory access operand never touches memory (immediate / register) Ex 1
C2 — the "how many trips?" axis direct (1) vs indirect (2) vs register-indirect (1) Ex 2
C3 — sign of the displacement can be negative (backward offset) Ex 3
C4 — degenerate / zero inputs , or — do the rules still hold? Ex 4
C5 — scaled indexing (arrays of wide elements) element size byte Ex 5
C6 — PC-relative, both directions forward branch and backward loop Ex 6
C7 — auto-increment / decrement ordering when does change relative to the access? Ex 7
C8 — the stack (real-world word problem) push/pop as auto-dec/auto-inc Ex 8
C9 — exam twist: same bits, four modes one instruction word decoded four ways Ex 9
C10 — limiting behaviour / wrap-around exceeds the address space Ex 10

Shared machine state for all examples (memorise this street):

Address Contents Register Contents
100 500 R1 400
200 108 R2 3
400 700 R3 408
403 900 Rz 0
404 111 PC 200
408 222 SP 600
500 800 Rb 596
596 42
600 55
608 333

The worked examples

Ex 1 — C1: the operand that never leaves the instruction


Ex 2 — C2: the "how many trips?" axis, three modes, same


Ex 3 — C3: a negative displacement (backward offset)


Ex 4 — C4: degenerate / zero inputs


Ex 5 — C5: scaled indexing for an array of wide elements


Ex 6 — C6: PC-relative in both directions


Ex 7 — C7: auto-increment vs auto-decrement ordering


Ex 8 — C8: the stack — a real-world word problem


Ex 9 — C9: exam twist — one instruction word, four modes


Ex 10 — C10: limiting behaviour — address wrap-around


Recall

Recall Which cells did we cover?

All ten: zero-access (Ex1), trip-count axis (Ex2), negative displacement (Ex3), zero/degenerate collapse (Ex4), scaled index (Ex5), PC-relative both ways (Ex6), inc/dec ordering (Ex7), stack (Ex8), one-word-four-modes (Ex9), wrap-around (Ex10). Every was a formula; every operand needed a trip count. Master those two habits.

Recall Quick self-test

LOAD (100) with M[100]=500, M[500]=800 — operand and trips? ::: operand 800, 2 memory trips (indirect). LOAD 0(R1) with (R1)=400 — what mode does it degenerate to? ::: register-indirect; EA=400, operand M[400]=700. Scaled arr[3], base 596, element size 4 — EA and operand? ::: EA = 596 + 3×4 = 608, operand M[608]=333. Push onto a downward stack, SP=600 — which auto-mode and new SP? ::: pre-decrement -(SP); SP becomes 599. LOAD 6(Rw), (Rw)=5, 3-bit address space — EA? ::: 11 mod 8 = 3.

The RISC-vs-CISC tension behind "how many modes should we even offer" lives in RISC vs CISC.