Andrew login ID Full Name Section 15 213 18 243 Fall 2010 Exam 1 Version A Tuesday September 28 2010 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 although you may use a single 8 1 2 x 11 sheet of paper with your own 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 60 points The problems are of varying difficulty The point value of each problem is indicated Good luck 1 10 2 10 3 6 4 6 5 4 6 10 7 14 TOTAL 60 Page 1 of 13 Problem 1 10 points General systems concepts Write the correct answer for each question in the following table 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 Consider the following code what is the output of the printf int x 0x15213F10 4 char y char x unsigned char z unsigned char x printf d u y z a b c d 241 15 15 241 241 241 15 15 2 In two s compliment what is T M in a b c d T min T max 0 1 3 Let int x 31 8 and int y 31 3 What are the values of x and y a b c d x 3 y x 4 y x 3 y x 4 y 3 4 4 3 4 In C the expression 15213U 1 evaluates to a True 1 b False 0 5 In two s compliment what is the minimum number of bits needed to represent the numbers 1 and the number 1 respectively a b c d 1 and 2 2 and 2 2 and 1 1 and 1 Page 2 of 13 6 Consider the following program Assuming the user correctly types an integer into stdin what will the program output in the end include stdio h int main int x 0 printf Please input an integer scanf d x printf d x 31 a b c d 0 T M in Depends on the integer read from stdin Segmentation fault 7 By default on Intel x86 the stack a b c d Is located at the bottom of memory Grows down towards smaller addresses Grows up towards larger addresses Is located in the heap 8 Which of the following registers stores the return value of functions in Intel x86 64 a b c d e rax rcx rdx rip cr3 9 The leave instruction is effectively the same as which of the following a mov pop b pop c mov pop d ret ebp esp ebp eip esp ebp esp 10 Arguments to a function in Intel IA32 assembly are passed via a b c d e The stack Registers Physical memory The text section A combination of the stack and registers Page 3 of 13 11 A buffer overflow attack can only be executed against programs that use the gets function a True b False 12 Intel x86 64 systems are a b c d Little endian Big endian Have no endianess Depend on the operating system 13 Please fill in the return value for the following function calls on both an Intel IA32 and Intel x86 64 system Function Intel IA32 Intel x86 64 sizeof char sizeof int sizeof void sizeof int 14 Select the two s complement negation of the following binary value 0000101101 a b c d 1111010011 1111010010 1000101101 1111011011 15 Which line of C code will perform the same operation as leal 0x10 rax rcx 4 rax a b c d e rax 16 rax 16 rax 16 16 rcx rax 16 rax 4 rcx rax 4 rcx rax 4 rcx 4 rax rax 4 rax rcx 16 Which line of Intel x86 64 assembly will perform the same operation as rcx int rax rcx a b c d mov lea lea mov rax rcx 4 rcx rax rcx 4 rcx rax 4 rcx rcx rax 4 rcx rcx 17 If a is of type int and b is of type unsigned int then a b will perform a b c d An unsigned comparison A signed comparison A segmentation fault A compiler error Page 4 of 13 18 Denormalized floating point numbers are a Very close to zero small magnitude b Very far from zero large magnitude c Un representable on a number line d Zero 19 What is the difference between an arithmetic and logical right shift a C uses arithmetic right shift Java uses logical right shift b Logical shift works on 32 bit data arithmetic shift works on 64 bit data c They fill in different bits on the left d They are the same 20 Which of the following assembly instructions is invalid in Intel IA32 Assembly a pop eip b pop ebp c mov esp ebp d lea 0x10 esp ebp Page 5 of 13 Problem 2 10 points Floating point encoding Consider the following 5 bit floating point representation based on the IEEE floating point format This format does not have a sign bit it can only represent nonnegative numbers There are k 3 exponent bits The exponent bias is 3 There are n 2 fraction bits Recall that numeric values are encoded as a value of the form V M 2E where E is the exponent after biasing and M is the significand value The fraction bits encode the significand value M using either a denormalized exponent field 0 or a normalized representation exponent field nonzero The exponent E is given by E 1 Bias for denormalized values and E e Bias for normalized values where e is the value of the exponent field exp interpreted as an unsigned number Below you are given some decimal values and your task it to encode them in floating point format In addition you should give the rounded value of the encoded floating point number To get credit you must give these as whole numbers e g 17 or as fractions in reduced form e g 3 4 Any rounding of the significand is based on round to even which rounds an unrepresentable value that lies halfway between two representable values to the nearest even representable value Value Floating Point Bits Rounded value 9 32 001 00 1 4 1 12 11 1 8 7 32 Page 6 of 13 Problem 3 6 points Accessing arrays Consider the C code below where H and J are constants declared with define int array1 H J int array2 J H int copy array int x int y array2 y x array1 x y return 1 Suppose the above C code generates the following x86 64 assembly code On entry edi x esi y copy array movslq movslq movq salq subq addq leaq addq movl movl movl ret esi rsi edi rdi rsi rax 4 rax rsi rax rdi rax rdi rdi 2 rdi …
View Full Document