Solutions to Exam #2, CS 347, Spring '98 1. A. 0x18, 0x30 B. a: largest b: &array[i] c: i d: array e: array[i] f: length g: 0 2. A. 32 B. 16 C. To save during call to fib(n-2) D. 8 E. It's a callee save register used by fib F. r26, the return pointer G. Nothing. It's there to pad for alignment 3. A. s4subq $1, $1, $2 # (4-1) * x B. s8addq $1, $1, $2 # 8x +x = 9x addq $2, $2, $2 # 9x + 9 x = 18x C. subq $31, $1, $2 # 0 - x = -x s8subq $2, $2, $2 # 8*-x -(-x) = -7x D. s8subq $1, $1, $2 # 8x - x = 7x s8subq $2, $1, $2 # 8*(7x) - x = 55x 4. A. 111001 00111 00000000000000000101 B. $7 C. 0x100 + 4 + 4*5 = 0x118 5. A. 010000 11111 00000101 1 0000000 010100 B. $31, 5 C. $4 D. 0x00 6. 16 bytes: 11 11 22 -- 33 -- -- -- 44 44 44 44 44 44 44 44 (where -- indicates a byte that is not set by the code) 7. 16 bytes (only 9 needed, but 7 added) 11 22 33 44 44 44 44 44 -- -- -- -- -- -- -- -- 8. mulq $17, 760, $2 # $2 = 760 * x addq $2, $18, $2 # $2 = 760 * x + y s4subq $2, $2, $2 # $2 = 3*(760x + y) addq $2, $16, $2 # $2 = &s[x][y].red 9. A. 188: 1*1 (initialization) + 21*7 (test) + 20*1 (update) + 20*1 (body) B. x = 21, y = 40 (loop test succeeds 20 times and fails 1 time) 10. A. 88: 1*6 (initialization) + 21*2 (test) + 20*1 (update) + 20*1 (body) B. x = 1, y = 40 C. No. The side effect in upper_bound() causes the two to have different behaviors with respect to variable x 11. ... for (i = x; i > x-y; i = i-2) ...