Andrew login ID Full Name Recitation Section CS 15 213 Fall 2009 Exam 1 Thursday September 24 2009 Instructions Make sure that your exam is not missing any sheets then write your full name Andrew login ID and recitation section A J on the front Write your answers in the space provided for the problem If you make a mess clearly indicate your final answer The exam has a maximum score of 76 points The problems are of varying difficulty The point value of each problem is indicated instructors reserve the right to change these values Pile up the easy points quickly and then come back to the harder problems This exam is OPEN BOOK You may use any books or notes you like No calculators or other electronic devices are allowed QUESTIONS If you have a question write it clearly on an index card and raise your hand We will take the card and write a reply Good luck Page 1 of 18 1 10 2 8 3 12 4 11 5 8 6 12 7 9 8 6 Extra 4 TOTAL 76 Page 2 of 18 Problem 1 10 points Part A Fill in the blanks in the table below with the number described in the first column of each row You can give your answers as unexpanded simple arithmetic expressions such as 15213 42 you should not have trouble fitting your answers into the space provided Remember that 32 bit floats have 8 bits of exponent and 23 bits of mantissa Description Number int x 0 float f float x What is the value of f int x 1 float f float x What is the value of f Smallest positive non zero denormalized 32 bit float Part B Assume we are running code on an IA32 machine which has a 32 bit word size and uses two s complement arithmetic for signed integers Consider the following definition int x foo unsigned int ux x int y bar Fill in the empty boxes in the table below For each of the C expressions in the first column either State that it is true of all argument values or Give an example where it is not true Puzzle True Counterexample x 31 x 31 0 x x 31 0 x y x y y x y x ux 31 31 x 31 31 Page 3 of 18 Problem 2 8 points struct char a 9 short b 3 float c char d int e char f short g foo A Show how the struct above would appear on a 64 bit x86 64 Windows machine primitives of size k are k byte aligned Label the bytes that belong to the various fields with their names and clearly mark the end of the struct Use hatch marks or x s to indicate bytes that are allocated in the struct but are not used B Rearrange the above fields in foo to conserve the most space in the memory below Label the bytes that belong to the various fields with their names and clearly mark the end of the struct Use hatch marks or x s to indicate bytes that are allocated in the struct but are not used Page 4 of 18 C How many bytes are wasted in part A inside and after the struct if the next memory value is a pointer D How many bytes are wasted in part B inside and after the struct if the next memory value is a pointer Page 5 of 18 Problem 3 12 points Consider the following two 8 bit floating point representations based on the IEEE floating point format Neither has a sign bit they can only represent nonnegative numbers 1 Format A There are k 4 exponent bits The exponent bias is 7 There are n 4 fraction bits 2 Format B There are k 6 exponent bits The exponent bias is 31 There are n 2 fraction bits Fill in the blanks in the table below by converting the given values in each format to the closest possible value in the other format Express values as whole numbers e g 17 or as fractions e g 17 64 If necessary you should apply the round to even rounding rule If conversion would cause an overflow follow the IEEE standard convention for representing Infinity You should also assume IEEE conventions for representing denormalized values Format A Format B Bits Value Bits Value 0111 0000 1 011111 00 1 112 23 32 110111 10 0000 0101 Page 6 of 18 Problem 4 11 points Your friend Harry Bovik who hasn t taken 15 213 is in need of your help He was writing a function to do strange arithmetic for a project of his but accidentally deleted his source code file and also spilled his drink across the sheet of paper with his scratch work on it leaving him with only half legible code and an executable file that he compiled just recently Being the clever student that you are you ask to see his scratchwork and executable file int foo a b 0 switch case 0 b case 1 b case 2 b case 3 b case 4 b return b Page 7 of 18 Feeding the executable to your trusty debugger you find the following relevant information gdb disassemble foo Dump of assembler code for function foo 0x0000000000400508 foo 0 mov 0x0 edx 0x000000000040050d foo 5 lea 0x1 rdi eax rdi first argument 0x0000000000400510 foo 8 cmp 0x4 eax 0x0000000000400513 foo 11 ja 0x40052c foo 36 0x0000000000400515 foo 13 mov eax eax 0x0000000000400517 foo 15 jmpq 0x4006d0 rax 8 0x000000000040051e foo 22 mov edi edx 0x0000000000400520 foo 24 shr edx 0x0000000000400522 foo 26 not edx 0x0000000000400524 foo 28 neg edx 0x0000000000400526 foo 30 jmp 0x40052c foo 36 0x0000000000400528 foo 32 mov edi edx 0x000000000040052a foo 34 xor edi edx 0x000000000040052c foo 36 mov edx eax 0x000000000040052e foo 38 retq End of assembler dump gdb x 8g 0x4006d0 0x4006d0 0x000000000040051e 0x0000000000400522 0x4006e0 0x0000000000400524 0x0000000000400528 0x4006f0 0x000000000040052a 0x3b031b01000a6425 0x400700 0x0000000400000028 0x00000044fffffe0c 1 Unfortunately Harry s scratch work has break statements hastily scribbled in and crossed out again in every case and he can t remember which cases are supposed to have them Using the assembly dump of his function figure out which cases had breaks at the end of them Write either break or nothing at all in the last blank of each case block 2 The scratch work you were handed also failed to note what types a and b are but fortunately some of the opcodes give it away Figure out what types Harry meant for his variables to be 3 Using the disassembly of foo and the jump table you found reconstruct the rest of the switch statement 4 What values will foo return for each possible input a Page 8 of 18 Problem 5 8 points Consider the following data structure declarations struct node unsigned uid union data d struct node next union data int x 3 long y 3 Below are given four C functions and five x86 64 code blocks compiled on Linux using GCC int odin struct node ptr return ptr …
View Full Document