The following code segment is executed on a processor which…

Cao
0

The following code segment is executed on a processor which allows only register operands in its instructions. Each instruction can have atmost two source operands and one destination operand. Assume that all variables are dead after this code segment.
c = a + b;
d = c * a;
e = c + a;
x = c *c;
if (x > a) {
y = a * a;
}
else {
d = d * d;
e = e * e;
}
Suppose the instruction set architecture of the processor has only tw registers. The
compiler optimIzatIOn IS code motion, which moves statements from one place to another preservIng correctness. what IS the minimum number of spills to memory
(A) 0 (B) 1 (C) 2 (D) 3

Ravi Garg edited question
    0
    Chueh Goon Moon (anonymous)

    ans is 1 .plz any one can explain??

    Chueh Goon Moon answered
      0
      Hitesh Dholaria (anonymous)

      Memory spill means when you require more registers (during register allocation) than available ones, then you have to store the contents of some registers to main memory to cope with limited registers and later on it can be restored. Here, we are restricted to use only 2 registers. Try to assign available registers to unique variables in a given source code. If you find that 2 registers aren’t enough at any point, then we definitely require a memory spill.

      Hitesh Dholaria answered
        0
        Hitesh Dholaria (anonymous)

        If we use code motion as an optimization technique, then we could allocate 2 registers to all the statements except very first one, which must be allocated 3 registers and hence 1 memory spill.

        Hitesh Dholaria answered
          Add image to editor add image from link

          Question stats

          • Active
          • Views373 times
          • Answers3 answers
          • Followers1 follower
          Question and answer is powered by AnsPress