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?
View worked solution
Answer: B
To find the minimum number of MOV instructions, we can carefully schedule the evaluation of the expressions using the two available registers, and .
Let's evaluate and first, followed by , and finally :
-
MOV c, R0()
(1st MOV) -
ADD d, R0() -
SUB e, R0()
Note: The instructionOP m, R_iperforms , soSUB e, R0correctly computes . -
MOV a, R1()
(2nd MOV) -
ADD b, R1() -
SUB R1, R0() -
MOV R1, t4()
(3rd MOV)
This sequence successfully computes the basic block using only 3 MOV instructions (two loads and one store).
Free practice · Your answers on this page are not saved.
