Andrew login ID:Full Name:Section:15-213/18-243, Fall 2010Exam 1 - Version ATuesday, September 28, 2010Instructions:• 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, although you may use a single 8 1/2 x 11 sheet of paper withyour 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 indicateyour 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 13Problem 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 1011 12 13 14 15 16 17 18 19 201. 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) -241, 15(b) -15, 241(c) -241, 241(d) -15, 152. In two’s compliment, what is −T Min?(a) T min(b) T max(c) 0(d) −13. Let int x = −31/8 and int y = −31 >> 3. What are the values of x and y?(a) x = −3, y = −3(b) x = −4, y = −4(c) x = −3, y = −4(d) x = −4, y = −34. 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 thenumber 1 respectively?(a) 1 and 2(b) 2 and 2(c) 2 and 1(d) 1 and 1Page 2 of 136. Consider the following program. Assuming the user correctly types an integer into stdin, what willthe 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) 0(b) T Min(c) Depends on the integer read from stdin(d) Segmentation fault7. By default, on Intel x86, the stack(a) Is located at the bottom of memory.(b) Grows down towards smaller addresses(c) Grows up towards larger addresses(d) Is located in the heap8. Which of the following registers stores the return value of functions in Intel x8664?(a) %rax(b) %rcx(c) %rdx(d) %rip(e) %cr39. The leave instruction is effectively the same as which of the following:(a) mov %ebp, %esppop %ebp(b) pop %eip(c) mov %esp, %ebppop %esp(d) ret10. Arguments to a function, in Intel IA32 assembly, are passed via(a) The stack(b) Registers(c) Physical memory(d) The .text section(e) A combination of the stack and registers.Page 3 of 1311. A buffer overflow attack can only be executed against programs that use the gets function.(a) True(b) False12. Intel x8664 systems are(a) Little endian(b) Big endian(c) Have no endianess(d) Depend on the operating system13. Please fill in the return value for the following function calls on both an Intel IA32 and Intel x8664system:Function Intel IA32 Intel x86 64sizeof(char)sizeof(int)sizeof(void*)sizeof(int*)14. Select the two’s complement negation of the following binary value: 0000101101:(a) 1111010011(b) 1111010010(c) 1000101101(d) 111101101115. Which line of C-code will perform the same operation as leal 0x10(%rax,%rcx,4),%rax?(a) rax = 16 + rax + 4*rcx(b) rax =*(16 + rax + 4*rcx)(c) rax = 16 +*(rax + 4*rcx)(d)*(16 + rcx + 4*rax) = rax(e) rax = 16 + 4*rax + rcx16. Which line of Intel x86-64 assembly will perform the same operation as rcx = ((int*)rax)[rcx]?(a) mov (%rax,%rcx,4),%rcx(b) lea (%rax,%rcx,4),%rcx(c) lea (%rax,4,%rcx),%rcx(d) mov (%rax,4,%rcx),%rcx17. If a is of type (int) and b is of type (unsigned int), then (a < b) will perform(a) An unsigned comparison.(b) A signed comparison.(c) A segmentation fault.(d) A compiler error.Page 4 of 1318. 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),%ebpPage 5 of 13Problem 2. (10 points):Floating point encoding. Consider the following 5-bit floating point representation based on the IEEEfloating 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 afterbiasing, and M is the significand value. The fraction bits encode the significand value M using either adenormalized (exponent field 0) or a normalized representation (exponent field nonzero). The exponent Eis given by E = 1 − Bias for denormalized values and E = e − Bias for normalized values, where e is thevalue 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. Inaddition, you should give the rounded value of the encoded floating point number. To get credit, you mustgive these as whole numbers (e.g., 17) or as fractions in reduced form (e.g., 3/4). Any rounding of thesignificand is based on round-to-even, which rounds an unrepresentable value that lies halfway betweentwo representable values to the nearest even representable value.Value Floating Point Bits Rounded value9/32 001 00 1/4112111/87/32Page 6 of 13Problem 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 %esi,%rsimovslq %edi,%rdimovq %rsi, %raxsalq $4, %raxsubq %rsi, %raxaddq %rdi, %raxleaq (%rdi,%rdi,2), %rdiaddq %rsi, %rdimovl array1(,%rdi,4), %edxmovl %edx, array2(,%rax,4)movl $1, %eaxretWhat are the values of H and J?H =J =Page 7 of 13Problem 4. (6 points):Structure alignment. Consider the following C struct:struct {char a, b;short c;long d;int*e;char f;float g;} foo;1. Show how the struct above would appear on a 32 bit
View Full Document