Compiler Construction MCQs with Answers
Practice important Compiler Construction MCQs with answers and explanations.
Chapter: 44
Q1161:
For "c = t1 * b", what happens when t1 is not live?
A. Use R1
B. Register spill
C. Use R2
D. Register free
Correct Answer:
A
Chapter: 44
Q1162:
Which instruction corresponds to "t2 = c + b" in assembly?
A. MOV R2,R3 ADD R1,R3
B. MOV R1,R2 ADD R3,R2
C. MOV R3,R2 ADD R2,R1
D. LOAD R1,R2 ADD R3,R1
Correct Answer:
A
Chapter: 44
Q1163:
In the last instruction "a = t2 + t2", what operation is performed?
A. ADD R3,R3
B. MUL R3,R3
C. SUB R3,R3
D. DIV R3,R3
Correct Answer:
A
Chapter: 44
Q1164:
Which instruction saves the variable a to memory at the end?
A. MOV R3,a
B. MOV a,R3
C. MOV R1,a
D. MOV a,R1
Correct Answer:
A
Chapter: 44
Q1165:
What is the benefit of using liveness information in register allocation?
A. Free unused registers
B. Increase code size
C. Delay execution
D. Increase memory usage
Correct Answer:
A
Chapter: 44
Q1166:
In basic code generation, which register descriptor status indicates a register is free?
A. Empty
B. InUse
C. Busy
D. Full
Correct Answer:
A
Chapter: 44
Q1167:
What is the typical order of processing instructions in basic code generation?
A. End to start
B. Beginning to end
C. Random
D. Parallel
Correct Answer:
B
Chapter: 44
Q1168:
Fill in the blank: The two main data structures used in basic code generation are ______ and ______.
A. Register descriptor, Address descriptor
B. Stack, Heap
C. Symbol table, Register file
D. Cache, Memory
Correct Answer:
A
Chapter: 44
Q1169:
Fill in the blank: MOV b,R1 means moving the value of variable b to register ______.
A. R1
B. R2
C. R3
D. R4
Correct Answer:
A
Chapter: 44
Q1170:
Fill in the blank: The assembly instruction ADD c,R1 adds the value of c to the contents of register ______.
A. R1
B. R2
C. R3
D. R4
Correct Answer:
A
Chapter: 44
Q1171:
Fill in the blank: When a variable is non-live after an instruction, its register can be ______.
A. Discarded
B. Kept
C. Duplicated
D. Stored
Correct Answer:
A
Chapter: 44
Q1172:
Fill in the blank: In the example, the instruction MUL R2,R2 means multiplying register R2 by ______.
A. Itself
B. Zero
C. One
D. Another register
Correct Answer:
A
Chapter: 44
Q1173:
Fill in the blank: The instruction sequence MOV R2,R3 ADD R1,R3 corresponds to adding the values in registers R1 and ______.
A. R2
B. R3
C. R1
D. R4
Correct Answer:
B
Chapter: 44
Q1174:
In liveness analysis, a variable is considered live if it has a ______ use in the future.
A. Next
B. Previous
C. No
D. Immediate
Correct Answer:
A
Chapter: 44
Q1175:
What happens to a register when the variable it contains is no longer live?
A. It can be reused
B. It causes an error
C. It is locked
D. It must be spilled
Correct Answer:
A
Chapter: 45
Q1176:
Liveness information helps us to keep values in ________ if they will be used later.
A. memory
B. registers
C. cache
D. disk
Correct Answer:
B
Chapter: 45
Q1177:
Why do we assume all variables are live at the end of blocks?
A. To save them for later use
B. To discard them
C. To optimize memory usage
D. To reload them immediately
Correct Answer:
A
Chapter: 45
Q1178:
Global data-flow analysis is required to determine live/next use information across _______.
A. functions
B. blocks
C. registers
D. instructions
Correct Answer:
B
Chapter: 45
Q1179:
In a DAG for a basic block, leaves are labeled by ________.
A. operator symbols
B. unique identifiers
C. values
D. registers
Correct Answer:
B
Chapter: 45
Q1180:
Interior nodes in a DAG are labeled by ________.
A. values
B. operator symbols
C. registers
D. basic blocks
Correct Answer:
B