The expression
where ‘op’ is one of ‘’, ‘’ and ‘’ (exponentiation) can be evaluated on a CPU with single register without storing the value of () if
View worked solution
Answer: A
The precedence of the operators is: (highest) > > (lowest).
Let us analyze the evaluation of the expression on a single-register CPU:
- If is : Since has higher precedence than , the expression is grouped as . We can load , multiply by to get in the register, multiply by to get , and then add the remaining terms. No intermediate storage of is required.
- If is : Since is left-associative, the expression is evaluated from left to right as . We compute in the register, multiply by , and continue multiplying the rest without storing any intermediate results.
- If is : Since has higher precedence than , the expression is parsed as . To evaluate this, the right operand must be evaluated before the final multiplication. If we compute first, we must store its value to free the single register for evaluating .
Thus, the evaluation can be done without storing if and only if is or .
Free practice · Your answers on this page are not saved.
