573exam2sol - ECE 573 Midterm 2 November 3, 2009 Name: _...

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

View Full Document Right Arrow Icon
ECE 573 — Midterm 2 November 3, 2009 Name: ______________________________________ Purdue email: ______________________________________ Please sign the following: I afFrm 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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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 modifed 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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/19/2012 for the course ECE 468 taught by Professor Test during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 12

573exam2sol - ECE 573 Midterm 2 November 3, 2009 Name: _...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online