You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
resultBox.innerHTML=`All Answered! Final Score (您的总成绩): ${correct} / ${total} (${Math.round(correct/total*100)}%)`;
159
+
resultBox.classList.add('show');
160
+
}
161
+
}
162
+
163
+
// 数据结构化 (新增了 True/False 和 指令选择 的多选题)
164
+
constquizData={
165
+
trueFalse: [
166
+
{
167
+
question: "Every optimum tiling is also an optimal tiling.",
168
+
options: [
169
+
{text: "True",explanation: "正确答案\nAn optimum tiling is the global best; if it weren't optimal, you could combine two tiles to get a better result, contradicting its status as the 'optimum'."},
170
+
{text: "False",explanation: "By definition, the global minimum (optimum) must also satisfy the local criteria for an optimal tiling."}
171
+
],
172
+
answer: 0
173
+
},
174
+
{
175
+
question: "The 'Maximal Munch' algorithm is guaranteed to find an 'optimum' tiling.",
176
+
options: [
177
+
{text: "True",explanation: "Maximal Munch only guarantees an 'optimal' tiling (locally efficient), not necessarily the 'optimum' (globally least cost)."},
178
+
{text: "False",explanation: "正确答案\nMaximal Munch is a greedy algorithm; while it finds an optimal tiling, it may miss a lower-cost global solution found by dynamic programming."}
179
+
],
180
+
answer: 1
181
+
},
182
+
{
183
+
question: "Instruction selection algorithms like Maximal Munch have a time complexity that is linear in terms of the number of nodes in the IR tree.",
184
+
options: [
185
+
{text: "True",explanation: "正确答案\nThe algorithms perform a fixed amount of work per node (or per munch), resulting in O(N) efficiency."},
186
+
{text: "False",explanation: "Despite the complexity of patterns, the matching process is highly efficient and scales linearly with the size of the input tree."}
187
+
],
188
+
answer: 0
189
+
},
190
+
{
191
+
question: "Instructions with side effects, such as autoincrement, are easily and naturally expressed using tree patterns.",
192
+
options: [
193
+
{text: "True",explanation: "Tree patterns are best suited for instructions that produce a single result; side effects usually require DAG-based patterns or ad hoc handling."},
194
+
{text: "False",explanation: "正确答案\nThe tree structure makes it difficult to represent an instruction that produces multiple results or updates multiple registers simultaneously."}
195
+
],
196
+
answer: 1
197
+
},
198
+
{
199
+
question: "Dynamic programming for instruction selection works in a top-down fashion.",
200
+
options: [
201
+
{text: "True",explanation: "Maximal Munch is top-down; dynamic programming is bottom-up because it needs the costs of subtrees to compute the cost of the parent."},
202
+
{text: "False",explanation: "正确答案\nDynamic programming is a bottom-up technique that calculates costs starting from the leaves and moving toward the root."}
203
+
],
204
+
answer: 1
205
+
},
206
+
{
207
+
question: "In the Schizo-Jouette architecture example, register r0 always contains the value zero.",
208
+
options: [
209
+
{text: "True",explanation: "正确答案\nThis is a common feature of many architectures (like MIPS) and is explicitly stated as a property of the Jouette machine."},
210
+
{text: "False",explanation: "The source explicitly mentions that r0 is hardwired to zero in this architectural model."}
211
+
],
212
+
answer: 0
213
+
}
214
+
],
215
+
multipleChoice: [
216
+
{
217
+
question: "In a tree-based intermediate representation (IR), what is the primary characteristic of each tree node?",
218
+
options: [
219
+
{text: "A. It can encapsulate multiple side effects like autoincrement and assignment.",explanation: "Complex side effects are typically features of machine instructions, not the simplified IR tree nodes."},
220
+
{text: "B. It is always 32 bits long to match the target architecture's word size.",explanation: "IR nodes are abstract data structures in the compiler, not physical machine words with fixed bit lengths."},
221
+
{text: "C. It represents a complete machine instruction including all addressing modes.",explanation: "Machine instructions often combine several primitive operations, whereas the IR nodes represent these primitives individually."},
222
+
{text: "D. It expresses only one primitive operation, such as a memory fetch or addition.",explanation: "正确答案\nThe IR is designed to be granular, representing single operations like memory access or arithmetic, which are later combined into machine instructions."}
223
+
],
224
+
answer: 3
225
+
},
226
+
{
227
+
question: "Which of the following best describes an 'optimum' tiling in instruction selection?",
228
+
options: [
229
+
{text: "A. A tiling that uses the maximum number of nodes in each individual tile.",explanation: "Using the largest possible tiles (Maximal Munch) guarantees an optimal tiling, but not necessarily the optimum (lowest cost) one."},
230
+
{text: "B. A tiling whose tiles sum to the lowest possible total cost for the entire tree.",explanation: "正确答案\nAn optimum tiling represents the global minimum cost based on the provided instruction cost model."},
231
+
{text: "C. A tiling where no two adjacent tiles can be combined into a lower-cost single tile.",explanation: "This describes an 'optimal' tiling, which is a local property rather than a global one."},
232
+
{text: "D. A tiling that produces the longest sequence of instructions to ensure safety.",explanation: "The goal of tiling is efficiency, so the shortest or least-cost sequence is generally preferred."}
233
+
],
234
+
answer: 1
235
+
},
236
+
{
237
+
question: "How does the 'Maximal Munch' algorithm select tiles during instruction selection?",
238
+
options: [
239
+
{text: "A. It randomly selects between matching tiles to avoid compiler bias.",explanation: "While it can be arbitrary if tile sizes are equal, the selection is based on tile size (number of nodes)."},
240
+
{text: "B. It examines every possible combination of tiles to find the absolute lowest cost.",explanation: "This describes dynamic programming; Maximal Munch uses a greedy approach."},
241
+
{text: "C. It starts at the root and finds the largest tile that fits, then repeats for the subtrees.",explanation: "正确答案\nMaximal Munch is a greedy top-down algorithm that prioritizes the tile covering the most nodes at the current root."},
242
+
{text: "D. It starts at the leaves and works upward to find the best match at the root.",explanation: "Maximal Munch is a top-down algorithm that begins at the root of the tree."}
243
+
],
244
+
answer: 2
245
+
},
246
+
{
247
+
question: "On a machine without a physical frame pointer, how is a reference to the virtual frame pointer (FP+k) typically resolved?",
248
+
options: [
249
+
{text: "A. It is replaced with SP+k+fs, where fs is the frame size.",explanation: "正确答案\nThe virtual frame pointer's position relative to the stack pointer depends on the total size of the current stack frame."},
250
+
{text: "B. It is ignored, and the compiler uses absolute memory addresses instead.",explanation: "Compilers must use relative addressing (via SP) because the absolute address of a stack frame varies at runtime."},
251
+
{text: "C. It is replaced by SP−k to account for stack growth directions.",explanation: "The offset depends on the frame size fs and how the virtual FP was defined relative to the SP at the start of the frame."},
252
+
{text: "D. It is resolved by allocating a dedicated register at runtime to act as a frame pointer.",explanation: "The question specifies a machine without a physical frame pointer; SP is used to simulate it mathematically."}
253
+
],
254
+
answer: 0
255
+
},
256
+
{
257
+
question: "Which of the following is a significant challenge when trying to use tree patterns for instructions with 'side effects,' such as autoincrementing a register after a memory fetch?",
258
+
options: [
259
+
{text: "A. The Jouette architecture forbids instructions with side effects.",explanation: "While Jouette is simple, the question is about the general limitation of the tree pattern-matching technique across different architectures."},
260
+
{text: "B. Tree patterns can only represent a single result or effect per tile.",explanation: "正确答案\nStandard tree patterns represent a single value or effect; instructions that produce two results (like a value and an incremented pointer) are difficult to capture in one tree."},
261
+
{text: "C. Side effects require the use of more than 32 registers.",explanation: "Register count is independent of whether an instruction has side effects or can be modeled by a tree pattern."},
262
+
{text: "D. Side effects make the matching algorithm run in exponential time.",explanation: "The algorithm remains linear; the difficulty lies in the structural representation of the instruction, not the computational complexity of the match."}
263
+
],
264
+
answer: 1
265
+
},
266
+
{
267
+
question: "When implementing instruction selection for a CISC machine with two-address instructions (e.g., r1←r1+r2), how is a three-address IR operation like t1←t2+t3 typically handled?",
268
+
options: [
269
+
{text: "A. By generating a MOVE instruction to copy t2 to t1, followed by an ADD instruction t1←t1+t3.",explanation: "正确答案\nTo simulate a three-address operation on two-address hardware, the source is moved to the destination first, and then the operation is performed in-place."},
270
+
{text: "B. By ignoring the instruction and hoping the register allocator finds a single instruction that matches.",explanation: "The instruction selector must emit valid assembly; it cannot leave IR nodes unimplemented for the allocator."},
271
+
{text: "C. By using a special MEM node to store the intermediate result of the addition.",explanation: "Storing to memory is inefficient; the standard approach uses temporary registers and extra moves which the allocator can later optimize."},
272
+
{text: "D. By forcing the register allocator to assign t1,t2, and t3 to the same physical register.",explanation: "This is often impossible if the values need to remain distinct; moves are the standard solution to preserve correctness."}
273
+
],
274
+
answer: 0
275
+
},
276
+
{
277
+
question: "In the Jouette architecture examples, which instruction would typically be generated for the IR pattern BINOP(PLUS,e1,CONST(i))?",
278
+
options:[
279
+
{text: "A. STORE",explanation: "A STORE instruction is used to move data from a register to memory, which corresponds to a MOVE(MEM(...),...) tree."},
280
+
{text: "B. MOVEM",explanation: "The MOVEM instruction in Jouette is specifically for memory-to-memory moves, which involves two MEM nodes."},
281
+
{text: "C. LOAD",explanation: "The LOAD instruction is used for memory fetches (MEM nodes), not for simple arithmetic additions with constants."},
282
+
{text: "D. ADDI",explanation: "正确答案\nThe ADDI (Add Immediate) instruction is designed to add a register value to a constant value, matching the PLUS operation with a CONST leaf."}
0 commit comments