4.1.8 · D5Computer Architecture (Deep)
Question bank — Memory addressing modes — immediate, register, direct, indirect, indexed
Vault refresh links if a term feels shaky: Instruction Encoding & Opcodes, Registers and the Register File, Memory Hierarchy and Access Latency, Pointers in C, Arrays and Stride, CPU Datapath and Control Unit.
True or false — justify
True or false: Immediate mode performs one memory read to fetch its operand.
False — the operand is already inside the instruction word, which was pulled in during the instruction fetch; the operand costs zero additional memory accesses. Intuition: the number is printed on the card itself, so there is nowhere to travel to.
True or false: Register mode never touches the memory bus for its operand.
True — the operand lives in a CPU register inside the register file (a tiny bank of storage right beside the ALU), reachable in one clock without any bus trip. Intuition: it is in your pocket, not across town.
True or false: A larger address field always means the instruction can reach more memory in direct mode.
True for direct mode specifically — since literally, the number of address bits caps the reachable range. Intuition: but this reach is frozen at assembly time, which is why direct mode is inflexible compared to indexed/indirect that recompute the target at runtime.
True or false: Indexed mode does an extra memory read to resolve its effective address.
False — indexed does an addition (), not a read. Intuition: adding a register value is arithmetic done inside the CPU, whereas indirect's extra step actually leaves the CPU to read a cell, which is why indirect costs 2 accesses and indexed costs 1.
True or false: Indirect mode and indexed mode both need exactly one memory access to get the operand.
False — indirect needs two ( to fetch the address, then to fetch the operand); indexed needs one. Intuition: indirect chases a pointer (two trips to memory), indexed just shifts a fixed base by a register (one trip).
True or false: The "effective address" is a physical thing stored somewhere in the CPU.
False — the EA is computed on the fly by the addressing-mode logic in the datapath (the wires and adders that route operands) each time the instruction runs. Intuition: it is a result, like the sum on a calculator display, not a saved variable.
True or false: In register-indirect mode the operand is the register's contents.
False — the register holds an address; the operand is , the cell that address points to. Intuition: the register is a signpost reading "house 200," and the operand is whatever lives in house 200.
True or false: Immediate mode can be used to write a value into a variable.
False — immediate supplies a source constant; it has no address, so nothing can be stored into an immediate. Intuition: you cannot mail a letter to a number printed on a card — there is no mailbox.
True or false: PC-relative addressing gives an absolute target that never changes when the code is moved in memory.
False — PC-relative computes where is a signed displacement and PC is the program counter (address of the current instruction). Intuition: because the target is measured relative to wherever the code currently sits, the whole program can be relocated and every jump still lands correctly — the opposite of an absolute address.
Spot the error
"Indexed EA equals the base plus the value stored at the base, i.e. ."
Error: indexed adds the register's contents , not a memory value — . Intuition: the person dereferenced memory (that's indirect's move); indexed never opens a box to build its address, it only adds a register.
"Direct mode is the most flexible because it names the exact cell you want."
Error: naming a fixed cell is the least flexible — that instruction can only ever touch that one address. Intuition: a signpost that always points to the same house cannot follow a moving target; flexibility comes from recomputing the target at runtime (indexed for arrays, indirect for pointers).
"To walk an array we rewrite the LOAD instruction for each element."
Error: indexed mode reuses the same instruction and just bumps the index register () each pass — see Arrays and Stride. Intuition: one instruction plus a changing counter sweeps the whole street; rewriting code per element defeats the entire purpose.
"Indirect mode is slow because addition is slow."
Error: it is slow because of the extra memory read to fetch the pointer, not arithmetic. Intuition: a memory access crosses the bus into the far-slower memory hierarchy (hundreds of cycles on a miss), while an add finishes in one cycle.
"Immediate stores the constant in a scratch memory cell, then reads it back."
Error: no memory cell is involved — the constant sits in the instruction's value field, already fetched. Intuition: inventing a memory round-trip would erase immediate mode's whole reason to exist, which is zero operand accesses.
"Register mode and register-indirect mode are the same because both name a register."
Error: register mode uses the register's contents as the operand (0 accesses); register-indirect uses the register's contents as an address and reads (1 access). Intuition: same field, opposite meaning — "the value" versus "the value is a signpost."
"PC-relative and direct addressing are interchangeable since both eventually give a memory address."
Error: direct puts an absolute address in the instruction; PC-relative stores a signed offset and computes . Intuition: one says "house 500," the other says "5 houses past where you stand" — only the relative one survives moving the whole neighbourhood.
Why questions
Why does counting the symbols predict the memory-access cost — and what exactly is counted?
The precise rule is: cost = (number of nestings inside the EA expression) + one final to fetch the operand, unless the mode has no memory operand at all. Direct's EA is (zero nestings) + 1 operand read = 1; indirect's EA is (one nesting) + 1 operand read = 2; immediate/register produce the value directly, so the "+1" is skipped and the total is 0.
Why can't we just give every memory cell its own opcode instead of using addressing modes?
Programs touch millions of cells but an opcode field has only a handful of bits — see Instruction Encoding & Opcodes. Intuition: encoding a short "recipe" and letting hardware compute the address each run is the only way to name a huge space with tiny instructions.
Why is indirect mode the natural fit for linked lists and pointers?
A node's "next" field holds the address of the following node, exactly the pattern — you read one stored address to reach the real target, mirroring how pointers dereference with
*.Why does incrementing the index register let one instruction sweep a whole array?
Because recomputes a fresh element address each pass while the base and the instruction bits stay fixed; bumping by the element stride slides the window forward one element at a time.
Why is immediate mode useless as a destination but fine as a source?
A destination must have an address to write into; an immediate has no address — it is the value embedded in the instruction — so it can only ever be read.
Why does PC-relative addressing make code position-independent?
Because the target is expressed as an offset from the current instruction's location (), the physical base cancels out: move the whole block anywhere and every relative jump still points to the same relative spot, which is exactly what shared libraries need.
Edge cases
Edge case: what does indirect mode do if happens to equal (a self-pointer)?
The EA resolves to itself, so the operand becomes — one legitimate read; the hardware does not loop forever, because indirection is applied a fixed number of times (once), not until convergence.
Edge case: what is the operand of indexed mode when the index register holds ?
, so it fetches — indexed with a zero index degenerates into exactly direct mode's behaviour (still 1 access).
Edge case: in indexed mode, what happens if is negative in two's-complement?
The hardware interprets the register as a signed value and effectively subtracts, so lands before the base — useful for reaching earlier array elements or a struct field at a negative offset, but a bug if you assumed the index was unsigned and expected a huge address instead.
Edge case: how does signed wraparound differ from plain overflow when computing an EA?
Overflow is when a positive sum exceeds the address width and wraps to a low address; signed wraparound is when a two's-complement negative index makes the sum dip below zero and wrap to a very high address. Both yield a valid-but-wrong cell, and the CPU computes either without complaint.
Edge case: does register mode's "0 memory accesses" also mean 0 accesses during instruction fetch?
No — every instruction still costs one fetch to read the instruction word itself; the "0" counts only operand accesses. All modes share the fetch cost equally.
Edge case: if a "double-indirect" mode existed (), how many operand accesses would it need?
Three — two reads to resolve the doubly-nested pointer chain plus the final operand read, following the "count the nestings + 1" rule that gives indirect its 2.
Edge case: what does immediate mode's "memory access count" become on a machine with a tiny instruction word that can't hold the full constant?
The constant may be split across bits or need a second instruction word, but the operand still costs 0 extra data-memory accesses — the extra cost is in instruction fetch, not operand fetch.
Edge case: in PC-relative addressing, what happens when the displacement is zero?
, so the instruction references its own location — a degenerate "point at myself" case, harmless but rarely useful, and the same idea that lets branch-to-self become an infinite loop.
Recall One-line self-test before you close this page
If someone says "indirect and indexed both cost one memory access," what is your instant correction? ::: Indirect costs two (read memory to get the pointer , then read again for the operand ); indexed costs one (it adds the register instead of reading). The difference is add-vs-read.