Machine-translated by Google. Questions are authored in English.
Top

Code Generation Questions and Answers

Answer: A

The intermediate form supplies the computation and the symbol table supplies the storage decisions. Code generation turns the pair into instructions for a particular machine. Nothing about the source language is visible at this stage.

Please log in or register to report this question.

Answer: B

Correct answer: instruction selection, register allocation and instruction ordering

These are the three decisions the back end must make: which instructions implement each operation, which values live in which registers, and in what order the instructions are issued. All three interact, which is what makes optimal code generation intractable and why each is handled by heuristics.

Please log in or register to report this question.

Answer: C

All three are used in practice. Emitting assembly is easiest to debug, relocatable code supports separate compilation, and absolute code suits a load and go compiler. The choice is usually settled by how the compiler is meant to be used.

Please log in or register to report this question.

4.

Match each output form with its principal advantage.
List I
A. assembly language
B. relocatable machine code
C. absolute machine code
D. bytecode for a virtual machine
List II
1. no link step is required at all
2. easy to read and to debug
3. portable across machines
4. supports separate compilation

Answer: D

Each form suits a different setting. The choice affects how much work remains after compilation and how easy the compiler itself is to develop and to test. Many compilers emit assembly during development and machine code later.

Please log in or register to report this question.

Answer: A

Correct answer: compare candidate instruction sequences and choose among them

Several sequences usually implement the same operation, and the cost model - typically counting instruction words and memory references - is what lets the generator prefer one. Its accuracy sets a limit on the quality of the code, since a model that misprices an instruction will choose wrongly every time.

Please log in or register to report this question.

6.

An instruction costs one unit plus one for each operand using an addressing mode that requires an extra word. How much does an instruction with two such operands cost?

Answer: B

Correct answer: 3

One unit for the instruction itself and one for each of the two operands requiring an extra word: \[ 1 + 1 + 1 = 3. \] The extra word is what makes a memory operand more expensive than a register one, and it is the whole basis on which the generator prefers registers.

Please log in or register to report this question.

Answer: C

The operand is named by a few bits inside the instruction itself. This is the whole reason register allocation matters so much to the quality of generated code. A value spilled to memory costs a load on every use of it.

Please log in or register to report this question.

Answer: D

Correct answer: recursive, in which the operand names another instruction

There is no such addressing mode: an operand names data, not an instruction. The other three are standard - register direct, indexed and indirect - and the set available on a machine largely determines how much work the generator must do to reach an operand.

Please log in or register to report this question.

Answer: A

A single load with a scaled index may realise a multiplication, an addition and a memory access together. Because one pattern can cover several nodes, the selector must decide how to tile the whole tree rather than translating each operation in isolation.

Please log in or register to report this question.

Answer: B

Correct answer: covering the expression tree with patterns, each naming an instruction

Each instruction is described as a small tree pattern, and generating code means tiling the expression tree with those patterns so that every node is covered. Dynamic programming finds the cheapest tiling for a tree, which makes instruction selection systematic rather than a matter of hand-written cases.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Code Generation Questions and Answers || Code Generation MCQ Questions and Answers || Code Generation GK Questions and Answers || Code Generation GK MCQ Questions || Code Generation Multiple Choice Questions and Answers || Code Generation GK || GK on Code Generation || Compiler Design Questions and Answers || Compiler Design MCQ Questions and Answers || Compiler Design GK Questions and Answers || GK on Compiler Design