Midterm 2024
Midterm 2024
Instructions to students
1. Students must report 10 mins prior to the commencement of the exam & sit in their assigned seats only.
2. Students are not allowed to leave the examination hall within 1 hr after the commencement of exam
3. Mobile phones/any form of communication devices are strictly prohibited in the exam rooms. It is best to leave the
mobile phone in the hostel itself before coming for the exam.
4. Mere possession of a mobile phone/communication device inside the examination hall or during the exam will be
treated as a case of cheating (absolutely no excuses). In such cases, suitable action will be taken.
5. No form of unfair means (including talking to another student, copying from another student's paper, copying from
any books, notes, cheat sheets, etc., use of mobile phone/communication devices) during the examination will be
tolerated. A student found resorting to any form of unfair means during the examination, will be given 'F' grade in that
course as a minimum punishment. No appeals will be accepted.
6. Abetting a student to resort to any form of unfair means will also be considered as an unfair practice. In this instance
as well, the student abetting another student will be given 'F' grade in that course. No appeals will be accepted. In case
the student who is abetting another student is from a different class/batch, suitable action will be taken on such a
student.
7. Before answering the questions, the student must write his/her name and student registration number on the answer
script.
8. When an additional sheet is taken by the student, the student must write his/her name and serial number, sign the
additional sheet and must get it countersigned by the invigilator.
10. If a student is found with a mobile phone/communication device/calculating device while taking a break to
use the washroom when the exam is in progress, it will be treated as a case of
cheating. Irrespective of whether the student is using the mobile phone/communication device/calculating device
or not, the same penalty as in item 4 will be applicable
1. Answer all parts of all the 6 questions in the space provided for each. The last blank sheet
may be used for rough work and will not be graded.
3. Assume that all numerical values shown in the questions are in decimal unless explicitly
indicated otherwise (e.g., 0x37, 1358)
Q1 (max: 20 marks, -1 for each wrong answer or wrong explanation) True/False or fill in the
blanks. For True/False answers, explanations are required and incorrect explanations will fetch
negative points as well. No explanations needed for fill-in-the-blank answers.
1. The first stage of compilation by GCC involves the processing of #define, #include and
other pre-processing directives in the source program.
2. The hexadecimal value 0x0FF1CE is stored in the register %rax. The number of logical left
shift operations (each left shift operation shifts exactly one bit) that can be performed on this
register before hitting the first non-zero bit is:
4. The value 1.28 represented in IEEE floating point representation as a float is (write
down the bit-wise representation)
7. The x86-64 ret instruction implicitly sets the value of the CPU register %rip
8. If func() is a recursive function in a C program then all of the recursive calls made to
func() will have the same associated return address.
9. A CPU with clock frequency 200 MHz has a clock period of 5 nsec.
10. The average rotational delay when reading data from a disk with 5400RPM is
approximately:
1. Which of the following statements can be used to print out and show the IEEE floating point
representation of the float variable f?
Answer:
A. printf(“%x \n”, f);
B. printf(“%x \n”, (unsigned int)f);
C. printf(“%x \n”, *(unsigned int *)(&f));
D. printf(“%x \n”, (unsigned int *)(&f));
4. Which of the following C statements will zero out the least significant 28 bits of unsigned
int X?
Answer:
A. X = (X<<28)>>28;
B. X = X & (~0x0FFFFFFF);
C. X = X & 0xF0000000;
D. X = X && 0xF0000000;
5. Which of the following C for loops will show the best locality of reference for the array
float A[1024][1024]?
Answer:
A. for (int i = 1023; i >= 0; i--)
for (int k = 1023; k >= 0; k--)
sum += A[i][k];
B. for (int i = 0; i < 1024; i++)
for (int k = 0; k < 1024; k ++)
sum += A[k][i];
C. for (int i = 0; i < 1024; i++)
for (k = 1023; k >= 0; k--)
sum += A[i][k];
D. for (int i = 0; i < 1024; i++)
for (int k = 0; k < 1024; k++)
sum += A[i][k];
2. Represent the real number -1.729 in 32 bit IEEE floating point representation. Show your
final answer in hexadecimal.
3. Represent the real value represented in 32 bit IEEE floating point as 0xC1B60000 in
decimal.
11a0 <plus>:
11a4: 89 f8 mov %edi,%eax
11a6: 85 f6 test %esi,%esi
11a8: 75 10 jne 11ba <plus+0x1a>
11aa: eb 24 jmp 11d0 <plus+0x30>
11ac: 0f 1f 40 00 nopl 0x0(%rax)
11b0: 83 ee 01 sub $0x1,%esi
11b3: 83 c0 01 add $0x1,%eax
11b6: 85 f6 test %esi,%esi
11b8: 74 0e je 11c8 <plus+0x28>
11ba: 85 f6 test %esi,%esi
11bc: 7f f2 jg 11b0 <plus+0x10>
11be: 83 c6 01 add $0x1,%esi
11c1: 83 e8 01 sub $0x1,%eax
11c4: 85 f6 test %esi,%esi
11c6: 75 f2 jne 11ba <plus+0x1a>
11c8: c3 ret
11c9: 0f 1f 80 00 00 00 00 nopl 0x0(%rax)
11d0: c3 ret
You are told that this is the assembly code obtained by compiling the following function:
1. Which registers store the value of the arguments res and incr when the function
plus is invoked?
3. Based on the assembly and the source code above, explain what you think the
nopl instruction does, and why it is inserted in the program?
Based on these lines, what do you think is the most likely hexadecimal encoding of
the nopl instruction?
5. Why do you see a different set and number of hexadecimal characters at address
11ac (0f 1f 40 00) and at address 11c9 (0f 1f 80 00 00 00 00) given that
both locations have the same instruction?
struct Employee
{
char *name;
unsigned int ID;
float salary;
float bonus;
int projects[24];
unsigned int reportsTo[8];
} Employees[32][64];