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 16–20 of 32
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__________ .
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__________ .
Answer: 10
In SSA form, each assignment creates a new variable:
The new variables are (5 in all). Add the input variables u, t, v, w, z (5 in all).
Total = 10
Answer: 10
The new variables are (5 in all). Add the input variables u, t, v, w, z (5 in all).
Total = 10
Answer: 10
A variable x is said to be live at a statement in a program if the following three conditions hold simultaneously:
i. There exists a statement that uses x
ii. There is a path from to in the flow graph corresponding to the program
iii. The path has no intervening assignment to x including at and
The variables which are live both at the statement in basic block 2 and at the statement in basic block 3 of the above control flow graph are
i. There exists a statement that uses x
ii. There is a path from to in the flow graph corresponding to the program
iii. The path has no intervening assignment to x including at and
The variables which are live both at the statement in basic block 2 and at the statement in basic block 3 of the above control flow graph are
Answer: (C)
For a block : , where holds the variables read in before any write, and is the union of of the successors.
Block 1 uses before defining them (, , are defined and then used inside the block). Block 1 is in a loop (4 1), so check that nothing more is added. Start with .
-
-
-
- , and , which is already inside . So no set changes and these values are final.
Live at both the statement in block 2 and the one in block 3: .
Answer: (C)
Block 1 uses before defining them (, , are defined and then used inside the block). Block 1 is in a loop (4 1), so check that nothing more is added. Start with .
-
-
-
- , and , which is already inside . So no set changes and these values are final.
Live at both the statement in block 2 and the one in block 3: .
Answer: (C)
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 _______________.
Answer: 8
In SSA, each result is stored in a new variable. Let us count the operations:
t1 = r / 3, t2 = q + t1, t3 = t2 + s, t4 = t * 5, t5 = t3 t4, t6 = u * v, t7 = t6 / w, t8 = t5 + t7
There are 8 operations so 8 temporaries are needed.
Answer: 8
t1 = r / 3, t2 = q + t1, t3 = t2 + s, t4 = t * 5, t5 = t3 t4, t6 = u * v, t7 = t6 / w, t8 = t5 + t7
There are 8 operations so 8 temporaries are needed.
Answer: 8
In the context of abstract-syntax-tree (AST) and control-flow-graph (CFG), which one of the following is TRUE?
Answer: (C)
Let us check every statement one by one:
- Option 1: in a CFG, a loop edge goes back to code that comes earlier so this is false.
- Option 2: a CFG has cycles when there are loops so this is false.
- Option 3: an AST node can have as many children as the construct needs. A CFG node (for example a switch) can have as many successors as the code has so this is true.
- Option 4: one CFG basic block can hold many statements so this is false.
Answer: The maximum number of successors depends on the input program
- Option 1: in a CFG, a loop edge goes back to code that comes earlier so this is false.
- Option 2: a CFG has cycles when there are loops so this is false.
- Option 3: an AST node can have as many children as the construct needs. A CFG node (for example a switch) can have as many successors as the code has so this is true.
- Option 4: one CFG basic block can hold many statements so this is false.
Answer: The maximum number of successors depends on the input program
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 j5 goto (3)
(10) i=i+1
(11) if i5 goto (2)
The number of nodes and edges in the control-flow-graph constructed for the above code, respectively, are
(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 j5 goto (3)
(10) i=i+1
(11) if i5 goto (2)
The number of nodes and edges in the control-flow-graph constructed for the above code, respectively, are
Answer: (B)
Leaders are (1), (2) (jump from 11), (3) (jump from 9) and (10) (comes after a jump).
Blocks: B1 = {1}, B2 = {2}, B3 = {3-9}, B4 = {10, 11}, and also Entry and Exit 6 nodes.
The edges are: EntryB1, B1B2, B2B3, B3B3, B3B4, B4B2, B4Exit 7 edges.
Final answer: 6 and 7
Blocks: B1 = {1}, B2 = {2}, B3 = {3-9}, B4 = {10, 11}, and also Entry and Exit 6 nodes.
The edges are: EntryB1, B1B2, B2B3, B3B3, B3B4, B4B2, B4Exit 7 edges.
Final answer: 6 and 7
Keep practising
Topics in Compiler Design
Lexical AnalysisParsingSyntax-directed TranslationRuntime EnvironmentAssemblers, Linkers and Loaders
Intermediate Code GenerationYou are here
Matching