Consider the C struct defined below: struct data { int marks [100]; char…

2017

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:

Answer: D. Index addressing mode, X(R1), where X is an offset represented in 2′s complement 16-bit representationKey idea: the grade field is located at a fixed byte offset from the struct base, so use an addressing mode that encodes that offset. Compute the offset:…

  1. A.

    Post-increment addressing mode, (R1)+

  2. B.

    Pre-decrement addressing mode, -(R1)

  3. C.

    Register direct addressing mode, R1

  4. D.
    1. Index addressing mode, X(R1), where X is an offset represented in 2′s complement 16-bit representation

Attempted by 79 students.

Show answer & explanation

Correct answer: D

Key idea: the grade field is located at a fixed byte offset from the struct base, so use an addressing mode that encodes that offset.

  • Compute the offset: offset = 100 * sizeof(int). Typically sizeof(int) == 4, so offset = 400 bytes.

  • Use an indexed memory load with that offset: load byte from X(R1) where R1 holds &student and X is the computed offset. This directly accesses student.grade without modifying R1.

  • If the offset does not fit in the instruction's 16-bit signed immediate, first form the address in a register (e.g., add the offset into another register) and then use register-indirect addressing to load the byte.

Explore the full course: Computer Architecture

Loading lesson…