{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

573exam2sol

# 573exam2sol - ECE 573 Midterm 2 November 3 2009 Name Purdue...

This preview shows pages 1–5. Sign up to view the full content.

ECE 573 — Midterm 2 November 3, 2009 Name: ______________________________________ Purdue email: ______________________________________ Please sign the following: I affirm that the answers given on this test are mine and mine alone. I did not receive help from any person or material (other than those explicitly allowed). X ___________________________________________ Part Points Score 1 20 2 12 3 40 4 38 5 30 Total 140

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Part 1: Semantic actions and functions (20 pts) 1) Why is it useful to pass arguments as read-only? (2 pts) Read only arguments are not modified by the callee, which means that it is safe to pass them by reference, which can save time as it avoids copying. 2) Draw the AST that would be generated for the expression *(p) + x and for each AST node, show the data object that would be generated. For each data object, show the code that would be generated (if any), the temporary the result will be stored in, and whether the temporary is an R-value or an L-value. (8 pts) + * p x Code: Temp: p Type: L-value Code: LD p, t1 Temp: t1 Type: L-value Code: Temp: x Type: L-value Code: LD p, t1 LD t1, t2 LD x, t3 ADD t2, t3, t4 Temp: t4 Type: R-value
3) Here is a partial stack of a method being executed (the stack grows down). Show the stack after calling int foo(int a, int[] b) . Show the frame pointer, and note how much space each part of the stack occupies (32-bit ints and pointers). Assume that we are using a callee-saves convention, and that the machine has 4 registers (plus FP & SP registers). Assume that there are no nested scopes or local variables in foo. (10 pts) Rest of stack Local variables Return value 4 bytes arg: a 4 bytes arg: b[] (dope vector) 4 bytes caller's frame pointer 4 bytes Saved registers 16 bytes caller's return address 4 bytes FP register

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Part 2: Common subexpression elimination (12 pts) For the next questions, consider the following piece of code: 1: A = B + C; 2: D = A - C; 3: E = B + C; 4: B = C + E; 5: F = A - C; 6: G = B + C; 1) Assume there is no aliasing between variables. For each statement, list which expressions are “available” after the statement executes (6 pts) 1 B+C 2 B+C, A-C 3 B+C, A-C 4 A-C, C+E 5 A-C, C+E 6 A-C, C+E, B+C 2) What does the code look like after performing CSE (when eliminating a redundant expression, replace it with the variable that holds the calculated value of the expression) (3 pts)
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}