Andrew login ID:Full Name:Recitation Section:CS 15-213, Fall 2008Final ExamFriday. December 12, 2008Instructions:• Make sure that your exam is not missing any sheets, then write your full name, Andrew login ID, andrecitation section (A–H) on the front.• The exam has a maximum score of 106 points.• This exam is OPEN BOOK. You may use any books or notes you like. No calculators or otherelectronic devices are allowed.1 (18):2 (12):3 (10):4 (8):5 (6):6 (7):7 (8):8 (12):9 (8):10 (8):11 (9):Total (106):Page 1 of 21Problem 1. (18 points):For the following questions, indicate whether each of the statements following them is true or false.1. The register rax currently has value 0. Which of the following statements are true?T/F: Executing movq (%rax), %rcx will cause a segmentation fault.T/F: Executing leaq (%rax), %rcx will cause a segmentation fault.T/F: Executing movq %rax, %rcx will cause a segmentation fault.T/F: Executing addq 8, %rsp will increase the stack allocation by 8 bytes.2. After a process calls fork(), which of the following are shared by it and the new child process? (By“shared,” we mean that an update by one process could affect the behavior of the other.)T/F: All file table entries corresponding to files open in the parent before the call to fork().T/F: New file table entries corresponding to files open()’d by the parent after the fork().T/F: New file table entries corresponding to files open()’d by the child after the fork().T/F: All of virtual memory.T/F: The stack.T/F: All register contents.T/F: All sockets with connections established before the fork().3. Consider the following global variable declaration:char str[80];Which of the following outcomes should be of significant concern if you write a program that callsgets(str)?T/F: There could be a stack overflow leading to execution of malicious code.T/F: There could be a buffer overflow that modifies other global variables.T/F: There could be a SEGFAULT.T/F: You might get a bad score if you did this for your 15-213 lab.Page 2 of 214. Consider the following structure definition:struct data {short things[3];unsigned int doodad;char stuff[8];}Which of the following holds for an x86-64 machine:T/F:The size of struct data is 18.T/F: The size of struct data is 20.T/F: The size of struct data is 24.T/F: Network code should use htons() for each entry in things that is sent to anothercomputer.T/F: Network code should use htons() for data in stuff that is sent to another computer.5. When you run two programs on the same Linux machine, why do you not have to worry about themusing the same physical memory?T/F: The programmers knew to avoid using the same addresses and were careful not to do so.T/F: The virtual addresses used by the running programs are translated to non-overlapping phys-ical addresses.T/F: Only one program really runs at a time, and the physical memory is saved/restored as partof each context switch.6. Suppose we compile and run the following code on a processor where integer multiply has a 10 clockcycle latency and a 2 clock cycle issue time. That is, although a single product computation requires10 clock cycles, the multiplier can start a new computation every 2 clock cycles.int prod = 1;for (i = 0; i < n; i+= 2) {prod = prod*a[i]*a[i+1]; // Line P}Which of the following statements hold for this code:T/F:It will properly compute the product for any array a of length n.T/F:It will have a CPE of 10.T/F: It will have a CPE of 2.T/F: Changing Line P to be (a[i]*a[i+1]) will change the CPE.T/F:Changing Line P to be (a[i]*a[i+1]) could change the computed result.Page 3 of 21Problem 2. (12 points):We are running programs on a machine where values of type int have a 32-bit two’s-complement represen-tation, and values of type long have a 64-bit two’s complement representation. Right shifts are performedarithmetically. Values of type double use the 64-bit IEEE format.We generate arbitrary integer values x and y, and convert them to values of type long and double asfollows:/*Create some arbitrary values*/int x = random();int y = random();/*Convert to long*/long lx = (long) x;long ly = (long) y;/*Convert to double*/double dx = (double) x;double dy = (double) y;For each of the following C expressions, you are to indicate whether or not the expression always yields 1.If it can yield 0, give values for the arguments that make the expression evaluate to 0.Hint: Note that some properties may hold for dx and dy that do not hold for arbitrary double-precisionfloating-point numbers, and similarly lx and ly are not arbitrary long’s.Expression Always 1? Arguments (if could yield 0)-˜x == x+1x+2*(x+x)+3*x == x<<3x>>1 == x/2lx*y == x*lyx + y == lx + lyly == 0 || (lx*ly/ly == lx)dx + dy == (double) (x+y)(x > y) == (dx > dy)Page 4 of 21Problem 3. (10 points):Consider the following x86 64 assembly code:# On entry, %edi = val, %rsi = Kfunc:pushq %r12movl %edi, %r12dpushq %rbpmovq %rsi, %rbppushq %rbxxorl %ebx, %ebxjmp .L8.L4:addl $1, %ebxaddq $8, %rbpcmpl $15213, %ebxje .L12.L8:cmpq $0, (%rbp)js .L4movl $8, %edicall malloctestq %rax, %raxmovq %rax, %rcxje .L5testl %r12d, %r12d# Move with sign extendmovslq %ebx,%rdxje .L13.L7:movq %rdx, (%rax).L5:popq %rbxpopq %rbpmovq %rcx, %raxpopq %r12ret.L13:movq (%rbp), %rdxjmp .L7.L12:popq %rbxxorl %ecx, %ecxpopq %rbpmovq %rcx, %raxpopq %r12retPage 5 of 21Fill in the blanks of the corresponding C function:________*func(int val, ________ K) {int i;_______ j;for (i = 0; i < 15213; i++)if ( __________________ ) {j = ________________________ ;if ( __________________ )*j = _____________________ ;return j;}return NULL;}Page 6 of 21Problem 4. (8 points):The problem requires understanding how C code accessing structures, unions, and arrays is compiled. As-sume the x86-64 conventions for data sizes and alignments.#include "def.h"typedef struct {short x[A][5]; /*Unknown constant A*/double y;float f;double d;} str;typedef union{double t ;str S;int array[A*5];} uni;void setVal(str*p, uni*u) {double val = p -> y;u -> t = val;}You do not have a copy of the file def.h, in which constants A and B are defined, but you have the followingx86-64 assembly code for the function setVal:setVal:# rdi = p, rsi = umovq 72(%rdi),%raxmovq %rax, (%rsi)retBased on this code, determine the values of the two constants and the size of the union:A = ________________Size of str = ________________ bytesSize of uni = _______________ bytesPage 7 of 21Problem 5. (6 points):Consider a system with 24 GB of physical
View Full Document