Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  The program below uses six temporary variable... Start Learning for Free
The program below uses six temporary variables a,b,c,d,e,f.
Assuming that all operations take their operands from registers, what is the minimum number of registers needed to execute this program without spilling?
  • a)
    2
  • b)
    3
  • c)
    4
  • d)
    6
Correct answer is option 'B'. Can you explain this answer?
Verified Answer
The program below uses six temporary variables a,b,c,d,e,f.Assuming th...
Here in these types of compiler questions, idea is "map/assign multiple temporaries to one registers."
here a, b, and c all are having 3 different values so i need atleast 3 registers r1, r2 and r3. a is mapped to r1, b to r2 and c to r3
d = a + b, after this line if u notice 'a' is never present on right hand side, so i can map (register of a which is r1 ) d to r1. e = c + d, after this line 'd' is never present on rhs, so i can map (register of d which is r1 ) e to r1.
at this time mapping is
r1 --- e
r2 --- b
r3 --- c
(at this moment i have registers for e, b and c. if i introduce new variable then i may need different register) now at this point if u see
f = c + e 
b = c + e
these two are essentially doing same thing, after these two line 'b' and 'f' are same so i can skip computing 'f'. and whereever f is present i will replace it with 'b'. (bcoz neither of 'f' and 'b' are changing after these two lines, so value of these will be 'c+e' forever)
(seems like i introduced one more variable f, and register is needed for that, but actually i did not really introduce 'f'. i am skipping computation of 'f') now at second last line "d = 5 + e" here i introduced 'd', i can map it to any of the register r1 or r3, bcoz after this line neither of 'e' or 'c' is required. (value of 'b' is required bcoz i need to return 'd+f', and 'f' is essentially equal to 'b')
finally code becomes
r1 = 1
r2 = 10
r3 = 20
r1 = r1 + r2
r1 = r3 + r1
(skipping 'f' computation) 
r2 = r3 + r1
r2 = r3 + r1
r1 = r2 + r2
r3 = 5 + r1
return r3 + r2
Therefore minimum 3 registers needed.
View all questions of this test
Explore Courses for Computer Science Engineering (CSE) exam

Similar Computer Science Engineering (CSE) Doubts

Top Courses for Computer Science Engineering (CSE)

The program below uses six temporary variables a,b,c,d,e,f.Assuming that all operations take their operands from registers, what is the minimum number of registers needed to execute this program without spilling?a)2b)3c)4d)6Correct answer is option 'B'. Can you explain this answer?
Question Description
The program below uses six temporary variables a,b,c,d,e,f.Assuming that all operations take their operands from registers, what is the minimum number of registers needed to execute this program without spilling?a)2b)3c)4d)6Correct answer is option 'B'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about The program below uses six temporary variables a,b,c,d,e,f.Assuming that all operations take their operands from registers, what is the minimum number of registers needed to execute this program without spilling?a)2b)3c)4d)6Correct answer is option 'B'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for The program below uses six temporary variables a,b,c,d,e,f.Assuming that all operations take their operands from registers, what is the minimum number of registers needed to execute this program without spilling?a)2b)3c)4d)6Correct answer is option 'B'. Can you explain this answer?.
Solutions for The program below uses six temporary variables a,b,c,d,e,f.Assuming that all operations take their operands from registers, what is the minimum number of registers needed to execute this program without spilling?a)2b)3c)4d)6Correct answer is option 'B'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of The program below uses six temporary variables a,b,c,d,e,f.Assuming that all operations take their operands from registers, what is the minimum number of registers needed to execute this program without spilling?a)2b)3c)4d)6Correct answer is option 'B'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of The program below uses six temporary variables a,b,c,d,e,f.Assuming that all operations take their operands from registers, what is the minimum number of registers needed to execute this program without spilling?a)2b)3c)4d)6Correct answer is option 'B'. Can you explain this answer?, a detailed solution for The program below uses six temporary variables a,b,c,d,e,f.Assuming that all operations take their operands from registers, what is the minimum number of registers needed to execute this program without spilling?a)2b)3c)4d)6Correct answer is option 'B'. Can you explain this answer? has been provided alongside types of The program below uses six temporary variables a,b,c,d,e,f.Assuming that all operations take their operands from registers, what is the minimum number of registers needed to execute this program without spilling?a)2b)3c)4d)6Correct answer is option 'B'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice The program below uses six temporary variables a,b,c,d,e,f.Assuming that all operations take their operands from registers, what is the minimum number of registers needed to execute this program without spilling?a)2b)3c)4d)6Correct answer is option 'B'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev