{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

exam2-key - ECE 468 Midterm 2 November 4 2010 Name Purdue...

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

View Full Document Right Arrow Icon
ECE 468 — Midterm 2 November 4, 2010 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 30 2 20 3 15 4 35 Total 100
Background image of page 1

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

View Full Document Right Arrow Icon
Part 1: Semantic actions and functions (30 pts) 1) Explain when pass-by-value will produce the same results as pass-by- reference (2 pts): They will produce the same results if the arguments are not modified inside the function. 2) a) Give one reason that caller-saves is better than callee-saves (2 points). b) Give one reason that callee-saves is better than caller-saves (2 points). Callee-saves > Caller-saves: less code to generate to save the registers (only at function header) Caller-saves > Callee-saves: easier to generate code to restore registers (don ʼ t have to look for all return points) 3) Draw the AST that would be generated for the expression x := y + z * w 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. (14 pts) := x + y * z w Code: Temp: x Type: L-value Code: Temp: z Type: L-value Code: Temp: w Type: L-value Code: Temp: y Type: L-value Code: LD z, t1 LD w, t2 MUL t1, t2, t3 Temp: t3 Type: R-value Code: LD y, t4 LD z, t1 LD w, t2 MUL t1, t2, t3 ADD t4, t3, t5 Temp: t5 Type: R-value Code: LD y, t4 LD z, t1 LD w, t2 MUL t1, t2, t3 ADD t4, t3, t5 ST t5, x Temp: Type:
Background image of page 2
3) Here is a partial stack of a method being executed (the stack grows down).
Background image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}