Lesson 36 +40 XP

Addressing Modes with Numericals, and RISC vs CISC

Addressing Modes with Numericals, and RISC vs CISC

The basic computer had two ways to find an operand: direct and indirect. Real processors offer many addressing modes, so that programs can use pointers, counters, arrays and relocatable code with short instructions. This lesson defines every common mode, works through the standard numerical example, and closes Unit III with the comparison of RISC and CISC processors and RISC's overlapped register windows.

1. Why Addressing Modes?

The addressing mode specifies a rule for interpreting the address field to find the operand. Modes give:

  1. programming flexibility: pointers to memory, loop counters, indexing of arrays, program relocation;
  2. fewer bits in the address field (a register number is shorter than a memory address).

The mode is either encoded in a separate mode field of the instruction or implied by the opcode. The address actually used to reach the operand is the effective address (EA).

OpcodeModeAddress
the operationhow to find the operanda memory address, a register or an operand

2. The Addressing Modes

Two modes need no address field at all:

  • Implied mode: the operand is specified implicitly by the instruction. Examples: CMA (complement the accumulator), zero-address stack instructions (ADD uses the top of the stack).
  • Immediate mode: the operand itself is in the instruction (an operand field instead of an address field). Used to initialise registers to constants: LD #NBR.

The others compute an EA:

ModeEffective address (EA)Typical use
Registeroperand is in the register named in the instruction (no memory access)fast temporary values
Register indirectEA = contents of the registerpointers; one short register field reaches all memory
AutoincrementEA = register, then register ← register + 1stepping through an array
Autodecrementregister ← register − 1, then EA = registerstepping backwards, stacks
DirectEA = address fieldsimple variables, branch targets
IndirectEA = M[address field]pointers stored in memory
RelativeEA = PC + address field (signed)branches near the current instruction; position-independent code
IndexedEA = XR + address fieldarrays: the address field is the start, XR the index
Base registerEA = base register + address fieldrelocation: the address field is the offset within a segment

In relative mode, PC already points to the next instruction when the EA is computed. The offset is usually small, so it fits in fewer bits than a full address.

Indexed and base-register modes compute the same sum; they differ in use. In indexed mode the address field holds a fixed array start and the register changes. In base-register mode the register holds the start of a program segment and the address field is the displacement inside it, so a program can be moved in memory by changing only the base register.

3. The Standard Numerical Example

A two-word instruction at addresses 200 and 201 is "load to AC" with a mode field; its address field (in word 201) is 500. PC = 200 before the fetch, R1 = 400 and the index register XR = 100. Memory holds the values shown.

Numerical example for addressing modesNumerical example for addressing modes

SolvedExample 1 · Effective address and AC for every mode (Mano)

Find the effective address and the operand loaded into AC for each addressing mode.

  1. After fetching both words, PC = 202.
  2. Direct: EA = 500, AC = M[500] = 800.
  3. Immediate: the operand is word 201 itself: EA = 201, AC = 500.
  4. Indirect: EA = M[500] = 800, AC = M[800] = 300.
  5. Relative: EA = PC + 500 = 202 + 500 = 702, AC = 325.
  6. Indexed: EA = XR + 500 = 600, AC = 900.
  7. Register: no EA; AC = R1 = 400.
  8. Register indirect: EA = R1 = 400, AC = 700.
  9. Autoincrement: EA = 400, AC = 700, then R1 = 401.
  10. Autodecrement: R1 = 399 first, EA = 399, AC = 450.

Answer:

ModeEAAC
Direct500800
Immediate201500
Indirect800300
Relative702325
Indexed600900
Register(none)400
Register indirect400700
Autoincrement400700
Autodecrement399450

The same table, computed by a Verilog testbench that applies each mode's EA rule to the memory of the example:

