• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Code Generation and Optimization

Question 1

Which of the following macros can put a micro assembler into an infinite loop? (i)
.MACRO M1 X
.IF EQ, X      ;if X=0 then
M1 X + 1
.ENDC
.IF NE X       ;IF X≠0 then
.WORD X        ;address (X) is stored here
.ENDC
.ENDM
(ii)
.MACRO M2 X
.IF EQ X
M2 X
.ENDC
.IF NE, X
.WORD X+1
.ENDC
.ENDM
  • (ii) only
  • (i) only
  • Both (i) and (ii)
  • None of the above

Question 2

Some code optimizations are carried out on the intermediate code because
  • they enhance the portability of the compiler to other target processors
  • program analysis is more accurate on intermediate code than on machine code
  • the information from dataflow analysis cannot otherwise be used for optimization
  • the information from the front end cannot otherwise be used for optimization

Question 3

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

Question 4

Which one of the following is FALSE?
  • A basic block is a sequence of instructions where control enters the sequence at the beginning and exits at the end.
  • Available expression analysis can be used for common subexpression elimination.
  • Live variable analysis can be used for dead code elimination.
  • x = 4 ∗ 5 => x = 20 is an example of common subexpression elimination.

Question 5

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 6

Consider the following C code segment. 

for (i = 0, i<n; i++)
{
   for (j=0; j<n; j++)
   {
       if (i%2)
       {
           x += (4*j + 5*i);
           y += (7 + 4*j);
       }
   }
}

Which one of the following is false?

  • The code contains loop invariant computation

  • There is scope of common sub-expression elimination in this code

  • There is scope of strength reduction in this code

  • There is scope of dead code elimination in this code

Question 7

Consider the grammar rule E → E1 - E2 for arith­metic expressions. The code generated is targeted to a CPU having a single user register. The sub­traction operation requires the first operand to be in the register. If E1 and E2 do not have any com­mon sub expression, in order to get the shortest possible code

  • E1 should be evaluated first

  • E2 should be evaluated first

  • Evaluation of E1 and E2 should necessarily be interleaved

  • Order of evaluation of E1 and E2 is of no consequence

Question 8

Consider the following statements.
  • S1: The sequence of procedure calls corresponds to a preorder traversal of the activation tree.
  • S2: The sequence of procedure returns corresponds to a postorder traversal of the activation tree.
Which one of the following options is correct?
  • S1 is true and S2 is false
  • S1 is false and S2 is true
  • S1 is true and S2 is true
  • S1 is false and S2 is false

Question 9

Consider the intermediate code given below:
1. i = 1
2. j = 1
3. t1 = 5 * i
4. t2 = t1 + j
5. t3 = 4 * t2
6. t4 = t3
7. a[t4] = –1
8. j = j + 1
9. if j <= 5 goto(3)
10. i = i + 1
11. if i < 5 goto(2) 
The number of nodes and edges in the control-flow-graph constructed for the above code, respectively, are
  • 5 and 7
  • 6 and 7
  • 5 and 5
  • 7 and 8

Question 10

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

There are 38 questions to complete.

Last Updated :
Take a part in the ongoing discussion