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
The value of $X$ is _____________ .
@svas7246
The main advantage of storing the result as register is they are stored in CPU memory which is accessed very fast compared to RAM. This makes the program to get executed faster.
If intermediate result is stored in memory then we don’t need an additional register to store it and it minimizes the registers used.
Good Read
what the question want to tell by these 2 lines –
only load and store instructions can have memory operands -> It means that during load and store instruction we can use variable name(memory operands) on RHS (Just to understand in easy language )
arithmetic instructions can have only register or immediate operands->.means whenever we perform arithmetic operation then we need to use only register(the register on which the memory operands are stored or loaded ) as a operand OR Immediate Operands(constants) as a operand .
@tusharp
check this link https://en.wikipedia.org/wiki/Sethi%E2%80%93Ullman_algorithm
@sanketnagrale ...yes 3 registers would be required...assign 1 in place of leaf node having 1…But ..I think this is correct tree according to Sethi-Ullman algo for given question ….We have to assign 1 to variables and zero if constants…
@Amit Puri You have assigned zero to c variable which is wrong i think…....correct me if wrong..
solution..
Answer: 2 Registers (minimum)
(adding this answer to visually see what’s happening really) Let’s Construct an Expression tree – an easy way to visualize now come from bottom to top, numbered 1 to 9
(note: immediate values can be specified by CPU, hence is no need to load them into Reg and here “ $R_{i}$ ← a “ is load operation [abusive notation] ) we try to conserve as many registers as possible, we can come from anyway, left first or right first in the tree but make sure the register is free to use at that point (i.e, not holding any temporary value that we want to use in the future)
64.3k questions
77.9k answers
243k comments
79.7k users