Andrew login ID Full Name Section 15 213 18 243 Spring 2011 Exam 1 Thursday March 3 2011 v1 Instructions Make sure that your exam is not missing any sheets then write your Andrew login ID full name and section on the front This exam is closed book closed notes You may not use any electronic devices Write your answers in the space provided below 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 Good luck 1 12 2 17 3 13 4 11 5 20 6 12 7 15 TOTAL 100 Page 1 of 13 Problem 1 12 points Multiple choice Write the correct answer for each question in the following table 1 2 11 12 3 4 5 6 7 8 9 10 1 Consider an int a and an int n If the value of ecx is a and the value of edx is n which of the following assembly snippets best corresponds to the C statement return a n a ret ecx edx 4 b leal ecx edx 4 eax ret c mov ecx edx 4 eax ret d mov ecx edx 1 eax ret 2 Which of the following 8 bit floating point numbers 1 sign 3 exponent 4 fraction represent NaN a b c d 1 000 1111 0 111 1111 0 100 0000 1 111 0000 3 rsp is 0xdeadbeefdeadd0d0 What is the value in rsp after the following instruction executes pushq rbx a b c d 0xdeadbeefdeadd0d4 0xdeadbeefdeadd0d8 0xdeadbeefdeadd0cc 0xdeadbeefdeadd0c8 4 How many lines does a direct mapped cache have in a set a b c d 0 1 2 4 Page 2 of 13 5 On an x86 64 Linux system which of these takes up the most bytes in memory a char a 7 b short b 3 c int c d float d 6 Two dimensional arrays are stored in order to help with cache performance a column major b row major c diagonal major d Art major 7 Which register holds the first argument when an argument is called in IA32 32 bit architecture a edi b esi c eax d None of the above 8 What is the C equivalent of mov 0x10 rax rcx 4 rdx a rdx rax rcx 4 10 b rax rcx 4 10 rdx c rdx rax rcx 4 0x10 d rdx rax rcx 4 0x10 9 What is the C equivalent of leal 0x10 rax rcx 4 rdx a rdx 10 rax rcx 4 b rdx 0x10 rax rcx 4 c rdx 0x10 rax rcx 4 d 0x10 rax rcx 4 rdx 10 What is the C equivalent of mov rax rcx a rcx rax b rax rcx c rax rcx d rcx rax Page 3 of 13 11 In x86 IA32 an application s stack grows from a High memory addresses to low memory addresses b Low memory addresses to high memory addresses c Both towards higher and lower addresses depending on the action d Stacks are a fixed size and do not grow 12 True or False In x86 64 the rbp register can be used as a general purpose register True False Page 4 of 13 Problem 2 17 points Bits A Convert the following from decimal to 8 bit two s complement 67 35 B Please solve the following are datalab style puzzle Please write brief and clear comments You may use large constants eg instead of saying 1 16 you may use 0x10000 reverseBytes reverse bytes Example reverseBytes 0x12345678 0x78563412 Legal ops int reverseBytes int x C Assume x and y are of type int For each expression below give values for x and y which make the expression false or write none if the expression is always true x y 0 x x 1 31 0x1 x x x 31 x 31 0 x 31 1 0 x y 1 Page 5 of 13 Problem 3 13 points Floats Consider a 6 bit floating point data type with 3 exponent bits and 3 fraction bits there is no sign bit so the data type can only represent positive numbers Assume that this data type uses the conventions presented in class including representations on NaN infinity and denormalized values A What is the bias B What is the largest value other than infinity that can be represented C What is the smallest value other than zero that can be represented D Fill in the following table Use round to even If a number is too big to represent use the representation of infinity and if it is too small to represent use the representation of 0 Value should be written in decimal Bits 011 000 Value 1 17 110 001 9 1 2 Page 6 of 13 Bits Value 5 111 010 3 32 8 1 2 Problem 4 11 points Structs Consider the following struct typedef struct char a 3 short b 3 double c long double d int e int f JBOB A Show how the struct above would appear on a 64 bit x86 64 Linux machine Label the bytes that belong to the various fields with their names and clearly mark the end of the struct Use x s to indicate bytes that are allocated in the struct but are not used A long double is 16 bytes long Page 7 of 13 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 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 8 of 13 Problem 5 20 points Assembly C translation Given the x86 assembly dump please fill in the blank lines for the function in the provided C code int lolwut char s int i n n 0 for i 0 i if return 1 n return 080483a4 lolwut 80483a4 55 80483a5 89 e5 80483a7 53 80483a8 8b 5d 08 80483ab 0f b6 0b 80483ae ba 00 00 80483b3 84 c9 80483b5 74 31 80483b7 8d 41 d0 80483ba ba 00 00 80483bf 3c 09 80483c1 76 0c 80483c3 eb 1e 80483c5 83 c3 01 80483c8 8d 41 d0 80483cb 3c 09 80483cd 77 14 80483cf 8d 14 92 80483d2 0f be c1 80483d5 8d 54 50 80483d9 0f b6 4b 80483dd 84 c9 80483df 75 e4 80483e1 eb 05 80483e3 ba ff ff 80483e8 89 d0 80483ea 5b 80483eb 5d 80483ec c3 00 00 00 00 d0 01 ff ff push mov push mov movzbl mov test je lea mov cmp jbe jmp add lea cmp ja lea movsbl lea movzbl test jne jmp mov mov pop pop ret ebp esp ebp …
View Full Document