5.1.3 · D5Instruction Set Architecture (ISA)

Question bank — Addressing modes

1,278 words6 min readBack to topic

Reminders used below, all built in the parent note: = the address/displacement field carried inside the instruction word; = the contents of register ; = the contents of memory at address ; = the effective address, the final location of the operand once the mode's rule is applied.


True or false — justify

True or false: immediate mode performs one memory access to fetch its operand.
False. The operand is the field inside the instruction word, so it arrives with the opcode during instruction fetch — zero extra memory accesses for the operand.
True or false: in direct (absolute) mode equals the operand value.
False. In direct mode is the address; the operand is , the contents at that address. is a location, not a value.
True or false: register mode and register-indirect mode both cost zero memory accesses.
False. Register mode reads the operand straight from the register (0 accesses), but register-indirect uses as an address, so it reads memory once: , operand .
True or false: indirect mode always needs exactly two memory accesses to get the operand.
True for memory-indirect: one read to fetch the pointer , a second to fetch the operand . That extra read is the price of indirection.
True or false: PC-relative branches store the absolute address of their target.
False. They store an offset ; the CPU computes . Storing distance rather than a fixed address is exactly what makes the code relocatable.
True or false: displacement mode and indexed mode use different arithmetic.
False. The arithmetic is identical (constant plus register). Only the roles differ: displacement treats as a fixed base and as the varying-at-compile-time offset; indexed treats as the base and as the loop-varying index.
True or false: adding more addressing modes always makes programs run faster.
False. Fancy modes cut instruction count but can lengthen decode logic and the pipeline critical path — a classic RISC vs CISC trade-off, not a free win.
True or false: immediate mode can hold an arbitrarily large constant.
False. The constant lives in the instruction's field, so its range is capped by that field's bit width. Larger constants need extra instructions or a memory load.

Spot the error

LOAD (100) is indirect, so the operand is . Where's the error?
The parentheses mean indirect: first (the pointer), then operand . Reading just is the direct answer.
"Register-indirect reads the register, gets a value, and that value is the operand." Error?
The register's contents are used as an address, not the operand. , then the operand is — one memory read still happens.
"PC-relative branch: I loaded the program 1000 bytes higher, so I must patch every branch's stored number." Error?
You don't patch anything. Branches store relative offsets, so shifts together with the code; that's the whole point of position independence.
"Auto-increment (R1)+ increments R1 first, then reads memory." Error?
For auto-increment the read happens at the current value first (), then steps up. It's auto-decrement that adjusts the register before the access.
"Direct mode is best for big arrays because you just name each element's address." Error?
Direct needs a full-width address baked in per access and can't loop by varying a register. Arrays use displacement/indexed mode so one base register plus a changing offset walks all elements cheaply.
"Displacement mode costs two memory accesses: one for A+(R) and one for the operand." Error?
Computing is arithmetic inside the CPU (ALU), not a memory access. Only the operand fetch touches memory — one access total.

Why questions

Why does indirect mode exist if it costs an extra memory access?
Because the target address can be decided at run time — following pointers, linked lists, and dispatch tables (Pointers and Arrays) needs an address stored in data, which only a memory read can supply.
Why is displacement mode called the "workhorse"?
It maps directly onto real code: holds a base (array start, struct address, or stack-frame pointer) and is a small compile-time offset, so array[i], struct.field, and local variables all become one cheap instruction.
Why do stacks favour auto-increment / auto-decrement?
Push and pop must move the stack pointer every time. Baking the step into the access means push/pop need no separate add/subtract instruction.
Why is PC-relative addressing essential for shared/relocatable code?
Because the operating system may load the program at any base address; offsets from stay valid wherever the code lands, whereas absolute targets would break.
Why does immediate mode give the fastest operand access?
The value travels inside the instruction already fetched, so there is no separate address to compute and no memory hierarchy round-trip — zero extra accesses.
Why might a RISC design deliberately support only a few addressing modes?
Fewer modes mean simpler, more uniform decoding and a shorter, more pipelineable critical path — trading per-instruction cleverness for higher clock speed and throughput.

Edge cases

What is the operand when in immediate mode?
The operand is simply the constant ; no memory is touched. Contrast direct mode where would mean "read ", an actual location.
In indirect mode, what happens if the pointer cell holds itself (self-pointer)?
, so operand again — one level of indirection resolves fine; the CPU only follows the pointer a fixed number of times, it does not loop endlessly.
For auto-increment, why does the word size (not always 1) matter?
The register must step by the size of one element, so byte data uses but a 4-byte word uses ; using the wrong would skip or overlap elements.
In auto-decrement, if is decremented below the valid range, what is the danger?
can underflow past the allocated region (e.g. stack overflow into other data), because the mode blindly does before reading — bounds are the programmer's responsibility, not the mode's.
For PC-relative mode, what does an offset of compute to?
, i.e. the current instruction's reference point itself — effectively a branch-to-self or a no-displacement reference, a legal but usually degenerate case.
If register-indirect uses a register holding an address that equals another register's contents, do the two modes still differ?
The arithmetic result can coincide, but the modes are defined by their rule, not the runtime value; the distinction between register-indirect () and base+index () still stands even when numbers happen to match.

Recall One-sentence survival rule

Every mode is a formula for plus a count of memory accesses — commit those two facts per mode and no trap on this page can catch you.