in CO and Architecture edited by
14,442 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
in CO and Architecture edited by
by
14.4k views

4 Comments

Base address of student is given so we can only reach first element of student structure which is student. marks[0]

To access grade we need offset to jump at grade.
1
1

Base Address take you to the Student structure where it’s stored and it will be the first address . Now from there you have to skip array[100] to reach to grade . So you need some value which will help you to do thisHere Offset come in the picture to help you to skip array[100] and take you to the GRADE

So it is Indexed Addressing Mode = BASE + OFFSET

2
2
@shikhar. thanks bro
1
1

3 Answers

59 votes
59 votes
Best answer

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

4 Comments

AS WE ALL KNOW IT IS A LINKED LIST, HENCE I WOULD ALSO HAVE CHOSEN D AS THE OPTION.
0
0
What if , register indirect addressing mode is given in the options???.. is it ok to move with this also???
0
0

 the point of the question is to find out if the student knows which addressing mode to use if the base address is given. So technically register indirect can be used to access struct elements, provided that we know its address. But it is more eficcient if we access it using an offset to the base address given so i would say even then option D would have been more appropriate

0
0
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 Comments

can u tell me wat is register direct addressing ??? and if u consider C as answer hw r u going to retrieve student.grade ??
0
0

register direct addressing mode  ADDRESS OF THE DATA IS DIRECTLY PRESENT IN THE REGISTER.

0
0
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.

2 Comments

Why not a option
1
1
Because they asked for efficiently
0
0
Answer:

Related questions