Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Reorder the fields in this structure so that the structure will (a) consume the

ID: 3536249 • Letter: R

Question

Reorder the fields in this structure so that the structure will (a) consume the most space and (b) consume the least space on an IA32 machine on Linux. The IA32 architecture has a notion of an instruction prefix, which we have not yet used or discussed. One commonly used prefix is "rep". Rep repeats the instruction a fixed number of times, where the number of times is given in the %ecx. which is called the "count register" for this purpose. Rep is typically combined with a string instruction. String instructions operate with memory operands pointed at by the %esi (source) and %edi (destination) registers. For example: will copy 256 byes starting at address A to addresses starting at address B. "movsb" means "Move String of Bytes". What the rep line does is essentially this pseudo code: Give an example (in C) of a loop that could make use of the rep prefix. Why is the rep prefix potentially helpful in improving memory system performance?

Explanation / Answer

I kw the ans of 1 only


ans of this que based on the following size.


char *a 4Bytes

short *b 4Bytes

char c 1Bytes

unsigned d 4Bytes

char e 1 Bytes

double f 8 Bytes

short g 2 Bytes.


For consuming the most space order shd be as follow (there may be more then one order but all will same max size)


struct foo{

char c ;

double f ;

char e ;

unsigned d ;

short g;

char *a ;

short *b;

}


size of structre will be


1byte ( size of char) + 7 Byte(padding) + 8 Byte (size of double) +

1byte ( size of char) + 3 Byte(padding) + 4 Byte (size of unsigned)+

2 Byte (size of short) + 2 Byte(padding) + 4 Byte (size of char *) +

4 Byte (size of char *) = 36 Byte but it is not multiple of 8 thats why

total size = 40 Bytes.



For consuming the least space order shd be as follow (there may be more then one order but all will same max size)


struct foo{

double f ;

unsigned d ;

char *a ;

short *b;

char c ;

char e ;

}


8 Byte (size of double) + 4 Byte (size of unsigned) + 4 Byte (size of char *) +

4 Byte (size of char *) + 2 Byte (size of short) + 1byte ( size of char) +1byte ( size of char)


size of structre will be =24 Bytes.