Andrew login ID Full Name Recitation Section CS 15 213 Spring 2009 Exam 1 Tues February 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 100 points The problems are of varying difficulty The point value of each problem is indicated 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 Good luck 1 16 2 22 3 13 4 13 5 22 6 14 TOTAL 100 Page 1 of 17 Problem 1 16 points Consider a new floating point format that follows the IEEE spec you should be familiar except with 3 exponent bits and 2 fraction bits and 1 sign bit Fill in all blank cells in the table below If in the process of converting a decimal number to a float you have to round write the rounded value next to the original decimal as well Description Decimal Bias Binary Representation Smallest positive number Lowest finite Smallest positive normalized 6 16 6 4 1 010 10 11 Page 2 of 17 Problem 2 22 points Consider the C code written below and compiled on a 32 bit Linux system using GCC struct s1 int y short x struct s2 struct s1 a struct s1 b int x char c int y char e 5 int z short fun1 struct s2 s return s a x void fun2 struct s2 s return s z int fun3 struct s2 s return s z short fun4 struct s2 s return s b x Page 3 of 17 a What is the size of struct s2 b How many bytes are wasted for padding You may use the rest of the space on this page for scratch space to help with the rest of this problem Nothing written below this line will be graded Page 4 of 17 c Which of the following correspond to functions fun1 fun2 fun3 and fun4 push mov mov movswl pop ret ebp esp ebp 0x8 ebp eax 0x4 eax eax ebp ANSWER push mov mov mov movswl pop ret ebp esp ebp 0x8 ebp eax 0x8 eax eax 0x4 eax eax ebp ANSWER push mov mov mov pop ret ebp esp ebp 0x8 ebp eax 0x20 eax eax ebp ANSWER push mov mov add pop ret ebp esp ebp 0x8 ebp eax 0x20 eax ebp ANSWER Page 5 of 17 d Assume a variable is declared as struct s2 myS2 and the storage for this variable begins at address 0xbfbdc300 gdb x 20w myS2 0xbfbdc300 0x000000d5 0xbfbdc310 0x000000ff 0xbfbdc320 0x0000000c 0xbfbdc330 0xb7ed9fd5 0xbfbdc340 0xb7eda0b9 0x0000000f 0x0000012c 0x080496a0 0xb7fc1ff4 0xb7fc1ff4 0xbfbdc338 0x01020501 0xbfbdc338 0x000000f3 0xbfbdc3a8 Fill in all the blanks below HINTS Label the fields Not all 20 words are used Remember endianness What would be returned by fun1 myS2 0x fun2 myS2 0x fun3 myS2 0x fun4 myS2 0x What is the value of myS2 b y 0x myS2 a y 0x myS2 z 0x myS2 e 1 0x Page 6 of 17 0x00000000 0xb7f0a603 0x0804828d 0x08040012 0xb7ec6dce Problem 3 13 points This problem concerns assembly code generated by GCC for a function containing a switch statement on an x86 64 machine Below is the entire assembly dump of the function selector whose C skeleton is given subsequently 0000000000400470 selector 400470 8d 46 01 400473 83 f8 06 400476 77 1a 400478 89 c0 40047a ff 24 c5 a0 05 40 00 400481 48 83 c7 04 400485 eb 0e 400487 8b 37 400489 eb 0a 40048b d1 fe 40048d 83 c6 05 400490 eb 03 400492 8d 34 f6 400495 48 63 c6 400498 8b 04 87 40049b c3 lea cmp ja mov jmpq add jmp mov jmp sar add jmp lea movslq mov retq 0x1 rsi eax 0x6 eax 400492 selector 0x22 eax eax 0x4005a0 rax 8 0x4 rdi 400495 selector 0x25 rdi esi 400495 selector 0x25 esi 0x5 esi 400495 selector 0x25 rsi rsi 8 esi esi rax rdi rax 4 eax The code at line 40047a uses an indirect jump to index into a jump table 40047a ff 24 c5 a0 05 40 00 jmpq 0x4005a0 rax 8 In GDB we examine the memory dump at address 0x4005a0 which produces the following output gdb x 8g 0x4005a0 0x4005a0 0x0000000000400487 0x4005b0 0x0000000000400492 0x4005c0 0x000000000040048b 0x4005d0 0x0000000000400481 0x0000000000400481 0x000000000040048d 0x0000000000400492 0x0000002c3b031b01 Page 7 of 17 Fill in the blank portions of C code below to reproduce the function corresponding to this object code int selector int x int y switch y case case break case y break case y case y break default y return Page 8 of 17 Problem 4 13 points The function below is hand written assembly code for a sorting algorithm Fill in the blanks on the next page by converting this assembly to C code globl mystery sort mystery sort dec exports the symbol so other c files can call the function rsi xor inc jmp rdx rdx rdx loop1 check xor mov jmp rdx rdx rsi rcx loop2 check dec mov mov cmp jle mov mov inc rcx 8 rdi rcx 8 r8 rdi rcx 8 r9 r8 r9 loop2 check r8 rdi rcx 8 r9 8 rdi rcx 8 rdx loop1 loop2 loop2 check test jnz rcx rcx loop2 loop1 check test jnz rdx rdx loop1 ret Page 9 of 17 void mystery sort long array long len long a b tmp do a for b b b if array array tmp array array array array tmp a while a Page 10 of 17 Problem 5 22 points Circle the correct answer 1 What register is the return value from a function stored in Assume 32 bit return value a eip b ebp c eax d esp 2 The pushl instruction does what to the stack pointer a decrements the stack pointer by 4 bytes b decrements the stack pointer by 1 byte c increments the stack pointer by 4 bytes d increments the stack pointer by 1 byte 3 What does the test instruction do before setting condition flags a bitwise and b subtraction c bitwise xor d bitwise bang 4 On the x86 64 fish machines what is the size of an int a 1 byte b 32 bytes c 4 bytes d 8 bytes 5 Which of the following represents the order of the registers that store the first four arguments to a function in x86 64 a rdi rsi rcx rdx b rax rbx rsi rdi c rsi rdi rdx rbx d rdi rsi rdx rcx Page 11 of 17 6 The operator performs what operation on a value a bitwise complement b logical complement c reverses the order of the bits d determines if the number is zero 7 What byte ordering system do the fish machines use a Little endian b Big endian c Intel x86 64 …
View Full Document