Question
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
Official answer and solution
- Official answer
- D
- From
- Official GATE 2017 answer key
Solution
Analyze how structure fields at fixed offsets are accessed in machine instruction sets.
The struct student is stored in memory starting at a base address held in register R1:
struct data {
int marks[100];
char grade;
int cnumber;
};
The field student.grade is located at a fixed byte offset from the start of the struct. For example, if an integer is 4 bytes, marks[100] occupies bytes, so grade is located at offset relative to R1.
To access memory at an address computed by adding a constant displacement to a base register R1 without modifying R1, the processor uses index addressing mode (or base-displacement addressing mode), denoted .
Post-increment and pre-decrement modes modify the register R1 itself, which is not desirable for accessing a fixed struct field. Register direct mode accesses only the register contents without referencing memory. Therefore, index addressing mode is the appropriate and efficient mode.
D
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2017 Computer Science and Information Technology (CS) Session 1
- Question
- 11 of 65, printed as CS Q.11
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.