in Compiler Design
461 views
0 votes
0 votes
What is minimum number of extra registers are required to swap 2 numbers, where 2 numbers are stored in two different registers?
in Compiler Design
by
461 views

3 Comments

0 extra registers.

R1 = R1+R2

R2 = R1-R2

R1 = R1 -R2
0
0
say both registers contains value 8
then will it be swapped?
0
0
Yes

R1 = 8, R2 = 8

R1 = 8+8 = 16

R2 = 16-8 = 8

R1 = 16-8 = 8

swapped. Result will be same. But what we want to achieved is achieved.
2
2

Please log in or register to answer this question.

Related questions