Exam 1 Solutions CS 213 Fall 2002 ********* Problem 1 ********* Expression decimal binary ----------------------------------- Zero | 0 | 0 0000 --- | -5 | 1 1011 --- | -14 | 1 0010 y | -9 | 1 0111 z | 23 | 1 0111 y-z | 0 | 0 0000 TMax | 15 | 0 1111 TMin | -16 | 1 0000 ----------------------------------- ********* Problem 2 ********* Part I A. Denormalized numbers (a) E = -6 (b) M = 31/32 B. Normalized numbers (a) E = -6 (b) E = +7 (c) M = 63/32 Part II ----------------------------------------------------------- Description | E | M | V | Binary ----------------------------------------------------------- Zero | -6 | 0 | 0 | 0 0000 00000 ----------------------------------------------------------- Smallest positive | -6 | 1/32 | 1/2048 | 0 0000 00001 ----------------------------------------------------------- Largest denorm | -6 | 31/32| 31/2048 | 0 0000 11111 ----------------------------------------------------------- Smallest pos norm | -6 | 1 | 32/2048 | 0 0001 00000 ----------------------------------------------------------- One | 0 | 1 | 1 | 0 0111 00000 ----------------------------------------------------------- Largest odd integer | 5 | 63/32| 63 | 0 1100 11111 ----------------------------------------------------------- Largest finite number| 7 | 63/32| 252 | 0 1110 11111 ----------------------------------------------------------- Positive infinity | - | - | +inf | 0 1111 00000 ----------------------------------------------------------- ********* Problem 3 ********* M=3 N=9 ********* Problem 4 ********* A. Product_Struct1: end of struct | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |name |XX|type |model |c |XXXXXXXX|price | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ Product_Struct2: end of struct | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |name |type |c |XX|model|XXXXX|price | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ B. sizeof(Product_Struct1) = 24 sizeof(Product_Struct2) = 16 sizeof(Product_Union) = 24 C. (a) p->product_id = 0x64636261 (b) p->two.name = 0x64636261 (c) p->two.type = 0x6665 (d) p->two.color = 0x00 (e) p->two.model = 0x2ace ********* Problem 5 ********* (c) fun6 ********* Problem 6 ********* A. return addr: 0x04 saved %ebp : 0x00 &buf : 0xf8 saved %ebx : 0xd8 %esp : 0xd8 B. (%ebp) = 0x6874726f C. 0x080484e3 ********* Problem 7 ********* int foo(int x, int y, int z) { int i, result; result = y; for (i = x; i >= z; i--) { result = result + i; } return result; }