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 6–10 of 32
Consider the following pseudo-code.
Which of of the following options CORRECTLY specifies the number of basic blocks and the number of instructions in the largest basic block, respectively?
Which of of the following options CORRECTLY specifies the number of basic blocks and the number of instructions in the largest basic block, respectively?
Answer: (D)
Leaders: the first instruction (L1), the jump targets (L3, L4, L11), and the instructions right after a conditional jump (L10, L13, L15).
Basic blocks:
- B1: L1-L2 (2)
- B2: L3 (1)
- B3: L4-L9 (6)
- B4: L10 (1)
- B5: L11-L12 (2)
- B6: L13-L14 (2)
- B7: L15 (1)
There are 7 basic blocks. The largest, B3, has 6 instructions.
Answer: 7 and 6
Basic blocks:
- B1: L1-L2 (2)
- B2: L3 (1)
- B3: L4-L9 (6)
- B4: L10 (1)
- B5: L11-L12 (2)
- B6: L13-L14 (2)
- B7: L15 (1)
There are 7 basic blocks. The largest, B3, has 6 instructions.
Answer: 7 and 6
Consider the following expression: . The following sequence shows the list of triples representing the given expression, with entries missing for triples (1), (3), and (6).
Which one of the following options fills in the missing entries CORRECTLY?
Which one of the following options fills in the missing entries CORRECTLY?
Answer: (A)
Expression: . The triples, in the order they are evaluated:
- (0) + p r
- (1) =[] s i this fetches s[i]
- (2) uminus (1)
- (3) * (0) (2) this is (p+r) * (s[i])
- (4) / u w
- (5) + (3) (4)
- (6) []= x i this is the location x[i] where the result is stored
- (7) = (6) (5)
Answer: (1) =[] s i, (3) * (0) (2), (6) []= x i
- (0) + p r
- (1) =[] s i this fetches s[i]
- (2) uminus (1)
- (3) * (0) (2) this is (p+r) * (s[i])
- (4) / u w
- (5) + (3) (4)
- (6) []= x i this is the location x[i] where the result is stored
- (7) = (6) (5)
Answer: (1) =[] s i, (3) * (0) (2), (6) []= x i
Consider the following statements regarding the front-end and back-end of a compiler.
S1: The front-end includes phases that are independent of the target hardware.
S2: The back-end includes phases that are specific to the target hardware.
S3: The back-end includes phases that are specific to the programming language used in the source code.
Identify the CORRECT option.
S1: The front-end includes phases that are independent of the target hardware.
S2: The back-end includes phases that are specific to the target hardware.
S3: The back-end includes phases that are specific to the programming language used in the source code.
Identify the CORRECT option.
Answer: (B)
Let us check every statement one by one:
- The front end covers lexical, syntax and semantic analysis and intermediate code. It depends on the source language and not on the target machine So S1 is TRUE.
- The back end covers machine-level code optimization and code generation. It is specific to the target hardware So S2 is TRUE.
- The back end takes intermediate code as its input, so it does not depend on the source language So S3 is FALSE.
Answer: Only S1 and S2 are TRUE
- The front end covers lexical, syntax and semantic analysis and intermediate code. It depends on the source language and not on the target machine So S1 is TRUE.
- The back end covers machine-level code optimization and code generation. It is specific to the target hardware So S2 is TRUE.
- The back end takes intermediate code as its input, so it does not depend on the source language So S3 is FALSE.
Answer: Only S1 and S2 are TRUE
Consider the control flow graph shown.
Which one of the following choices correctly lists the set of live variables at the exit point of each basic block?
Which one of the following choices correctly lists the set of live variables at the exit point of each basic block?
Answer: (D)
Uses and definitions: B1 defines i, j, a. B2 uses and defines i, j. B3 defines a. B4 uses a and defines i. Flow: B1 → B2; B2 → B3 and B4; B3 → B4; B4 → B2 or exit.
A variable is live at a point if it may be used later before being redefined. For each block, , and OUT is the union of IN of the next blocks:
-
- ,
Start with all sets empty and repeat until nothing changes.
Round 1 (nothing known yet about OUT(B4)):
- IN(B4) = {a}; OUT(B3) = IN(B4) = {a}; IN(B3) = {}
- OUT(B2) = IN(B3) IN(B4) = {a}; IN(B2) = {i, j, a}
Round 2 (use the new IN(B2)):
- OUT(B4) = IN(B2) = {a, i, j}; IN(B4) = {a, j}
- OUT(B3) = IN(B4) = {a, j}; IN(B3) = {j}
- OUT(B2) = IN(B3) IN(B4) = {a, j}; IN(B2) = {a, i, j}, which is unchanged
- OUT(B1) = IN(B2) = {a, i, j}
Nothing changes in round 3, so these are the final sets.
Answer: (D)
A variable is live at a point if it may be used later before being redefined. For each block, , and OUT is the union of IN of the next blocks:
-
- ,
Start with all sets empty and repeat until nothing changes.
Round 1 (nothing known yet about OUT(B4)):
- IN(B4) = {a}; OUT(B3) = IN(B4) = {a}; IN(B3) = {}
- OUT(B2) = IN(B3) IN(B4) = {a}; IN(B2) = {i, j, a}
Round 2 (use the new IN(B2)):
- OUT(B4) = IN(B2) = {a, i, j}; IN(B4) = {a, j}
- OUT(B3) = IN(B4) = {a, j}; IN(B3) = {j}
- OUT(B2) = IN(B3) IN(B4) = {a, j}; IN(B2) = {a, i, j}, which is unchanged
- OUT(B1) = IN(B2) = {a, i, j}
Nothing changes in round 3, so these are the final sets.
Answer: (D)
In the context of compilers, which of the following is/are NOT an intermediate representation of the source program?
One or more options are correct.
Answer: (D)
Three address code, AST and CFG are all forms of the program that are used between the front end and the back end. The symbol table only keeps information about names. It does not represent the program.
Answer: Symbol table
Answer: Symbol table
Keep practising
Topics in Compiler Design
Lexical AnalysisParsingSyntax-directed TranslationRuntime EnvironmentAssemblers, Linkers and Loaders
Intermediate Code GenerationYou are here
Matching