We are evaluating the expression:
E=(a−1)∗(((b+c)/3)+d) Let's determine the minimum number of registers required using optimal evaluation order (evaluating the heavier subtree first):
Evaluate the right operand (((b+c)/3)+d) first:
ADD R1, R1, R2 (R1 = b + c, R2 becomes free)
DIV R1, R1, 3 (R1 = (b + c) / 3, immediate operand)
ADD R1, R1, R2 (R1 = ((b + c) / 3) + d, R2 becomes free)
Evaluate the left operand (a−1):
SUB R2, R2, 1 (R2 = a - 1, immediate operand)
Perform the final multiplication:
MUL R1, R2, R1 (R1 = (a - 1) * (((b + c) / 3) + d))
Throughout the computation, only 2 registers (R1 and R2) are used simultaneously with no register spilling. Since at least 2 registers are required to hold the operands for the binary multiplication operator, the minimum number of registers is 2.