Final Exam Solutions
CS 213 Fall 2006

*********
Problem 1
*********
Value	FP bits	  Rounded val	Comment	
1/32	000 00	  0		denorm, round down to zero
1/16    000 01    1/16		smallest positive denorm, exact
3/32    000 10    1/8		denorm, round up 
1       011 00    1		normalized, exact
11      110 10    12		normalized, round up
12      110 10    12		normalized, no rounding

*********
Problem 2
*********
CNT1=7
CNT2=3
CNT3=2

*********
Problem 3
*********
Example solutions:
type_t: long, N=4
type_t: int[2], N=5
type_t: long double, N=3

*********
Problem 4
*********
int looped (int a[], int n) {
    int i;
    int x = 0;

    for(i = 0; x < n; i++) {
        if (x < a[i])
            x = a[i];
    }
    return x;
}

*********
Problem 5
*********
A. &buf = 0x55683a68
B. %ebp = 0x55683a78
C. ret addr = 0x08048bf9
D. %esp = 0x55683a58
E. 00 00 00 00 00 00 00 00 
   00 00 00 00 20 8b 04 08

*********
Problem 6
*********
1. CPE = 15/3
2. CPE = 10/3
3. CPE = 7/3
4. CPE = 7/3
5. CPE = 10/3

-1 if you forgot to divide by three.

*********
Problem 7
*********
A.
(a) | 10 CT | 1 CI | 3 CO |
(b) CI = 0x1, CO = 0x4
(c) 
1 0 0
1 1 0
0 1 1
0 0 1

B.
m m h
m h m
h h h
h h h

C.
(a) (i) 7 misses, (ii) 13 misses
(b) (i) 2 misses, (ii) 8 misses

*********
Problem 8
*********
A. abc, bac
B. 213

*********
Problem 9
*********
A. 15
B. 11

*********
Problem 10
*********
A. 0
B. -1
C. 0
D. 1

*********
Problem 11
*********
A. yes

B. The deadlock occurs because mutex4 and mutex2 are allocated in
different orders.  Here is one example:

t1p4 -> t2p1 -> t2p2 -> t2p4 -> t1p2

At this point, thread 1 is blocked forever on mutex2 and thread 2 is
blocked forever on mutex 4.