Intermediate Code Generation
Q21.
The following code segment is executed on a processor which allows only register operands in its instructions. Each instruction can have atmost two source operands and one destination operand. Assume that all variables are dead after this code segment. c = a + b; d = c * a; e = c + a; x = c * c; if (x > a) { y = a * a; } else { d = d * d; e = e * e; } What is the minimum number of registers needed in the instruction set architecture of the processor to compile this code segment without any spill to memory? Do not apply any optimization other than optimizing register allocationQ22.
The program below uses six temporary variables a, b, c, d, e, f. a =1 b= 10 c =20 d= a +b e= c +d f =c +e b= c+ e e =b +f d =5 +e return d +f Assuming that all operations take their operands from registers, what is the minimum number of registers needed to execute this program without spilling?Q23.
In a simplified computer the instructions are: The computer has only two registers, and OP is either ADD or SUB. Consider the following basic block: Assume that all operands are initially in memory. The final value of the computation should be in memory. What is the minimum number of MOV instructions in the code generated for this basic block?Q24.
Generation of intermediate code based on an abstract machine model is useful in compilers becauseQ25.
Mention the pass number for each of the following activities that occur in a two pass assembler: A. object code generation B. literals added to literal table C. listing printed D. address resolution of local symbolsQ26.
Choose the correct alternatives (more than one may be correct) and write the corresponding letters only: Indicate all the true statements from the following:Q27.
The expression ( a * b) * c \; op \dots where 'op' is one of '+', '*' and '\uparrow' (exponentiation) can be evaluated on a CPU with single register without storing the value of (a * b) ifQ29.
Consider the following C code segment. for (i = 0, < i n; i++) { for (j=0; j< n; j++) { if (i%2) { x += (4*j + 5*i); y += (7 + 4*j); } } } Which one to the following false?Q30.
Consider evaluating the following expression tree on a machine with load-store architecture in which memory can be accessed only through load and store instructions. The variables a, b, c, d and e are initially stored in memory. The binary operators used in this expression tree can be evaluated by the machine only when the operands are in registers. The instructions produce result only in a register. If no intermediate results can be stored in memory, what is the minimum number of registers needed to evaluate this expression?