Intermediate Code Generation: GATE CS Previous Year Questions

Intermediate Code Generation · Compiler Design

32 questions · asked in 16 of 27 years (2000–2026)

MCQ 26 · MSQ 1 · NAT 51-mark 13 · 2-mark 19

2000Questions per year2026

Questions 26–30 of 32

Q26GATE 20132 marksMCQ−0.67 if wrong
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;
} 
What is the minimum number of registers needed in the instruction set architecture of the processor to compile this code segment without any spill to memory? Do not apply any optimization other than optimizing register allocation

Q27GATE 20132 marksMCQ−0.67 if wrong
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 two registers. The only allowed compiler optimization is code motion, which moves statements from one place to another while preserving correctness. What is the minimum number of spills to memory in the compiled code?

Q28GATE 20112 marksMCQ−0.67 if wrong
Consider evaluating the following expression tree on a machine with load-store architecture in which memory can be accessed only through load and store instructions. The variables a, b, c, d and e are initially stored in memory. The binary operators used in this expression tree can be evaluated by the machine only when the operands are in registers. The instructions produce result only in a register. If no intermediate results can be stored in memory, what is the minimum number of registers needed to evaluate this expression?
+--abe+cd

Q29GATE 20102 marksMCQ−0.67 if wrong
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 this program without spilling?

Q30GATE 20081 markMCQ−0.33 if wrong
Some code optimizations are carried out on the intermediate code because

Keep practising

Topics in Compiler Design

All CS topics ›