retagged by
1,399 views

1 Answer

Best answer
8 votes
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

Related questions

2 votes
2 votes
1 answer
1
0 votes
0 votes
3 answers
3
radha gogia asked Dec 9, 2015
1,375 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 ?