A computer which issues instructions in order, has only 2 registers and 3 opcodes ADD, SUB and MOV. Consider 2 different implementations of the following basic block: Case 1   Case 2 t1 = a + b;    t2 = c + d; t2 = c + d;    t3 = e – t2; t3 = e – t2;    t1 = a + b; t4 = t1 – t2;    t4 = t1 – t2;   Assume that all operands are initially in memory. Final value of computation also has to reside in memory. Which one is better in terms of memory and by how many MOV instructions?

A computer which issues instructions in order, has only 2 registers and 3 opcodes ADD, SUB and MOV. Consider 2 different implementations of the following basic block: Case 1   Case 2 t1 = a + b;    t2 = c + d; t2 = c + d;    t3 = e – t2; t3 = e – t2;    t1 = a + b; t4 = t1 – t2;    t4 = t1 – t2;   Assume that all operands are initially in memory. Final value of computation also has to reside in memory. Which one is better in terms of memory and by how many MOV instructions? Correct Answer Case 1, 3

Solving both the cases with 2-Address format.

Case 1

MOV a, t1 (moves value of a to t1)

ADD b, t1 (adds value of b to t1 and stores in t1)

MOV c, t2

ADD d, t2

SUB e, t2

SUB t1, t2

MOV t2, a (as end value has to be in memory)

Hence, 3 MOV operations in total.

Case 2

MOV c, t2

ADD d, t2

MOV t2, t3 (because t2 is updated in next instruction and this value needs to be preserved till end)

SUB e, t2

MOV a, t1

ADD b, t1

SUB t1, t3

MOV c, t3

Hence 4 MOV operations in total.

Therefore, Case 1 has less MOV operations and that is 3. 

Related Questions

Consider the following system of equations in three real variables x1, x2 and x3
2x1 - x2 + 3x3 = 1
3x1 - 2x2 + 5x3 = 2
-x1 - 4x2 + x3 = 3
This system of equations has
Let X1, X2 be two independent normal random variables with means μ1, μ2 and standard deviations σ1, σ2 respectively. Consider Y = X1 - X2; μ1 = μ2 = 1, σ1 = 1, σ2 = 2, Then,