All Exams Test series for 1 year @ ₹349 only
Question

Which of the following addressing mode is best suited to access elements of an array of contiguous memory locations ?

The correct answer is

Indexed addressing mode

Understanding Addressing Modes for Contiguous Array Access

Addressing modes in computer architecture define how the operand of an instruction is specified. When dealing with data structures like arrays stored in contiguous memory locations, selecting the appropriate addressing mode is crucial for efficient access.

An array stores elements of the same data type sequentially in memory. If the array starts at a base address $B$, and each element has a size $S$, the address of the $i$-th element (using 0-based indexing) is typically calculated as $B + i \times S$. We need an addressing mode that can effectively compute this address.

Analyzing Addressing Modes for Array Elements

Let's examine the given addressing modes and their suitability for accessing contiguous array elements:

  • Indexed Addressing Mode: In this mode, the effective address is calculated by adding a base address (often stored in a base register or provided directly) to the value of an index register, scaled by a factor (often the element size). The formula is typically $Effective Address = Base Address + Index Register \times Scale Factor$. This precisely matches the calculation needed for accessing array elements ($B + i \times S$), where the base address is $B$, the index register holds $i$, and the scale factor is $S$. This mode is specifically designed for accessing elements within data structures like arrays or tables.
  • Base Register Addressing Mode: Here, the effective address is the sum of the value in a base register and a displacement value specified in the instruction. The formula is $Effective Address = Base Register + Displacement$. While a base register can hold the array's base address, the displacement is a fixed offset. To access different elements, the displacement would need to change with each instruction, or the index would somehow need to be incorporated into the displacement, which is not how this mode is typically used for array traversal. It's more suited for accessing fields within a structure or accessing data relative to a base address.
  • Relative Addressing Mode: In this mode, the effective address is calculated relative to the current instruction pointer (Program Counter - PC). The formula is $Effective Address = PC + Displacement$. This mode is primarily used for branch instructions or accessing data located near the current instruction (position-independent code). It is not suitable for accessing elements of an array based on its base address and an index.
  • Displacement Mode: This mode, sometimes also called Direct Addressing (if the displacement is the full address) or Base Addressing (without an index register), calculates the effective address by adding a displacement value to a base address (which might be implicitly zero or held in a register). If it's just $Effective Address = Displacement$, it's direct addressing, only suitable for a fixed memory location. If it's $Effective Address = Base Register + Displacement$, it's the same as Base Register Addressing mode discussed above, which is not ideal for indexing through array elements efficiently.

Comparing Addressing Modes for Array Access

Based on the analysis, Indexed addressing mode directly supports the calculation $B + i \times S$ required for accessing the $i$-th element of a contiguous array. The base address is provided, and the index (often in a register) is used directly in the address calculation, often with built-in scaling based on the data type size.

Addressing Mode Suitability for Contiguous Array Access
Addressing Mode Effective Address Calculation Suitability for Contiguous Array Access
Indexed Base Address + Index $\times$ Scale Highly Suitable (Directly supports array element address calculation)
Base Register Base Register + Displacement Less Suitable (Displacement is fixed, not directly index-based)
Relative PC + Displacement Not Suitable (PC-relative, not for array element access)
Displacement (Base + Displacement) Base Address + Displacement Less Suitable (Similar to Base Register mode)

Therefore, the Indexed addressing mode is best suited for efficiently accessing elements of an array stored in contiguous memory locations because its address calculation mechanism directly aligns with how array element addresses are computed.

Revision Table: Key Addressing Modes

Summary of Addressing Modes
Mode Name Description Use Case
Immediate Operand is part of the instruction. Loading constants into registers.
Direct Instruction contains the full memory address. Accessing fixed memory locations.
Register Operand is in a register. Fast access to values in CPU registers. Indexed Base Address + Index $\times$ Scale. Accessing array/table elements.
Register Indirect Register contains the memory address. Implementing pointers.

Additional Information: Why Indexed Mode Excels for Arrays

Indexed addressing mode is specifically designed to handle data structures like arrays. It allows for easy iteration through array elements by simply incrementing or decrementing the index register. Many architectures also include hardware support for scaling the index by the element size (e.g., 1, 2, 4, 8 bytes), making the calculation $Base + Index \times Scale$ very fast, often performed within the memory access cycle itself. This hardware support is what makes Indexed addressing particularly efficient for array processing compared to modes like Base Register + Displacement, which would require extra instructions to calculate the correct displacement for each element or manage the base address dynamically.

Was this answer helpful?

Important Questions from Indexed Address - Teaching

  1. An instruction is stored at location 500 with its address field at location 501. The address field has the value 400. A processor register R 1contains the number 200. Match the addressing mode (List-I) given below with effective address (List-II) for the given instruction.

    List I

    List II

    a.

    Direct

    i.

    200

    b.

    Register indirect

    ii.

    902

    c.

    Index with R 1as the index register

    iii.

    400

    d.

    Relative

    iv.

    600

    Choose the correct option from those given below:

Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App