Intermediate Code Generation GATE CS PYQ QUIZ

Last Updated :
Discuss
Comments

Question 1

The minimum number of arithmetic operations required to evaluate the polynomial P(X) = X5 + 4X3 + 6X + 5 for a given value of X using only one temporary variable.

  • 6

  • 7

  • 8

  • 9

Question 2

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?

  • 0

  • 1

  • 2

  • 3

Question 3

Consider the same data as above question. 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.

  • 3

  • 4

  • 5

  • 6

Question 4

The least number of temporary variables required to create a three-address code in static single assignment form for the expression q + r/3 + s – t * 5 + u * v/w is

  • 4

  • 8

  • 7

  • 9

Question 5

Consider the following intermediate program in three address code

p  = a - b
q = p * c
p = u * v
q = p + q

Which one of the following corresponds to a static single assignment from the above code A)

p1 = a - b
q 1 = p1 * c
p1 = u * v
q1 = p1 + q1

B)

p3 = a - b
q4 = p3 * c
p4 = u * v
q5 = p4 + q4

C)

p 1 = a - b
q1 = p2 * c
p3 = u * v
q2 = p4 + q3

D)

p1 = a - b
q1 = p * c
p2 = u * v
q2 = p + q
  • A

  • B

  • C

  • D

Question 6

In the context of abstract-syntax-tree (AST) and control-flow-graph (CFG), which one of the following is True?

  • In both AST and CFG, let node N2 be the successor of node N1. In the input program, the code corresponding to N2 is present after the code corresponding to N1

  • For any input program, neither AST nor CFG will contain a cycle

  • The maximum number of successors of a node in an AST and a CFG depends on the input program

  • Each node in AST and CFG corresponds to at most one statement in the input program

Question 7

In the context of compilers, which of the following is/are NOT an intermediate representation of the source program?

  • Three address code

  • Abstract Syntax Tree (AST)

  • Control Flow Graph (CFG)

  • Symbol table

Question 8

Consider the following code segment.

x = u - t;
y = x * v;
x = y + w;
y = t - z;
y = x * y;

The minimum number of total variables required to convert the above code segment to static single assignment form is   Note : This question was asked as Numerical Answer Type.

  • 6

  • 8

  • 9

  • 10

Question 9

One of the purposes of using intermediate code in compilers is to

  • make parsing and semantic analysis simpler.

  • improve error recovery and error reporting.

  • increase the chances of reusing the machine-independent code optimizer in other compilers.

  • improve the register allocation.

Question 10

In a simplified computer the instructions are:

GATECS2007Q54

The computer has only two registers, and OP is either ADD or SUB. Consider the following basic block:

GATECS2007Q541

Assume that all operands are initially in memory. The final value of the computation should be in memory. What is the minimum number of MOV instructions in the code generated for this basic block?

  • 2

  • 3

  • 5

  • 6

There are 12 questions to complete.

Take a part in the ongoing discussion