VERILOG
// Effective address and operand for each addressing mode, on Mano's example:
// a two-word "load to AC" at 200-201 with address field 500, PC = 202,
// R1 = 400, XR = 100
module tb;
    reg [15:0] M [0:1023];
    reg [15:0] pc, r1, xr, ea, ac, adr;
    integer mode;
    reg [8*18:1] name;
    initial begin
        M[399] = 450;
        M[400] = 700;
        M[500] = 800;
        M[600] = 900;
        M[702] = 325;
        M[800] = 300;
        M[201] = 500;              // address field of the instruction
        for (mode = 0; mode < 9; mode = mode + 1) begin
            pc = 202;              // PC after fetching both words
            r1 = 400;
            xr = 100;
            adr = M[201];
            case (mode)
                0: begin name = "direct";            ea = adr;      ac = M[ea]; end
                1: begin name = "immediate";         ea = 201;      ac = M[ea]; end
                2: begin name = "indirect";          ea = M[adr];   ac = M[ea]; end
                3: begin name = "relative";          ea = pc + adr; ac = M[ea]; end
                4: begin name = "indexed";           ea = xr + adr; ac = M[ea]; end
                5: begin name = "register";          ea = 0;        ac = r1;    end
                6: begin name = "register indirect"; ea = r1;       ac = M[ea]; end
                7: begin                                       // EA = R1, then R1 + 1
                    name = "autoincrement";
                    ea = r1;
                    ac = M[ea];
                    r1 = r1 + 1;
                end
                default: begin                                 // R1 - 1, then EA = R1
                    name = "autodecrement";
                    r1 = r1 - 1;
                    ea = r1;
                    ac = M[ea];
                end
            endcase
            if (mode == 5) $display("%0s: EA = -, AC = %0d", name, ac);
            else $display("%0s: EA = %0d, AC = %0d, R1 = %0d", name, ea, ac, r1);
        end
    end
endmodule

Each line matches the table, including the side effects of autoincrement (R1 becomes 401 after use) and autodecrement (R1 becomes 399 before use):

OUTPUT
direct: EA = 500, AC = 800, R1 = 400
immediate: EA = 201, AC = 500, R1 = 400
indirect: EA = 800, AC = 300, R1 = 400
relative: EA = 702, AC = 325, R1 = 400
indexed: EA = 600, AC = 900, R1 = 400
register: EA = -, AC = 400
register indirect: EA = 400, AC = 700, R1 = 400
autoincrement: EA = 400, AC = 700, R1 = 401
autodecrement: EA = 399, AC = 450, R1 = 399
SolvedExample 2 · Another set of effective addresses (Mano)

An instruction is at location 300 with its address field at location 301. The address field holds 400 and R1 holds 200. Find the EA for direct, immediate, relative, register indirect and indexed (R1 as index register).

  1. Direct: EA = 400.
  2. Immediate: the operand is at 301 (the address field itself).
  3. Relative: PC = 302 after the fetch, EA = 302 + 400 = 702.
  4. Register indirect: EA = R1 = 200.
  5. Indexed: EA = 200 + 400 = 600.
Answer400, 301, 702, 200, 600
SolvedExample 3 · Relative branch offset (Mano)

A relative-mode branch instruction is stored at location 750 and must branch to 500. What is the relative address field if the instruction is one word long? Two words?

  1. One word: after the fetch PC = 751. Offset = 500 − 751 = −251.
  2. Two words: PC = 752. Offset = 500 − 752 = −252.
Answer−251 (one word), −252 (two words), stored in 2's complement
SolvedExample 4 · Number of memory references

How many memory references does a "load to AC" need, including fetching a one-word instruction, in direct, indirect, register, register indirect and immediate mode?

  1. Fetch: 1 in every mode.
  2. Direct: + 1 operand read = 2. Indirect: + 1 address read + 1 operand read = 3.
  3. Register: operand is in a register = 1. Register indirect: + 1 operand read = 2.
  4. Immediate: the operand comes with the instruction = 1.
Answer2, 3, 1, 2, 1

4. RISC and CISC

