The GATE Grind

GATE 2017 CS – Question 21

Computer Organization and Architecture · Instruction Set and Addressing Modes · 1 mark · Multiple choice

Consider the C struct defined below:

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

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

  1. Post-increment addressing mode, (R1)+
  2. Pre-decrement addressing mode, -(R1)
  3. Register direct addressing mode, R1
  4. Index addressing mode, X(R1), where X is an offset represented in 2's complement 16-bit representation.

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (D) Index addressing mode, X(R1), where X is an offset represented in 2's complement 16-bit representation.

Explanation

The field `grade` is at a fixed offset from the start of the struct, which is $100 \times 4 = 400$ bytes. Index addressing computes the address as base register plus a constant offset, which is exactly what is needed. The other modes change the register or access the register itself.