1,758 views
1 votes
1 votes
Consider the following code segment:

c=b+a

e=c-a

f=c*e

h=c+a

i=h+f

The minimum number of  $\color{blue} {total}$ and $\color{blue} {temporary }$ variable required to convert the above code segment to static single assignment form are  ________

8 Answers

Best answer
4 votes
4 votes
c(temp 1) = a ( variable )+ b ( variable )

e(temp 2) = c - a

f(temp 3) = c * e

h(temp 4) = c + a

i(temp 5) = h + f

So temp = 5

Total = temporary + variable

Total = 7
selected by
2 votes
2 votes

c=b+a                              ;  t1= b + a

e=c-a     , e=b+a -a = b => e=b

f=c*e                                ; t2=t1*b  // e=b

h=c+a                              ; t3=t1*a

i=h+f                               ; t4=t3+t2

# Temporary Variables = 4

# Total Variables = 4 +2  = 6

Here, we are doing Code optimization.

Ref:https://gateoverflow.in/2068/gate2014-3-34#q2068

1 votes
1 votes
c = b + a

and in next step

e= c-a which is nothing but b+a-a=b

hence no need to assign e as b

instead whenever value of e is required we can conveniently refer to value of e.

c1=b+a

f1=c1*b

h1=c1+a

t1=h1+f1
1 votes
1 votes
There is  a phase in compiler processing called as code optimization either it could be Machine independent or dependent .
So the term minimum here always refer to optimization and that too without losing the crisp of the program i.e correctness of program should be maintained.
here,

$c=b+a$

$e=c-a$ $\color{Red}{\text{(This is redundant)}} \ b+a-a=b$

$f=c \times e$

$h=c+a$

$i=h+f$

Therefore,

$T_1=b+a$

$e=c-a$ $\color{Red}{\text{(Redundant)}} $

$T_2=T_1 \times b$

$T_3=T_1+a$

$T_4=T3+T_2$

Related questions

1 votes
1 votes
0 answers
1
Hemant Parihar asked Jan 19, 2018
1,143 views
Consider the following code segment:c = b + ae = c - af = c * eh = c + ai = h + fThe minimum number of temporary variable required to convert the above code segment to s...
1 votes
1 votes
0 answers
2
AnilGoudar asked Dec 28, 2017
393 views
Convert the following 3 address code to single Static Assignment.a = b + cd = d + a.
9 votes
9 votes
1 answer
3
papesh asked Dec 17, 2016
1,920 views
$x=5$$x=x-3$$\textbf{if } x<3$$\quad y=x*2$$\quad w=y$$\textbf{else}$$\quad y=x-3$$w=x-y$$z=x+y$Give Equivalent SSA.