4.1 CISC (complex instruction set computer)

The trend in the 1970s was to add more and more instructions and modes, to bring machine language closer to high-level languages and to reduce the "semantic gap". Characteristics:

  1. a large number of instructions (typically 100 to 250),
  2. some instructions perform specialised tasks and are rarely used,
  3. a large variety of addressing modes (5 to 20),
  4. variable-length instruction formats,
  5. instructions that operate directly on memory operands,
  6. usually microprogrammed control.

4.2 RISC (reduced instruction set computer)

Studies showed most programs use a small subset of instructions most of the time. RISC keeps only those and makes them fast:

  1. relatively few instructions and few addressing modes,
  2. memory access limited to LOAD and STORE; all operations are register to register,
  3. fixed-length, easily decoded instruction formats,
  4. single-cycle execution of most instructions (made possible by pipelining),
  5. hardwired rather than microprogrammed control,
  6. a relatively large number of registers, often with overlapped register windows,
  7. an efficient pipeline, with compiler support (for example, delayed branch and delayed load).
FeatureCISCRISC
Instruction setlarge, complexsmall, simple
Instruction lengthvariablefixed
Addressing modesmanyfew
Memory operandsin most instructionsLOAD / STORE only
Cycles per instructionmanyabout one
Control unitmicroprogrammedhardwired
Registersfewmany (register windows)
Code sizesmallerlarger
Burden onhardwarecompiler
ExamplesIntel x86, VAX, IBM 370ARM, MIPS, SPARC, RISC-V

4.3 Overlapped register windows

Procedure calls are frequent, and saving and restoring registers on each call is slow. A RISC register file is divided into windows, one per active procedure. Each window has:

  • local registers, private to the procedure,
  • common registers shared with the next window, used to pass parameters (the caller's out-registers are the callee's in-registers),
  • plus global registers seen by every procedure.

Overlapped register windowsOverlapped register windows

With G global, L local and C common registers per window and W windows:

window size = L + 2C + G qquad register file = (L + C) W + G
SolvedExample 5 · Register window sizes

Find the window size and the total number of registers for (a) G = 10, L = 10, C = 6, W = 4 and (b) the Berkeley RISC I with W = 8.

  1. (a) Window = 10 + 2 × 6 + 10 = 32 registers seen by a procedure. File = (10 + 6) × 4 + 10 = 74.
  2. (b) Window = 32. File = (10 + 6) × 8 + 10 = 138.
Answer(a) 32 and 74; (b) 32 and 138
💡 Tip

Key points to remember

  • Implied and immediate modes have no EA; register mode uses no memory.
  • Relative EA = PC (already pointing past the instruction) + offset; indexed EA = XR + address; base EA = base + displacement.
  • Mano's example: direct 800, immediate 500, indirect 300, relative 325, indexed 900, register 400, register indirect 700, autoincrement 700, autodecrement 450.
  • CISC: many instructions and modes, variable length, memory operands, microprogrammed.
  • RISC: few simple fixed-length instructions, load/store, one cycle, hardwired, many registers; windows: L + 2C + G and (L + C)W + G.
🎯 END-TERM EXAM PREP

📝 IPU End-Term Exam Corner (5-10 Marks)

  • Q1. What is an addressing mode? Explain implied, immediate, register, register indirect, autoincrement, direct, indirect, relative, indexed and base register modes with examples. (10 Marks)
  • Q2. A two-word load instruction at 200-201 has address field 500; R1 = 400, XR = 100 and memory as in Mano's example. Find EA and AC for all modes. (10 Marks)
  • Write: PC = 202, and the table of Example 1.
  • Q3. A relative branch at location 750 must go to 500. Find the address field for one-word and two-word instructions. (2.5 Marks)
  • Q4. Compare RISC and CISC architectures. (5 Marks)
  • Q5. Explain overlapped register windows. With G = 10, L = 10, C = 6 and W = 4, find the window size and the register file size. (5 Marks)