The least number of temporary variables required : GATE 2015 - Paper 1

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 _________.

Answer

Static Single Assignment or SSA form requires that each variable is assigned exactly once. Therefore, to calculate the given expression, the three address code will be something like following:

t1 := r / 3      (∴ t1 holds r/3)
t2 := q + t1     (∴ t2 holds q + r/3)
t3 := t2 + s     (∴ t3 holds q + r/3 + s)
t4 := t * 5      (∴ t4 holds t*5)
t5 := t3 − t4    (∴ t5 holds q + r/3 + s − t*5)
t6 := u * v      (∴ t6 holds u*v)
t7 := t6 / w     (∴ t7 holds u*v/w)
t8 := t5 + t7    (∴ t8 holds q + r/3 + s − t*5 + u*v/w)

Therefore, total 8 temporary variables are required to create the three-address code in SSA form for the given expression.

0Comment