Addressing Modes in Assembly Language to Know for Intro to Computer Architecture

Addressing modes in assembly language are essential for understanding how data is accessed and manipulated in computer architecture. These modes determine how operands are specified, impacting performance and efficiency in executing instructions. Each mode offers unique advantages for different programming scenarios.

  1. Immediate Addressing

    • The operand is specified directly in the instruction itself.
    • Useful for loading constants or small values directly into registers.
    • Fastest addressing mode since no memory access is required.
    • Limited by the size of the instruction format (e.g., 8-bit, 16-bit).
    • Example:
      MOV R1, #5
      (moves the value 5 directly into register R1).
  2. Register Addressing

    • The operand is located in a register, specified by the instruction.
    • Provides fast access to data since registers are the fastest storage.
    • Reduces the need for memory access, improving performance.
    • Limited by the number of available registers in the architecture.
    • Example:
      ADD R1, R2, R3
      (adds the values in R2 and R3, storing the result in R1).
  3. Direct Addressing

    • The address of the operand is given explicitly in the instruction.
    • Simple and straightforward, but requires a memory access.
    • The operand can be located anywhere in the memory space.
    • Limited by the addressable memory range of the architecture.
    • Example:
      LOAD R1, 1000
      (loads the value from memory address 1000 into R1).
  4. Indirect Addressing

    • The address of the operand is specified by a register or memory location.
    • Allows for more flexible data access, enabling dynamic memory usage.
    • Requires an additional memory access to retrieve the operand's address.
    • Useful for implementing data structures like linked lists or arrays.
    • Example:
      LOAD R1, (R2)
      (loads the value from the address contained in R2 into R1).
  5. Base Register Addressing

    • Combines a base register with an offset to calculate the effective address.
    • Useful for accessing arrays or structures where the base address is known.
    • Provides flexibility in memory access while maintaining efficiency.
    • The offset can be a constant or a value in another register.
    • Example:
      LOAD R1, 100(R2)
      (loads the value from the address R2 + 100 into R1).
  6. Indexed Addressing

    • Uses a base address and an index to calculate the effective address.
    • Ideal for accessing elements in an array or table.
    • The index can be a register or a constant, allowing for dynamic access.
    • Facilitates iteration over data structures with minimal code changes.
    • Example:
      LOAD R1, (R2 + R3)
      (loads the value from the address calculated by adding R2 and R3 into R1).
  7. Relative Addressing

    • The effective address is determined by adding a constant value to the current instruction pointer.
    • Useful for branching and control flow in programs.
    • Allows for position-independent code, enhancing modularity.
    • Simplifies the implementation of loops and conditional statements.
    • Example:
      JMP LABEL
      (jumps to the address calculated by adding the offset of LABEL to the current instruction pointer).
  8. Stack Addressing

    • Operands are accessed from a stack data structure, using push and pop operations.
    • Supports function calls, local variables, and recursion effectively.
    • The stack pointer (SP) keeps track of the top of the stack.
    • Enables last-in, first-out (LIFO) access to data, which is crucial for managing function calls.
    • Example:
      PUSH R1
      (pushes the value in R1 onto the stack).


© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.

© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.