• edited by
1,852 views
2 2 votes

Any one please explain the concept of without spilling

The following program uses six temporary variables $p, q, f, s, t$ and $u$. The code is :
\[
\begin{array}{l}
p=6 \\
q=7 \\
t=p * q \\
s=t+p \\
u=8 \\
u=s * p \\
s=p+u \\
r=r * q \\
t=t+p \\
\text { return } t
\end{array}
\]

Assuming that all operations take their operands from registers. What is the minimum number of registers needed to execute this program without spilling?

  1. 4
  2. $\vee 5$
  3. 6
  4. 3

1 Answer

Best answer
8 8 votes

The operation of moving a variable from a register to memory is called spilling

So we will have to allocate only registers we can't store the result in memory

p=6  => lets save value of p in register R1

q=7  => since we need value of p in future instructions we cant save it in R1, so let us use R2 for q

t=p*q => now both p and q are used in future instructions, so we will have to store t in R3

s=t*p => p, q and t, all 3 are being used in future instructions so we will have to store s in R4

u=8  =>  p, q, t and s all 4 are being used in future instructions so we will have to store u in R5

u=s*p  => no need of extra register. The operation is being performed on u that is R5

s=p+u  => since we are updating value of s, again we dont need extra register this will be done in R4

r=r*q  => now only t and p are being used in future instruction so we can store r in any of R2,R4 or R5. So no need of extra register

t=t+p  => since we are updating value of t, again we dont need extra register this will be done in R3

Hence we need only 5 registers R1, R2, R3, R4 and R5

Hence answer should be 5

• selected by
Position:
Show:

Related questions

2 2 votes
1 1 answer
1.2k
1.2k views
Balaji Jegan asked Jan 20, 2018
1,214 views
Please answer this!Consider the basic block given below:\[\begin{array}{l}b=b+c \\d=b+d \\b=b-d \\e=d+b\end{array}\]The minimum number of nodes and edges present in the D...
1 1 vote
0 0 answers
861
861 views
__ asked Sep 2, 2016
861 views
dag
Here is a sequence of twelve array assignments and references:r = a[i]s = a[j]t = a[i]a[j] = bu = a[i]v = a[j]a[j] = cw = a[i]x = a[j]y = a[i]z = a[j]a[j] = bConstruct th...
0 0 votes
3 answers 3 answers
2.8k
2.8k views
radha gogia asked Dec 9, 2015
2,794 views
In this one I am unable to follow in the above node marked as "-" ,it has two edges one upward and one downward for "+" node so then how to proceed with this ?Consider th...
1 1 vote
1 1 answer
4.6k
4.6k views
Vikrant Singh asked Feb 1, 2015
4,613 views
The identification of common sub-expression and replacement of run-time computations by compile-time computations islocal optimizationconstant folding3 loop optimization4...