




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





5 problems, 8 pages Final Exam 29 April 2008
Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate the pages of the exam. For maximum credit, show your work. Good Luck!
Your Name ( please print ) ________________________________________________
D total
E 30 25 30 35 25 145
5 problems, 8 pages Final Exam 29 April 2008
Problem 1 (5 parts, 30 points) Compiler Optimization
Consider the following program fragment. a = f(50); if (a < 0) { b = g(0); if (b > 100) e = h(a, b); else e = 0; a = e * a; } else { g = g(1); h = g * 4; a = h + g + a; } printf(“answer: %d\n”, a);
Part A (5 points) The control flow graph for this fragment is shown below. Fill in the definitions and uses of the variables (e.g., “def x” and “use w”) in the basic blocks of the graph.
Part B (7 points) Identify the webs (of def-use chains) in the control flow graph by drawing a region for each variable and labeling each web S 1 , S 2 , etc.
5 problems, 8 pages Final Exam 29 April 2008
Problem 2 (1 part, 25 points) Hash Tables and Heap
Consider an open hash table composed of a four-bucket table, with each bucket containing a variable length list. Each list entry has three slots corresponding to the three word groupings in the entries section. The hash function is key mod four. Inserted entries are appended to the end of a bucket list. Deallocated entries are maintained on a LIFO free list. When the free list is empty, new entry objects are allocated from heap memory. Accesses are listed as . Simulate the access list below and draw the ending state. Assume the hash table is initially empty, the heap pointer is initially 5016 and the free pointer is initially
Heap Pointer
(^5016) Free List
Buckets
5000 5004 5008 5012
Entries
5016 5040 5066 5090
Hash Table Access Trace
1 insert 4007 111 5 insert 4007 555 2 insert 4001 222 6 remove 4001 n/a 3 insert 4003 333 7 remove 4007 n/a 4 insert 4005 444 8 insert 4004 666
5 problems, 8 pages Final Exam 29 April 2008
Problem 3 (3 parts, 30 points) Crypto Baseline
Part A (10 points) The crypto program decodes a coded file using the EncodeStream function with an inverse dictionary. Complete the line below that creates this dictionary.
void DecodeStream(char *Dictionary) { int I; char InverseDictionary[26]; void EncodeStream(char *); for (I = 0; I < 26; I++)
EncodeStream(InverseDictionary); }
Part B (10 points) In the edge detection program, the byte array InFrame provides the R, G, and B bytes for each pixel in the Height by Width image. The pixel index I points to a position within the image array.
Write code that checks if the current position I has a north neighbor i.e., it is not in the first row.
if ( ){
Write code that checks if the current position I has an east neighbor i.e., it is not in the last column.
if ( ){
Part C (10 points)
Explain the difference between int People[100]; and extern int People[100];.
Regarding implementation, explain the differences between an array and a struct.
In a makefile, what does the line beginning with .c.o: express?
5 problems, 8 pages Final Exam 29 April 2008
Problem 5 (3 parts, 25 points) Reverse Compilation
Part A (15 points) You’re a computer engineer at MicroSoftServe, a Seattle-based company selling trendy $5 miniature ice cream cones. Unfortunately during a recent power failure, a 200 gallon vat of TripleCaf Espresso Cream™ melted, shorting out the company’s file server. Only the MIPS assembly code could be salvaged. For the MIPS fragment below, write C code that best matches the behavior. Fortunately, labels are included in the comments so be sure to use them. You do not need to declare In, Out, and Ptr. For full credit, write the high level C version; do not transliterate.
Label Instruction Comment L1: add $2, $0, $0 # $2 is Out lw $1, 0($4) # $1 is In, $4 is Ptr L2: beq $1, $0, L andi $3, $1, 1 add $2, $2, $ srl $1, $1, 1 j L L3: sw $2, 4($4) jr $
Part B (5 points) Where does an exception (interrupt) handler obtain storage? What impact does this have on the access functions for this storage?
Part C (5 points) Explain the most common method to implement task priorities in a preemptive multitasking environment? For example, suppose Task A has twice the priority of Task B.
5 problems, 8 pages Final Exam 29 April 2008
MIPS Instruction Set (core) instruction example meaning arithmetic add add $1,$2,$3 $1 = $2 + $ subtract sub $1,$2,$3 $1 = $2 - $ add immediate addi $1,$2,100 $1 = $2 + 100 add unsigned addu $1,$2,$3 $1 = $2 + $ subtract unsigned subu $1,$2,$3 $1 = $2 - $ add immediate unsigned addiu $1,$2,100 $1 = $2 + 100 set if less than slt $1, $2, $3 if ($2 < $3), $1 = 1 else $1 = 0 set if less than immediate slti $1, $2, 100 if ($2 < 100), $1 = 1 else $1 = 0 set if less than unsigned sltu $1, $2, $3 if ($2 < $3), $1 = 1 else $1 = 0 set if < immediate unsigned sltui $1, $2, 100 if ($2 < 100), $1 = 1 else $1 = 0 multiply mult $2,$3 Hi, Lo = $2 * $3, 64-bit signed product multiply unsigned multu $2,$3 Hi, Lo = $2 * $3, 64-bit unsigned product divide div $2,$3 Lo = $2 / $3, Hi = $2 mod $ divide unsigned divu $2,$3 Lo = $2 / $3, Hi = $2 mod $3, unsigned transfer move from Hi mfhi $1 $1 = Hi move from Lo mflo $1 $1 = Lo load upper immediate lui $1,100 (^) $1 = 100 x 2 16 logic and and $1,$2,$3 $1 = $2 & $ or or $1,$2,$3 $1 = $2 | $ and immediate andi $1,$2,100 $1 = $2 & 100 or immediate ori $1,$2,100 $1 = $2 | 100 nor nor $1,$2,$3 $1 = not($2 | $3) xor xor $1, $2, $3 (^) $1 = $2 ⊕ $ xor immediate xori $1, $2, 255 (^) $1 = $2 ⊕ 255 shift shift left logical sll $1,$2,5 $1 = $2 << 5 (logical) shift left logical variable sllv $1,$2,$3 $1 = $2 << $3 (logical), variable shift amt shift right logical srl $1,$2,5 $1 = $2 >> 5 (logical) shift right logical variable srlv $1,$2,$3 $1 = $2 >> $3 (logical), variable shift amt shift right arithmetic sra $1,$2,5 $1 = $2 >> 5 (arithmetic) shift right arithmetic variable srav $1,$2,$3 $1 = $2 >> $3 (arithmetic), variable shift amt memory load word lw $1, 1000($2) $1 = memory [$2+1000] store word sw $1, 1000($2) memory [$2+1000] = $ load byte lb $1, 1002($2) $1 = memory[$2+1002] in least sig. byte load byte unsigned lbu $1, 1002($2) $1 = memory[$2+1002] in least sig. byte store byte sb $1, 1002($2) memory[$2+1002] = $1 (byte modified only) branch branch if equal beq $1,$2,100 if ($1 = $2), PC = PC + 4 + (1004) branch if not equal bne $1,$2,100 (^) if ($1 ≠ $2), PC = PC + 4 + (1004) jump jump j 10000 PC = 10000* jump register jr $31 PC = $ jump and link jal 10000 $31 = PC + 4; PC = 10000*