The program below uses six temporary variables a, b, c, d, e, f. a =1 b =10 c = 20 d = a + b e = c + d f = c + e b = c + e e = b + f d = 5 + e return d + f Assuming that all operations take their operands from registers, what is the minimum number of registers needed to execute thi s program without spilling? 

The program below uses six temporary variables a, b, c, d, e, f. a =1 b =10 c = 20 d = a + b e = c + d f = c + e b = c + e e = b + f d = 5 + e return d + f Assuming that all operations take their operands from registers, what is the minimum number of registers needed to execute thi s program without spilling?  Correct Answer 3

Key Points

 A directed acyclic graph is used to 

  • To find the common subexpressions
  • To find the minimum number of registers required to convert the intermediate code into the target assembly language.

[ alt="min reg" src="//storage.googleapis.com/tb-img/production/21/08/min_reg.png" style="width: 259px; height: 457px;">

So above DAG has 3 registers R1, R2, and R3 are required to convert intermediate code into the target assembly language.

Hence the correct answer is 3.

Related Questions