Exam 1 Solutions CS 213 Fall 2001 ********* 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 ********* ------------------------------------------------------------------ Description | Binary | M | E | Value ------------------------------------------------------------------ Minus Zero | 1 000 0000 | 0 | -2 | -0.0 ------------------------------------------------------------------ --- | 0 100 0101 | 21/16 | 1 | 21/8 ------------------------------------------------------------------ Smallest Denormalized| 1 000 1111 | 15/16 | -2 | -15/64 ------------------------------------------------------------------ Largest normalized | 0 110 1111 | 31/16 | 3 | 31/2 ------------------------------------------------------------------ One | 0 011 0000 | 1 | 0 | 1.0 ------------------------------------------------------------------ --- | 0 101 0110 | 11/8 | 2 | 5.5 ------------------------------------------------------------------ Positive infinity | 0 111 0000 | --- | --- | +\infty ------------------------------------------------------------------ ********* Problem 3 ********* fun8 ********* Problem 4 ********* fun6 ********* Problem 5 ********* M=15 N=9 ********* Problem 6 ********* int foo(int a) { int i; int result = a + 2; for (i=0; i < a; i++) { result += (i + 5); result *= (i + 3); } return result; } ********* Problem 7 ********* A. OldSensorData: 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 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |code |XXXXX| start | raw |XX| data | | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ NewSensorData: 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 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |code |start| raw |XX|sense| ext |XXXXX| data | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ B. newData->start = 0xff00 newData->raw[0] = 0xb8 newData->raw[2] = 0x50 newData->raw[4] = 0xe1 newData->sense = 0x008f ********* Problem 8 ********* A. <- buf[0] -><- buf[1] -> +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | |64|72|2e|65|76|69|6c|00| | | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ ^ ebp ---------- addresses increase this way ------> The printf inside main prints 0x6c6976 (or 0x006c6976 is OK too) B. (a) buf[0] = 0x652e7264 buf[3] = 0x08040073 (b) %ebp = 0x6576696c