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:
$t_1\: = \: a+b$
$t_2\: = \: c+d$
$t_3\: = \: e-t_2$
$t_4\: = \: t_1 – t_3$
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?
MOV c, R1
ADD d, R1
SUB e, R1
SUB a, R1
ADD b, R1
MOV R1, m
What's wrong with this one?
@sidharth
MOV c, R1 ; R1=c
ADD d, R1 ; R1= d+c
SUB e, R1 ; R1=e-(c+d)
SUB a, R1 ; R1=a-(e-(c+d))
ADD b, R1 ;R1=b+a-(e-(c+d))
I think this is right, answer should be 2 then !
@VS and @ Sidharth Singla
I think this is right, answer should be 2.
is @rahul sharma 5's answer not OK ? (means answer is not 2 because basic block should be executed in sequence)
By the definition of a basic block "whenever the first instruction in a basic block is executed, the rest of the instructions are necessarily executed exactly once, in order." [Source: Wikipedia]
3 MOV instructions.
Min 3 moves
When will be the final official key...