Exam 1 Solutions CS 213 Fall 2003 ********* Problem 1 ********* --------------------------------- Expression decimal binary --------------------------------- Zero | 0 | 00 0000 --- | -6 | 11 1010 --- | 18 | 01 0010 ux | 47 | 10 1111 y | -3 | 11 1101 x >> 1 | -9 | 11 0111 TMax | 31 | 01 1111 -TMin | -32 | 10 0000 TMin+TMin | 0 | 00 0000 ********* Problem 2 ********* Part I A. [1,2): 2^7 B. [2,3): 2^6 Part II A. Denormalized numbers (a) E = -6 (b) M = 127/128 B. Normalized numbers (a) E = -6 (b) E = +7 (c) M = 255/128 Part III ----------------------------------------------------------- Description | E | M | V | Binary ----------------------------------------------------------- Zero | -6 | 0 | 0 | 0 0000 00000 ----------------------------------------------------------- Smallest positive | -6 | 1/128 | 1/8192 | 0 0000 00001 ----------------------------------------------------------- Largest denorm | -6 | 127/128 | 127/8192| 0 0000 11111 ----------------------------------------------------------- Smallest pos norm | -6 | 1 | 128/8192| 0 0001 00000 ----------------------------------------------------------- ********* Problem 3 ********* fun6 ********* Problem 4 ********* fall summer spring winter ********* Problem 5 ********* IA-32 Windows: 1 2 3 || 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 || c - - - - - - - d d d d d d d d s s - - p p p p f f f f p p p p || || IA-32 Linux: 1 2 || 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 || c - - - d d d d d d d d s s - - p p p p f f f f p p p p || || ********* Problem 6 ********* int mystery(int a, int b, int c) { int x, y; y = c; for (x = a + b; x > 0; x--) y++; return y; } ********* Problem 7 ********* A. buf[0] = 0x64636261 buf[1] = 0x68676665 buf[2] = 0x08040069 B. ebp = 0x68676665 C. eip = 0x08040069 ********* Problem 8 ********* %eax = 0x400446e8