Exam 1, Version 2 (day listed as "Thurs") Solutions 15-213/18-243 Fall 2009 ********* Problem 1 ********* Part A. Nan 0 -2^-149 Part B. True False True True (!ux is a signed int) ********* Problem 2 ********* A. aaaaaaaaaxb1b2b3 ccccxxxxdddddddd exffgggghhhhxxxx<-end B. ddddddddccccgggg hhhhb1b2b3ffaaaa aaaaaexx<-end C. 10 D. 2 ********* Problem 3 ********* Format A Format B Bits Value Bits Value 0111 0000 1 011111 00 1 1110 1100 224 100110 11 224 0101 1011 27/64 011101 11 28/64 1111 0000 inf 111101 10 3*2^29 0000 0011 3/1024 010110 10 3/1024 ********* Problem 4 ********* int foo (unsigned int a) { int b = 0; switch (a + 1) { case 0: b = a >> 1; __________; case 1: b = ~b; ______; case 2: b = -b; break; case 3: b = a; _____; case 4: b = b ^ a; break; // optional break (falls through either way) } return b; } 4. a == -1 => Tmin a == 0 => 6 a == 1 => -5 a == 2 => 0 a == 3 => 6 o.w. => 5 ********* Problem 5 ********* odin c dva d tri e chetyre a ********* Problem 6 ********* a) ecx = *rax b) eax = *(rax + 4) c) call, jmp, ret d) x86_64 32-bit has les registers than 64-bit mode, so local variables would need to be stored on the stack. Stack accessing takes extra instructions and extra time. e) int mystery (int * array, size_t size, int e){ int a; int i; int end = len - 1; int temp; do { a = 0; for (i = 0; i < end; i++) { if (array[i] > array[i + 1]) { /* you should write the body of the if statement below */ temp = array[i]; array[i] = array[i + 1]; array[i + 1] = temp; a = 1; } } end--; } while (a != 0); } f) Bubble Sort ********* Problem 7 ********* 1. d 2. d 3. b 4. d 5. a 6. c 7. d 8. a 9. b ********* Problem 8 ********* H = 31 J = 12