- Consider the arithmetic expression
u * (v - w) + x / y
and a register machine with instructions of the form
LD reg, src
ST dst, reg
OP reg1, reg2, reg3 // the registers need not be distinct
- Draw an abstract syntax tree for the expression and label the nodes with Ershov numbers.
- Generate machine code for the expression on a two-register machine
minimizing the number of spills.
- Consider the following sequence of three-address code:
x = 0
i = 0
L: t1 = i * 4
t2 = a[t1]
t3 = i * 4
t4 = b[t3]
t5 = t2 * t4
x = x + t5
i = i + 1
if i < n goto L
- Draw a flow graph for this three-address code.
- Optimize this code by eliminating common subexpressions,
performing reduction in strength on induction variables,
and eliminating all the induction variables that you can.
State what transformations you are using at each optimization step.
- Consider the lambda-calculus expression
(λu. (λx. u) u) ((λy. y) (λw. (λv.v) w) ).
- Draw a parse tree for this expression.
- Identify all redexes in this expression.
- Evaluate this expression using normal order evaluation.
- Evaluate this expression using applicative order evaluation.
- Evaluate the lambda-calculus expression
(λx.(λy.(x(λx.xy))))y
. What order of
evaluation did you use? Explain all the steps you used in the evaluation.