GATE 2017 CS – Question 62
Consider the expression $(a - 1) * (((b + c) / 3) + d)$. Let $X$ be the minimum number of registers required by an *optimal* code generation (without any register spill) algorithm for a load/store architecture, in which (i) only load and store instructions can have memory operands and (ii) arithmetic instructions can have only register or immediate operands. The value of $X$ is ________.
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: 2
Explanation
Evaluate the right-hand part first: load $b$ and $c$ into two registers and add them, then divide by the immediate 3, which leaves one register. Load $d$ into the other register and add, which leaves the right part in one register. Then load $a$ into the free register, subtract the immediate 1 and multiply. At no point are more than 2 registers needed.