Skip to content
Official PYQ · 2017

GATE CS 2017 Set 1 Q11 — Machine Instructions and Addressing Modes

Explain with AI

Consider the CC  struct defined below:

struct data {
    int marks [100];
    char grade;
    int cnumber;
};
struct data student;

The base address of student is available in register R1R1. The field student.grade can be accessed efficiently using:

Choose one option
View worked solution

Answer: D

To access a specific field of a structure, we need to calculate its memory address relative to the base address of the structure.

The layout of the struct data in memory is sequential:

  • marks (an array of 100 integers) starts at the base address of the structure.
  • grade (a character) is located immediately after the marks array.

Let the base address of student (stored in register R1R1) be BB. The member student.grade is located at a fixed offset XX from the base address, where:

X=100×sizeof(int)X = 100 \times \text{sizeof(int)}

Therefore, the effective address of student.grade is calculated as:

Effective Address=Contents(R1)+X\text{Effective Address} = \text{Contents}(R1) + X

This is precisely how Index addressing mode (also referred to as Base-displacement addressing mode), represented as X(R1)X(R1), operates. The constant offset XX is determined at compile-time and can be easily represented as a 16-bit 2's complement displacement.

Why other options are incorrect:

  • Options A & B (Post-increment / Pre-decrement): These modes modify the contents of register R1R1 (the base address pointer) as a side effect, which is undesirable because we want to preserve the base address of the structure in R1R1 for future accesses.
  • Option C (Register direct): This mode accesses the contents of the register R1R1 itself, rather than the memory location pointed to by R1R1.

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

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