edited by
14,372 views
49 votes
49 votes

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\text{-bit}$ representation
edited by

3 Answers

Best answer
59 votes
59 votes

Answer is option (D).

Displacement Mode :-

Similar to index mode, except instead of a index register a base register will be used. Base register contains a pointer to a memory location. An integer (constant) is also referred to as a displacement. The address of the operand is obtained by adding the contents of the base register plus the constant. The difference between index mode and displacement mode is in the number of bits used to represent the constant. When the constant is represented a number of bits to access the memory, then we have index mode. Index mode is more appropriate for array accessing; displacement mode is more appropriate for structure (records) accessing.

Reference:

http://www.cs.iit.edu/~cs561/cs350/addressing/addsclm.html

edited by
8 votes
8 votes

Actually answer can be both C or D.It depends on the architecture.If the machine is byte addressable then option D is correct.

For instance, say int takes 4 bytes and char takes 8 bytes.If it is byte addressable then the memory layout will be somewhat shown in the figure.If we are using for e.g decimal addressing and lets take the base address as 1000,then we need displacement of 51 to access student.grade.

Now if the machine is word addressable and say 1 word=100*4(for marks array)+8(for grade)+4(for cnumber)=412bytes .Then the picture will look something like..

In this case we dont need displacement...it can be done with direct addressing mode only.

2 votes
2 votes

sruct data
{
int marks[100];
char grade;
int cnumber;
}; struct data student
Base Address of student is available in R1.
So student.grade can be accessed efficiently by Relative Indexed Addressing Mode.
It is clearly mentioned X is the offset address to be summed with Base Address of R1.

Hence Index Addressing mode X(R1), where X is an offset represented in 2’s complement 16-bit representation.
⇾ Relative, Base Indexed & all subtypes of Indirect addressing modes are used with Arrays.

Answer:

Related questions