Docsity

ECE 3035 B 1 -2 p.m. Computing Mechanisms Final Exam Spring 2008, Exams of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE 3035 B 1 -2 p.m. Computing Mechanisms Spring 2008
5 problems, 8 pages Final Exam 28 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) ________________________________________________
12345
A
B
C
Dtotal
E
30 25 30 35 25 145
1
pf3
pf4
pf5
pf8

Partial preview of the text

Download ECE 3035 B 1 -2 p.m. Computing Mechanisms Final Exam Spring 2008 and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

5 problems, 8 pages Final Exam 28 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 ) ________________________________________________

A

B

C

D total

E 30 25 30 35 25 145

5 problems, 8 pages Final Exam 28 April 2008

Problem 1 (5 parts, 30 points) Compiler Optimization

Consider the following program fragment. a = f(50); b = g(0); if (a < 0) { if (b > 100) e = h(a, b); else e = 0; b = e * a; } else { g = g(1); h = g * 4; h = h + g; } printf(“answer: %d\n”, b);

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 S1, S 2, etc.

T F

F

T

5 problems, 8 pages Final Exam 28 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

op key value # op key value

1 insert 4006 111 5 insert 4000 555 2 insert 4000 222 6 remove 4006 n/a 3 insert 4002 333 7 remove 4004 n/a 4 insert 4004 444 8 insert 4003 666

5 problems, 8 pages Final Exam 28 April 2008

Problem 3 (3 parts, 30 points) C Baselines

Part A (10 points) The crypto program encodes a ASCII text file into code output using a Dictionary array. Complete the missing lines below. void EncodeStream(char *Dictionary) { int Ch, I; int getchar(); Ch = getchar(); while (Ch != EOF) { if (Ch >= 'A' && Ch <= 'Z')

else if (Ch >= 'a' && Ch <= 'z')

else putchar(Ch); Ch = getchar(); } } Part B (10 points) In the edge detection program, each component is compared to a current Min and Max. Write a C function Compare that compares a pixel value against the current Min and Max. If the value exceeds the min-max range, the appropriate limit is updated. Value, Min, and Max are parameters for this function. Hint: Compare is a void function.

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 28 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) Explain the difference between synchronous and asynchronous exceptions. Give an example of each type.

Part C (5 points) Explain the difference between the IRQ and NMI inputs on most processors. Which input is most often used? Why is the other input required?

5 problems, 8 pages Final Exam 28 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*