+1 vote
314 views

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  ________

| 314 views
0
0
Akash what these command execute.
0
@Anu007 sir ,I didn't get u!!
0
+2
Temp : 5

Total: 7
0
0

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
by Active (2k points)
selected by
0
I think code optimization not part of syllabus.
0

Are you sure about the no. of temp variables being 5?  because acc. to them it's 4.
+2
Yes I am sure, and you can check more  similar kinds of questions which already asked in previous year gate paper.
+1
0

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.

by Boss (10.9k points)
+1
answer is wrong.. it will be $5,7$ below given answer is correct indeed .

Also the link/reference you are giving are completely different from the qstn asked .
0

Here we are asked the minimum number of temporary variables.

In the reference that I have provided, it is not completely different.

There we need to design a DAG.

First we have done Code optimization , then designed it.

Now,

You can check code optimization is not possible.

I think for answering such question because minimum number is asked , we should do code optimization

0

https://gateoverflow.in/39675/gate-2016-1-19

Here, in one of the answers , Someone even made a DAG and then counted the

#internal nodes = # temporary variables used,

If we also follow the same approach then my answer is correct.

+1 vote