Skip to content
Official PYQ · 2005

GATE CS 2005 Q66 — Machine Instructions and Addressing Modes

Explain with AI

Match each of the high level language statements given on the left hand side with the most natural addressing mode from those listed on the right hand side.(1)A[I]=B[J](a)Indirect addressing(2)while (∗A++);(b)Indexed addressing(3)int temp =∗x(c)Auto increment\begin{array}{clcl} \text{(1)} &\text{$A[I] = B[J]$} & \qquad\text{(a)} &\text{Indirect addressing} \\ \text{(2)} &\text{while $(^*A\text{++});$} & \qquad\text{(b)} & \text{Indexed addressing} \\ \text{(3)} & \text{int temp $= ^*x$} & \qquad\text{(c)} &\text{Auto increment} \\ \end{array}

Choose one option
View worked solution

Answer: C

To find the most natural addressing mode for each high-level language statement, we analyze how each operation is translated into machine instructions:

  1. Statement (1): A[I]=B[J]A[I] = B[J]
    This statement accesses elements of arrays AA and BB using indices II and JJ. In assembly, the effective address of an array element is computed as Base Address+Index\text{Base Address} + \text{Index}. This is the definition of Indexed addressing.
    ∴(1)→(b)\therefore (1) \rightarrow (b)

  2. Statement (2): while (*A++);
    This statement dereferences the pointer AA and then increments the pointer to point to the next memory location. This sequential access and update operation is directly supported by the Auto-increment addressing mode, where the register holding the address is automatically incremented after the memory access.
    ∴(2)→(c)\therefore (2) \rightarrow (c)

  3. Statement (3): int temp = *x;
    Here, xx is a pointer variable that holds the address of the actual data. Accessing the value pointed to by xx (dereferencing) requires fetching the address from xx first and then accessing that address. This is Indirect addressing (specifically, register indirect if xx is in a register, or memory indirect if xx is in memory).
    ∴(3)→(a)\therefore (3) \rightarrow (a)

Thus, the correct matching is (1,b),(2,c),(3,a)(1, b), (2, c), (3, a), which corresponds to Option C.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Machine Instructions and Addressing Modes questions