Compiler Design MCQ Questions And Answers - Code Generation
This section focuses on "Code Generation" in Compiler Design. These Multiple Choice Questions (MCQs) should be practiced to improve the Compiler Design skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive examinations.
1. Code generation can be considered as the?
A. first phase of compilation
B. second phase of compilation
C. third phase of compilation
D. final phase of compilation
View Answer
Ans : D
Explanation: Code generation can be considered as the final phase of compilation.
2. ___________ is a tool that depicts the structure of basic blocks, helps to see the flow of values flowing among the basic blocks, and offers optimization too.
A. DAG
B. CAG
C. SAG
D. PAG
View Answer
Ans : A
Explanation: Directed Acyclic Graph (DAG) is a tool that depicts the structure of basic blocks, helps to see the flow of values flowing among the basic blocks, and offers optimization too.
3. In Directed Acyclic Graph, Leaf nodes represent?
A. identifiers
B. names
C. constants
D. All of the above
View Answer
Ans : D
Explanation: Leaf nodes represent identifiers, names or constants.
4. In Algebraic expression simplification, a = a + 1 can simply be replaced by?
A. a
B. INC a
C. DEC a
D. MUL a
View Answer
Ans : B
Explanation: the expression a = a + 0 can be replaced by a itself and the expression a = a + 1 can simply be replaced by INC a.
5. x * 2 can be replaced by x << 1 is an example of?
A. Algebraic expression simplification
B. Accessing machine instructions
C. Strength reduction
D. Code Generator
View Answer
Ans : C
Explanation: Strength reduction : There are operations that consume more time and space. Their ‘strength’ can be reduced by replacing them with other operations that consume less time and space, but produce the same result.
6. The following code is an example of?
void add_ten(int x)
{
return x + 10;
printf(""value of x is %d"", x);
}
A. Redundant instruction elimination
B. Unreachable code
C. Flow of control optimization
D. None of the above
View Answer
Ans : B
Explanation: Unreachable code : Unreachable code is a part of the program code that is never accessed because of programming constructs.
7. How many descriptors are used for track both the registers (for availability) and addresses (location of values) while generating the code?
A. 2
B. 3
C. 4
D. 5
View Answer
Ans : A
Explanation: The code generator has to track both the registers (for availability) and addresses (location of values) while generating the code. For both of them, the following two descriptors are used: Register descriptor and Address descriptor.
8. __________ are used to keep track of memory locations where the values of identifiers are stored.
A. Register descriptor
B. Address descriptor
C. Both A and B
D. None of the above
View Answer
Ans : B
Explanation: Address descriptor : Values of the names (identifiers) used in the program might be stored at different locations while in execution. Address descriptors are used to keep track of memory locations where the values of identifiers are stored.
9. Code generator uses ______ function to determine the status of available registers and the location of name values.
A. setReg
B. cinReg
C. pfReg
D. getReg
View Answer
Ans : D
Explanation: Code generator uses getReg function to determine the status of available registers and the location of name values.
10. Which of the following is not a form of Intermediate representation?
A. Abstract Syntax Tree
B. 3-address code
C. Directed cyclic Graph
D. Reverse Polish Notation
View Answer
Ans : C
Explanation: IR Type : Intermediate representation has various forms. It can be in Abstract Syntax Tree (AST) structure, Reverse Polish Notation, or 3-address code.
Discussion