GATE 2017 CS – Question 21
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
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.