Skip to content
GATEiit

GATE CSE 2017 Session 1 Q21: Addressing mode to access student.grade in a struct

Syllabus topic: Instruction set and addressing modes

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

Try it: multiple choice: exactly one correct option

Select one option
Wrong answer costs 1/3 mark in GATE.
Show answer and explanation

Answer: D (official GATE 2017 final answer key)

Concept used: A struct field at a fixed offset from a base address held in a register is reached with base/index (displacement) addressing.

Concept notes

Loading notes…

First step: Compute the offset of grade from the start of the struct (after 100 ints) and ask which mode adds a constant offset to R1.

Full step-by-step solution

Loading…

Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.

More questions on Instruction set and addressing modes

Every PYQ on this topic →

Share this question

WhatsAppDownload image

Source: official GATE 2017 Session 1 CS question paper and final answer key, organised by IIT Roorkee. Question paper · Answer key