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

Intermediate Code Generation Questions and Answers

Answer: A

The address is the base plus the index times the element width. Multi dimensional arrays extend the same idea, with one multiplication per dimension in row major order. The multiplications by constant bounds are usually strength reduced afterwards.

Please log in or register to report this question.

22.

An array A of 4 byte elements is declared with lower bound 0. What offset from the base does A[7] occupy?

Answer: B

With a lower bound of zero the offset is simply the index times the element width: \[ \text{offset} = i \times w = 7 \times 4 = 28 \ \text{bytes} \] A non-zero lower bound \( l \) would require the base to be adjusted, giving \( (i - l) \times w \) instead. Note the offset is measured from the base, so \( \mathrm{A}[7] \) is the eighth element yet sits 28 bytes along, not 32.

Please log in or register to report this question.

23.

A two dimensional array B of 4 byte elements has 10 columns and lower bounds of zero. In row major order, what offset does B[2][3] occupy?

Answer: C

Row-major order lays each row out contiguously, so the linear index counts whole rows first: \[ \text{index} = i \times n_{cols} + j = 2 \times 10 + 3 = 23 \] \[ \text{offset} = 23 \times 4 = 92 \ \text{bytes} \] Column-major order would compute \( j \times n_{rows} + i \) instead, which is why the same subscript addresses different memory in Fortran and in C.

Please log in or register to report this question.

Answer: D

The last subscript varies fastest in row major order. C and its relatives use it while Fortran uses column major, which matters when arrays are passed between languages. Mixing the two conventions silently transposes the data.

Please log in or register to report this question.

Answer: A

Splitting the address into a constant part and an index dependent part lets the constant be folded at compile time. Only the varying portion then needs computing at run time. For a loop over an array the saving is repeated on every iteration.

Please log in or register to report this question.

Answer: B

The value approach is needed when the result is stored or passed. It is less efficient than jumping code inside a condition, where the value is tested and immediately discarded. Compilers choose between the two according to how the result is used.

Please log in or register to report this question.

Answer: C

Correct answer: inherited attributes naming the true and false destinations

The jumping translation never computes a boolean value at all: it passes down, as inherited attributes, the labels to jump to if the expression proves true and if it proves false. Each subexpression generates jumps to those, which is what gives the short-circuit evaluation of and and or for nothing.

Please log in or register to report this question.

28.

Assertion (A): Short circuit evaluation of a boolean expression avoids computing a value at all.
Reason (R): Each subexpression is given the destinations to jump to, so control reaches the right place without any result being stored.

Answer: D

Both are true and the reason gives the mechanism, and it also explains the semantics. Because the second operand is never reached when the first settles the outcome, side effects in it do not occur, which languages specify deliberately.

Please log in or register to report this question.

Answer: A

Once a is false the whole conjunction is false. Skipping b saves work and, more importantly, avoids any side effects the language guarantees will not happen. A call or an assignment hidden in the second operand simply never runs.

Please log in or register to report this question.

Answer: B

The destination of a forward jump is not yet known at the moment the jump must be written out. Leaving the field blank and noting where the instruction sits allows the value to be supplied later, which is what makes single pass translation of control constructs possible at all.

Please log in or register to report this question.

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