Compiler Construction MCQs with Answers
Practice important Compiler Construction MCQs with answers and explanations.
Chapter: 45
Q1181:
When generating a DAG from 3-address code, if a node for "y op z" exists, we should:
A. add y
B. add z
C. add x to the node label
D. remove node
Correct Answer:
C
Chapter: 45
Q1182:
In DAG generation, if y or z exist in the DAG, we:
A. create new leaves
B. point to existing nodes
C. delete old nodes
D. create new operators
Correct Answer:
B
Chapter: 45
Q1183:
If a variable x existed previously as a leaf in the DAG, we should:
A. remove it
B. subscript that entry
C. rename it
D. delete it
Correct Answer:
B
Chapter: 45
Q1184:
DAGs can have nodes with multiple labels because they represent:
A. instructions
B. operators
C. computed values
D. registers
Correct Answer:
C
Chapter: 45
Q1185:
Which of the following 3-address code lines correspond to a DAG node labeled '+'?
A. t1 = a * a
B. a = b + c
C. c = t1 * b
D. t2 = c + b
Correct Answer:
B
Chapter: 45
Q1186:
In DAG-based optimization, a node with more than one parent indicates a:
A. unique expression
B. common sub-expression
C. dead code
D. loop
Correct Answer:
B
Chapter: 45
Q1187:
Which traversal order of the given DAG resulted in fewer machine instructions?
A. Order 1
B. Order 2
C. Both same
D. None
Correct Answer:
B
Chapter: 45
Q1188:
Reordering DAG traversal can improve code by:
A. reducing memory
B. increasing registers
C. reducing machine instructions
D. increasing registers usage
Correct Answer:
C
Chapter: 45
Q1189:
Registers in a machine are considered a ________ resource.
A. unlimited
B. scarce
C. infinite
D. optional
Correct Answer:
B
Chapter: 45
Q1190:
The program counter is kept in a _________.
A. cache
B. memory
C. register
D. stack
Correct Answer:
C
Chapter: 45
Q1191:
Division operator typically requires how many registers?
A. One
B. Two
C. Three
D. Four
Correct Answer:
B
Chapter: 45
Q1192:
The general register allocation problem is known to be:
A. P
B. NP
C. NP-complete
D. Undecidable
Correct Answer:
C
Chapter: 45
Q1193:
Graph coloring in register allocation ensures that:
A. adjacent nodes share colors
B. no two connected nodes share colors
C. nodes are deleted
D. nodes are merged
Correct Answer:
B
Chapter: 45
Q1194:
In register allocation, the interference graph has:
A. one node per instruction
B. one node per variable
C. one edge per instruction
D. no edges
Correct Answer:
B
Chapter: 45
Q1195:
An edge between two nodes in an interference graph indicates:
A. variables are independent
B. variables live at the same time
C. variables are equal
D. variables can be merged
Correct Answer:
B
Chapter: 45
Q1196:
In the register allocation algorithm, what happens when all nodes have degree >= K?
A. All nodes get colors
B. Spill nodes to memory
C. Stop allocation
D. Increase registers
Correct Answer:
B
Chapter: 45
Q1197:
What does the 'Simplify' step in graph coloring do?
A. Remove nodes with many neighbors
B. Remove nodes with fewer than K neighbors
C. Assign colors
D. Mark spill nodes
Correct Answer:
B
Chapter: 45
Q1198:
Assigning colors in graph coloring starts from:
A. the original graph
B. an empty graph
C. the largest node
D. the smallest node
Correct Answer:
B
Chapter: 45
Q1199:
Live variables are saved at the end of blocks because:
A. they may be needed later
B. they are not used again
C. to free up registers
D. to optimize CPU cycles
Correct Answer:
A
Chapter: 45
Q1200:
The algorithm to generate DAG from 3-address code involves checking for:
A. operator existence
B. variable existence
C. node existence
D. memory location
Correct Answer:
C