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

Code Generation Questions and Answers

Answer: A

Increment and decrement instructions, multiply and accumulate, and address computation instructions are typical examples. Recognising them is part of instruction selection. A machine description lists the idioms the generator should look for.

Please log in or register to report this question.

Answer: B

Correct answer: correct but longer and slower than necessary

Machine idioms - an increment instruction, an add with shift, a multiply-accumulate - do in one instruction what would otherwise take several. Ignoring them costs performance and code size but not correctness, since the longer sequence computes the same result.

Please log in or register to report this question.

Answer: C

Everything that depends on the machine lives in the back end. The front end depends on the source language and should not need to change at all. That separation is precisely what an intermediate representation exists to provide.

Please log in or register to report this question.

Answer: D

Machine description languages let a new target be supported by writing a specification rather than code. The approach trades some code quality for much faster retargeting. A hand written back end still wins where the last few per cent matter.

Please log in or register to report this question.

Answer: A

Correct answer: needs no register allocation, since operands are on a stack

A stack machine takes its operands from the top of the stack implicitly, so there are no registers to allocate and code generation reduces to a postorder walk of the expression tree. That simplicity is why stack code is used for portable intermediate forms - and why it is slower than register code on real hardware.

Please log in or register to report this question.

Answer: B

Each leaf becomes a push and each interior node an operator that consumes the values pushed by its children. The result is exactly reverse Polish order. No register allocation is required, which is what makes the model so simple.

Please log in or register to report this question.

Answer: C

Explicit registers avoid the traffic that a stack discipline forces. Stack code is more compact, which is why it remains attractive for a portable distribution format. Just in time compilers translate such code into register code before running it.

Please log in or register to report this question.

Answer: D

Correct answer: find the storage location and type of each name

The generator needs to know where each name lives - a register, a frame offset, a static address - and what type it has, since the type determines which instructions apply. Both come from the symbol table, which is why it survives long after the parse.

Please log in or register to report this question.

Answer: A

Correct answer: a conversion instruction inserted where the semantic analyser required

The semantic analyser has already decided where a conversion is needed and recorded it in the tree; the generator’s task is to emit the machine’s conversion instruction at that point. Treating the two representations as interchangeable would produce nonsense, since their bit patterns mean quite different things.

Please log in or register to report this question.

Answer: B

Correct answer: checking that every identifier has been declared

Declaration checking belongs to semantic analysis and is complete long before code generation begins - the generator assumes a correct program. Instruction selection, register allocation and scheduling are its three tasks, and all three are about how to express a program already known to be valid.

Please log in or register to report this question.

Loading…
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