Andrew login ID:Full Name:Section:15-213/18-243, Spring 2011Exam 1Thursday, March 3, 2011 (v1)Instructions:• Make sure that your exam is not missing any sheets, then write your Andrew login ID, full name, andsection 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 indicateyour 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 13Problem 1. (12 points):Multiple choice.Write the correct answer for each question in the following table:1 2 3 4 5 6 7 8 9 1011 121. Consider an int*a and an int n. If the value of %ecx is a and the value of %edx is n, which ofthe following assembly snippets best corresponds to the C statement return a[n]?(a) ret (%ecx,%edx,4)(b) leal (%ecx,%edx,4),%eaxret(c) mov (%ecx,%edx,4),%eaxret(d) mov (%ecx,%edx,1),%eaxret2. Which of the following 8 bit floating point numbers (1 sign, 3 exponent, 4 fraction) represent NaN?(a) 1 000 1111(b) 0 111 1111(c) 0 100 0000(d) 1 111 00003. %rsp is 0xdeadbeefdeadd0d0. What is the value in %rsp after the following instruction exe-cutes?pushq %rbx(a) 0xdeadbeefdeadd0d4(b) 0xdeadbeefdeadd0d8(c) 0xdeadbeefdeadd0cc(d) 0xdeadbeefdeadd0c84. How many lines does a direct-mapped cache have in a set?(a) 0(b) 1(c) 2(d) 4Page 2 of 135. 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 d6. Two-dimensional arrays are stored in order, to help with cache performance.(a) column-major(b) row-major(c) diagonal-major(d) Art-major7. 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 above8. 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) = rdx10. What is the C equivalent of mov %rax,%rcx(a) rcx = rax(b) rax = rcx(c) rax =*rcx(d) rcx =*raxPage 3 of 1311. 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• FalsePage 4 of 13Problem 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 mayuse 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 theexpression 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) == 1Page 5 of 13Problem 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 thedata type can only represent positive numbers). Assume that this data type uses the conventions presentedin 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 representa-tion of infinity, and if it is too small to represent, use the representation of 0. Value should be writtenin decimal.Bits Value Bits Value011 000 1 517 111 010110 001 3/329 1/2 8 1/2Page 6 of 13Problem 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 thatbelong to the various fields with their names and clearly mark the end of the struct. Use x’s to indicatebytes that are allocated in the struct but are not used. A long double is 16 bytes long.+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+| | | | | | | | | | | | | | | | |+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--++--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+| | | | | | | | | | | | | | | | |+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--++--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+| | | | | | | | | | | | | | | | |+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--++--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+| | | | | | | | | | | | | | | | |+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+Page 7 of 13B. Rearrange the above fields in foo to conserve the most space in the memory below. Label the bytesthat belong to the various fields with their names and clearly mark the end of the struct. Use hatchmarks 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 13Problem 5. (20 points):Assembly/C translation. Given the x86 assembly dump, please fill in the blank lines for the function in theprovided C code:int lolwut(char*s){int i, n;n = 0;for(i = 0;
View Full Document