CS 354, version A Fall 2014 | Name:___________________ Section:________________ ID:___________________ | |
Exam 2 | ||
No electronic devices may be used while taking this exam.
No calculators, no cell phones.
Each student is allowed one 8.5 by 11 inch sheet of paper with handwritten notes. Do not write on the notes sheet during the exam.
Show all work, and do any/all calculations on the exam. Extra scratch paper may not be used. Partial credit will be given based on work shown. |
Exam Score Q1 = _____ / 10 Q2 = _____ / 5 Q3 = _____ / 10 Q4 = _____ / 10 Q5 = _____ / 10 Q6 = _____ / 30 Q7 = _____ / 20 Q8 = _____ / 5 Total = _____ / 100 |
Question 1 (10 points)
You find this x86 code within a program:
testl %eax, %eax
jz next
inc %ecx
next:
Assume that the value in %eax
is the integer variable aa
,
and the value in %ecx
is the integer variable count
.
Write the C code fragment that this assembly language fragment implements.
Question 2 (5 points)
Write the equivalent of the x86 instruction
pushl %edx
as a series of x86 instructions, without using the
pushl
instruction.
Question 3 (10 points total)
Part A (4 points)
While working on a job, you suspect that the stepA program that
you are using has a bug. You decide to investigate, before you send
an email claiming to have found a bug in stepA.
But, you only have the Linux binary executable of stepA.
What Linux program can you use to generate an assembly language
version of the stepA?
Part B (6 points)
In your divide.c
program from assignment 3,
what two types of interrupts did you catch and handle?
Question 4 (10 points)
Write an x86 code fragment that implements the C code fragment:
ar[i] = -36 + ar[i];Assume
ar
is an
array of integers,
variable i is in %edi
,
and this code initializes other variables:
leal ar, %ebx movl $-36, %eax
Question 5 (10 points total)
The compiler is working to produce the x86 assembly language
code for a function that uses 5 integer-type local variables.
Write the prologue code for this function.
Question 6 (30 points total)
Here are portions of a C program (on the left) and its x86 assembly
language version (on the right).
int f1(int a, int b) { f1: push %ebp
int x; mov %esp,%ebp
sub $0x10,%esp
x = a + b; mov _____(%ebp),%eax
mov _____(%ebp),%edx
add %edx, %eax
mov %eax,-0x4(%ebp)
return __________ ; mov -0x4(%ebp),%eax
leave
ret
}
int main() { main: push %ebp
int xx, yy, zz; mov %esp,%ebp
sub $0x18,%esp
movl $0x10,-0xc(%ebp)
xx = _______; movl $0xffffffff,-0x8(%ebp)
mov -0x8(%ebp),%eax
yy = _______; mov %eax,0x4(%esp)
mov -0xc(%ebp),%eax
mov %eax,(%esp)
zz = f1(xx, yy); call f1
mov %eax,-0x4(%ebp)
mov $0x80484f4,%eax
mov -0x4(%ebp),%edx
mov %edx,0x4(%esp)
mov %eax,(%esp)
printf("%d\n", zz); call printf
return 0; mov $0x0,%eax
} leave
ret
Part A (5 points)
Circle the prologue code within
f1()
.
Part B (15 points)
Fill in the blanks within both the
the C code and the assembly language code to complete the
missing code.
Part C (10 points)
What is the output of this program?
Question 7 (20 points total)
Part A (4 points)
What is the key difference between RAM and ROM?
Part B (4 points)
Identify one advantage that SSDs have over rotating disks.
Part C (4 points)
If an application invokes getc(),
and no key has been pressed on the keyboard,
what technique does the operating system code
use to block to wait for input?
Part D (4 points)
What distinguishes an interrupt from a trap?
Part E (4 points)
Are real world exception handlers reentrant or non-reentrant?
Question 8 (5 points)
What programming bug does a stack smashing attack rely upon?