The least number of temporary variables required to create a three-address…
2015
The least number of temporary variables required to create a three-address code in static single assignment form for the expression \(q + r / 3 + s – t * 5 + u * v /w\) is _______________.
Attempted by 68 students.
Show answer & explanation
Correct answer: 8
Key idea: each binary operation in the expression requires a distinct temporary in static single assignment form because each result must be assigned exactly once.
Apply operator precedence to group the expression as: q + (r / 3) + s - (t * 5) + ((u * v) / w).
Count the binary operations (each needs one temporary):
r / 3
t * 5
u * v
(u * v) / w
q + (r / 3)
(previous) + s
(previous) - (t * 5)
(previous) + ((u * v) / w)
One convenient three-address code (SSA) ordering that uses one temporary per operation is:
t1 = r / 3
t2 = t * 5
t3 = u * v
t4 = t3 / w
t5 = q + t1
t6 = t5 + s
t7 = t6 - t2
t8 = t7 + t4
Therefore, the least number of temporary variables required is 8.
A video solution is available for this question — log in and enroll to watch it.