Instruction Register and Addressing Modes

Jul 15, 2024

Instruction Register and Addressing Modes

Instruction Register

  • Holds the program instruction currently being executed.
  • Modern processors use more than the 16-bit representation shown in the diagram.
  • Anatomy of a machine code instruction:
    • Operation Code (opcode): Represents operations like add, subtract, load, store.
    • Operand(s): Identifies the data to be operated upon. Could be a value, CPU register, or memory address.

Bit Allocation

  • More opcode bits = larger instruction set, but fewer bits for operand = fewer memory locations accessible.
  • Fewer opcode bits = fewer instruction types, more bits for memory addresses.

Addressing Modes

  • Different modes help overcome memory addressing limitations and efficiently utilize registers and memory.
  • Immediate Addressing: Operand is the actual value to be operated on (e.g., #5).
  • Direct (Absolute) Addressing: Operand is a memory address containing the value.
  • Indirect Addressing: Operand is a memory address that holds the effective memory address.
  • Register Direct Mode: Operand is a processor register containing a value (very fast).
  • Register Indirect Mode: Operand is a register containing a memory address.
  • Relative Addressing: Effective memory address = Program counter base address + operand offset.
  • Indexed Addressing: Operand = base memory address, effective memory address = base address + index register value.

Execution Examples

  • Immediate Addressing Example:
    • Instruction: Load value #5 into accumulator.
    • Address in PC is copied to Memory Address Register.
    • Instruction copied to Current Instruction Register via Memory Data Register.
    • PC incremented after fetch.
    • Processor operates immediately on the fetched value.
  • Direct Addressing Example:
    • Instruction: Load content of location 501 into accumulator.
    • Address in PC copied to Memory Address Register.
    • Instruction fetched in Current Instruction Register, PC incremented.
    • Processor retrieves value from memory address 501.
  • Indirect Addressing Example:
    • Looks in memory location 501 for the address of the location with needed data.
    • Memory accessed twice during execution.
  • Register Direct Mode Example:
    • Instruction: Load contents of register r1 into accumulator.
    • No memory access needed after fetch.
  • Relative Addressing Example:
    • Unconditional jump instruction: Adds operand value 3 to program counter 101.
    • PC updated to 104, control passed to new instruction.
  • Indexed Addressing Example:
    • Operand adds 3 to address 500 (fourth element of array).
    • Effective memory address calculated as base address + index register value.

Summary

  • Immediate Addressing: Operand is the actual value.
  • Direct Addressing: Operand is a memory address with the value.
  • Indirect Addressing: Operand is a memory address with the effective memory address.
  • Register Direct Mode: Operand is a processor register with a value.
  • Register Indirect Mode: Operand is a processor register with a memory address.
  • Relative Addressing: Effective address = PC base address + operand offset.
  • Indexed Addressing: Effective address = base memory address + index register value.

Variations & Additional Modes

  • Indexed addressing has variations:
    • Indexed Immediate
    • Indexed Indirect
  • Displacement Mode: Uses a register (other than index register) containing a memory address.
  • Some architectures include Auto increment, Auto decrement, and spec addressing modes.