edited by
698 views
0 votes
0 votes

Given problem and answer :
 

 

I am getting 3 minimum registers as answer, can anyone verify?

here's how I am getting 3 :

T1 = r
T2 = s
T1 = T1 * T2
T2 = t
T3 = u
T2 = T2 – T3
T1 = T1 * T2       // T2 and T3 are free now

 

T2 = p
T3 = q
T2 = T2 * T3
T3 = t
T2 = T2 + T3

 
T2 = T1 + T2

edited by

2 Answers

1 votes
1 votes

I am getting 4 min number of registers .

Given expression : ((p X q) + t) + ((t – u) X (r X s))

Let r1, r2, r3, r4 as registers 

r1 = p

r2 = q

r1 = p X q

r2 = t

r1 = r1 + r2

r3 = u

r2 = r2 – r3

r3 = r

r4 = s

r3 = r3 X r4

r2 = r2 X r3

r1= r1 + r2

 

0 votes
0 votes
Here it is given that no spilling can be done so we can’t the result in the memory.

now i am picking new register only when it requires.

we want to multiply p and q both are in memory so we load them both in register from memory.

Load R1,p  (R1← p)

Load R2,q (R2-<q)

mul R1,R1,R2(R1← R1*R2)

now we need to add these value with t.

now t is in memory so we need to bring it back and we have R2 empty.

Load R2,t (R2← t)

now just add them both.

add R1,R1,R2 (R1← R1+R2)

now i need the value of u but R1 store the value of the sum and R2 store t which need next operation so we need to assign another register R3 for u.

load R3,u (R3<-u)

sub R3,R2,R3 (R3← R2-R3)

now we only have R2 left to store the value of r and we need another register for s as R1,R2 store the result of our calculation which needed in future.

Load R2,r (R2<-r)

Load R4,s (R4<-s)

mul R4,R4,R2(R4<-R4*R2)

mul R3,R3,R4(R3<-R3*R4)

add R1,R1,R3(R1-<R1+R3)

Hence answer is 4.

Related questions

0 votes
0 votes
0 answers
3
nbhatt asked Jan 12, 2023
440 views
8 votes
8 votes
1 answer
4
Kapil asked Nov 2, 2016
3,010 views
How to draw register allocation interference graph ?Can anyone explain this along with " What is a live variable "?Explain with the example given below ?a = 1 b = 10 c = ...