A computer which issues instructions in order, has only 2 registers and 3…

2020

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 accesses and by how many MOV instructions ?

  1. A.

    Case 2, 2

  2. B.

    Case 2, 3

  3. C.

    Case 1, 2

  4. D.

    Case 1, 3

Attempted by 50 students.

Show answer & explanation

Correct answer: A

The problem requires minimizing MOV instructions with only two registers. Case 1 forces t1 to be stored and reloaded, increasing memory traffic compared to Case 2. In Case 2, the instruction order allows t2 to remain in a register while computing subsequent values, reducing unnecessary loads and stores. Analysis confirms Case 2 saves exactly 2 MOV instructions over Case 1.

Explore the full course: Isro