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 21–25 of 32
Which one of the following is FALSE?
Answer: (D)
Changing x = 4 * 5 into x = 20 means the constant is worked out at compile time. This is constant folding. It is not common subexpression elimination. The other statements are true.
Answer: x = 4*5 x = 20 is an example of common subexpression elimination (FALSE)
Answer: x = 4*5 x = 20 is an example of common subexpression elimination (FALSE)
For a C program accessing x[i][j][k], the following intermediate code is generated by a compiler. Assume that the size of an integer is 32 bits and the size of a character is 8 bits.
t0 = i * 1024
t1 = j * 32
t2 = k * 4
t3 = t1 + t0
t4 = t3 + t2
t5 = x[t4]
Which one of the following statements about the source code for the C program is CORRECT?
t0 = i * 1024
t1 = j * 32
t2 = k * 4
t3 = t1 + t0
t4 = t3 + t2
t5 = x[t4]
Which one of the following statements about the source code for the C program is CORRECT?
Answer: (A)
Step for t2: k 4 so one element takes 4 bytes (int).
Step for t1: j 32 one row of the last dimension is 32 B, which is 8 ints so the third dimension is 8.
Step for t0: i 1024 1024 / 32 = 32 rows so the second dimension is 32.
So x is declared as int x[ ][32][8]. This matches int x[32][32][8].
Answer: int x[32][32][8]
Step for t1: j 32 one row of the last dimension is 32 B, which is 8 ints so the third dimension is 8.
Step for t0: i 1024 1024 / 32 = 32 rows so the second dimension is 32.
So x is declared as int x[ ][32][8]. This matches int x[32][32][8].
Answer: int x[32][32][8]
The minimum number of arithmetic operations required to evaluate the polynomial for a given value of x, using only one temporary variable is _____.
Answer: 7
Rewrite P(x) in this form:
Steps with one temporary t:
- t = x * x
- t = t + 4
- t = t * x
- t = t * x. Now t holds:
- t = t + 6
- t = t * x. Now t holds:
- t = t + 5
This takes 7 operations with one temporary.
Answer: 7
Steps with one temporary t:
- t = x * x
- t = t + 4
- t = t * x
- t = t * x. Now t holds:
- t = t + 6
- t = t * x. Now t holds:
- t = t + 5
This takes 7 operations with one temporary.
Answer: 7
One of the purposes of using intermediate code in compilers is to
Answer: (C)
Intermediate code does not depend on the machine. So the same optimizer (and front end) can be used again with other back ends for other machines.
Answer: increase the chances of reusing the machine-independent code optimizer in other compilers
Answer: increase the chances of reusing the machine-independent code optimizer in other compilers
Consider the basic block given below.
a= b + c
c =a + d
d =b + c
e =d - b
a =e + b
The minimum number of nodes and edges present in the DAG representation of the above basic block respectively are
a= b + c
c =a + d
d =b + c
e =d - b
a =e + b
The minimum number of nodes and edges present in the DAG representation of the above basic block respectively are
Answer: (A)
Work with the values to simplify:
- d = b + c, and e = d b = c (the new c). Then a = e + b = c + b = d.
So e uses the same node as c, and the last a uses the same node as d.
- Leaf nodes: b, c0, d0 (3 nodes)
- n1 = b + c0 (a), n2 = n1 + d0 (c, e), n3 = b + n2 (d, a). These are 3 more nodes, with 2 edges each.
Nodes = 6, edges = 6
Answer: 6 and 6
- d = b + c, and e = d b = c (the new c). Then a = e + b = c + b = d.
So e uses the same node as c, and the last a uses the same node as d.
- Leaf nodes: b, c0, d0 (3 nodes)
- n1 = b + c0 (a), n2 = n1 + d0 (c, e), n3 = b + n2 (d, a). These are 3 more nodes, with 2 edges each.
Nodes = 6, edges = 6
Answer: 6 and 6
Keep practising
Topics in Compiler Design
Lexical AnalysisParsingSyntax-directed TranslationRuntime EnvironmentAssemblers, Linkers and Loaders
Intermediate Code GenerationYou are here
Matching