edited by
2,295 views
5 votes
5 votes
Consider following 3 address code
t1 = t+e
t2 = g+a
t3 = t1*t2
t4 = t2+t2
t5 = t4+t3

The minimum number of temporary variables that can be used in equivalent 3-address code of above code is

 

Approach:

t = t+e, g = g+a, t = t*g, g = g+g,t = t+g. Hence 4 temporary variables are needed. Is this right?
edited by

4 Answers

8 votes
8 votes
t1=e+t

t2=g+a

t1=t1+t2

t2=t2+t2

t1=t1+t2
3 votes
3 votes

t = t+e     {t,e     active here}
g = g+a   {t,g,a  active here}  //here register e overwritten by a.

t = t*g     {t,g    active here}
g = g+g   {t, g   active here}
t = t+g    { t      active here}

total 3 register required.

0 votes
0 votes
I think t,e, g, a are actual addresses that are not considered as temporary variables. In my opinion t1 and t2 are temporary variable that we are used in a three adress code. Sir, please suggest me if it is wrong.
0 votes
0 votes
It will require only two temporary variables.

t1 = t + e

t2 = g + a

t1 = t1 * t2

t2 = t2 + t2

t1 = t1 + t2

Related questions

2 votes
2 votes
1 answer
1
Sambhrant Maurya asked Nov 1, 2018
4,300 views
The minimum number of variables required in 3 address code of the given expression are:______a * b * c + d - a + e * f - g + hOrder of precedence: * + - ; with * as lef...
0 votes
0 votes
1 answer
3
thor asked Nov 17, 2016
1,064 views
3 votes
3 votes
1 answer
4
sh!va asked Jun 23, 2016
14,842 views
Three address code invlovesexactly 3 addressesat most 3 addressesat least 3 addressesNo unary opeartors