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

Which of the following addressing modes is convenient to handle pointers?

The correct answer is

indirect addressing

Understanding Addressing Modes in Computer Architecture

Addressing modes determine how the operand (the data being operated upon) of an instruction is specified. Different addressing modes are used depending on how and where the data is stored.

Let's look at some common addressing modes:

  • Immediate Addressing: The operand's value is directly present in the instruction itself. This is useful for constants.
  • Direct Addressing: The instruction contains the direct memory address where the operand is stored.
  • Indirect Addressing: The instruction contains the memory address where the address of the operand is stored. The CPU first reads the content at the given address, and that content is the effective address of the actual operand.
  • Base Addressing: The address of the operand is calculated by adding a displacement value (offset) specified in the instruction to the content of a base register.
  • Relative Addressing: The address of the operand is calculated by adding a displacement value (offset) specified in the instruction to the content of the Program Counter (PC). This is often used for jump instructions.

Handling Pointers with Addressing Modes

A pointer is a variable that stores the memory address of another variable. When you use a pointer, you are essentially saying "go to this address and find the data there".

Consider a pointer variable, say ptr, which holds the address of another variable, say data_var.

If you want to access the value of data_var using ptr, you first need to read the content of ptr (which is an address) and then use that address to fetch the value of data_var.

Let's see how addressing modes relate to this:

  • Immediate and Direct Addressing: These modes directly provide the value or the address of the operand in the instruction itself. They don't easily handle situations where the address of the operand is stored in another memory location (like a pointer variable).
  • Base and Relative Addressing: These modes calculate the operand's address by adding an offset to a register's content or the PC. While useful for arrays or position-independent code, they don't directly match the "address-of-an-address" nature of dereferencing a pointer.
  • Indirect Addressing: This mode is specifically designed for scenarios where the instruction provides an address, and the content found at that address is the effective address of the actual operand. This perfectly mirrors how a pointer works: the instruction can point to the memory location holding the pointer variable's value (which is an address), and the CPU then uses that value (the stored address) to access the final data.

Therefore, indirect addressing is the most convenient mode for handling pointers because it directly supports the concept of using a stored address to access data.

Was this answer helpful?

Important Questions from Addressing Modes

  1. How many bits are required to distinguish between a direct and an indirect address?

  2. Which one of the following types of instructions is useful for initializing registers to assign a constant value?
  3. In which one of the following addressing modes, the effective address is equal to the address part of the instruction?
  4. Match the LIST-I with LIST-II
    LIST-ILIST-II
    A. Immediate addressing modeI. MOV A,@R0
    B. Indexed addressing modeII. MOV DPTR,#4521H
    C. Register addressing modeIII. MOVC A,@A+DPTR
    D. Register indirect addressing modeIV. MOV A,R0
    Choose the correct answer from the options given below:
  5. Match each addressing mode in List I with a data element or an element of a data structure (in a high-level language) in List II:
    List IList II
    P. Immediate1. Element of an array
    Q. Indirect2. Pointer
    R. Base with index3. Element of a record
    S. Base with offset/displacement4. Constant
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