0% found this document useful (0 votes)
10 views12 pages

Midterm 2024

The document is an exam paper for UMC 102 Midterm Test scheduled for February 20, 2024, with a maximum score of 100 marks. It includes detailed instructions for students regarding exam conduct, question types, and answer formats, along with specific questions covering topics such as base conversions, representation conversions, and assembly code analysis. Students are warned against the use of mobile phones and unfair practices during the exam, with strict penalties for violations.

Uploaded by

orgjeeadv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views12 pages

Midterm 2024

The document is an exam paper for UMC 102 Midterm Test scheduled for February 20, 2024, with a maximum score of 100 marks. It includes detailed instructions for students regarding exam conduct, question types, and answer formats, along with specific questions covering topics such as base conversions, representation conversions, and assembly code analysis. Students are warned against the use of mobile phones and unfair practices during the exam, with strict penalties for violations.

Uploaded by

orgjeeadv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Q1 Q2 Q3 Q4 Q5 Q6 Total

(20) (10) (10) (15) (25) (20) (100)

DO NOT WRITE ANYTHING ABOVE THIS LINE

UMC 102 Midterm Test 20 February 2024


Maximum marks: 100 Duration: 3 hours

Name: ________________________________ SR No: ____________________

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.

9. DURING THE UMC 102 EXAMINATIONS, POSSESSION OR USE OF CALCULATING DEVICES OF


ANY KIND IS PROHIBITED.

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

Pages: 11 printed + 1 blank 1


UMC 102 Midterm Test Instructions

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.

2. Assume the following sizes in Bytes for different types of data

char int unsigned int float double pointer


1 4 4 4 8 8

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:

3. The largest unsigned integer value in 20 bits is:

4. The value 1.28 represented in IEEE floating point representation as a float is (write
down the bit-wise representation)

Pages: 11 printed + 1 blank 2


5. The 64 bit IEEE double precision floating point representation uses an exponent bias value
of 1023.

6. The x86-64 CPU register %rsp is caller saved.

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:

Pages: 11 printed + 1 blank 3


Q2 (10 marks) Multiple choice: Identify the options that correctly answer each question below.
Note: Zero or more of the options could be correct. Points will be given if and only if all the correct
options are selected. No points will be given if any wrong options are selected and/or all the correct
options are not selected. No justification is required.

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));

2. Which of the following are volatile memory?


Answer:
A. Magnetic hard disk B. Solid state disk C. ROM D. SRAM

3. Which of the following values cannot be represented in 2s complement representation using


5 bits?
Answer:
A. 16 B. 15 C. -15 D. -16

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];

Pages: 11 printed + 1 blank 4


Q3 (10 marks) Base conversion: Show your work and the final answer for the following base
conversions.
1. Convert 1729 into the hexadecimal number system.

2. Convert 0x1729 into the base 4 number system.

Pages: 11 printed + 1 blank 5


Q4 (15 marks) Representation conversion: Show your work and the final answer for the following
representation conversions.
1. Represent -1729 in the 2s complement representation. Show your final answer in
hexadecimal.

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.

Pages: 11 printed + 1 blank 6


Q5 (25 marks) Look at the following fragment of x86-64 assembly code:

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:

int plus (int res, int incr) {


if (incr == 0) return res;
if (incr > 0) return plus (res + 1, incr - 1);
return plus (res - 1, incr + 1);
}

Now, answer the following questions:

1. Which registers store the value of the arguments res and incr when the function
plus is invoked?

Pages: 11 printed + 1 blank 7


2. Clearly, plus is a recursive function, yet there are no recursive call instructions
observed in the assembly code. Explain how this is possible.

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?

Pages: 11 printed + 1 blank 8


4. Observe the following two lines in the assembly code:

11ac: 0f 1f 40 00 nopl 0x0(%rax)


...
11c9: 0f 1f 80 00 00 00 00 nopl 0x0(%rax)

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?

Pages: 11 printed + 1 blank 9


Q6 (20 marks) The compiler assigns memory starting at memory address 10000 for the array
Employees declared below. Assume that the compiler assigns space for the fields of struct
Employee in order of declaration and based on the size table given on page 2 of this Midterm Test,

struct Employee
{
char *name;
unsigned int ID;
float salary;
float bonus;
int projects[24];
unsigned int reportsTo[8];
} Employees[32][64];

1. Calculate the size of struct Employee.

2. Calculate the size of the array Employees.

Pages: 11 printed + 1 blank 10


3. Calculate the address of Employees[9][18].

4. Assuming that the address of Employees[9][12].projects is 0(%rax) calculate


the address of Employees[10][20].projects[12] in terms of %rax.

Pages: 11 printed + 1 blank 11


Pages: 11 printed + 1 blank 12

You might also like