2,186 views

A computer which issues instructions in order, has only $2$ registers and $3$ opcodes $\text{ADD, SUB}$ and $\text{MOV}$. Consider $2$ different implementations of the following basic block :

$$\begin{array}{l|l}\text{Case 1} & \text{Case 2} \\ \hline t1=a+b;&t2=c+d;\\t2=c+d;&t3=e-t2;\\t3=e-t2;&t1=a+b;\\t4=t1-t2;&t4=t1-t2;\end{array}$$

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 $\text{MOV}$ instructions?

1. $\text{Case 2,2}$
2. $\text{Case 2,3}$
3. $\text{Case 1,2}$
4. $\text{Case 1,3}$

Question should state whether operations accept:
(i) both operands in registers (AND/OR)
(ii) one in register and other in memory

I believe the answer should be Case 1, 1.

Let's say our registers are $R_1$ and $R_2$

Case 1:

Move $a$ into $R_1$.

Add $b$ to $R_1$

Move $c$ into $R_2$

Add $d$ to $R_2$

Subtract $R_2$ from e.

Subtract $R_2$ from $R_1$

Store the result in memory via a move operation.

Total: 3

Case 2:

Move $c$ into $R_1$

Add $d$ to $R_1$

Move $e$ into $R_2$

Subtract $R_1$ from $R_2$

Move $a$ into $R_1$

Add $b$ to $R_1$

Subtract $R_1$ from $R_2$

Store the result in memory via a move operation.

Total: 4.
yes

For CASE 1 and CASE 2 Assembly language code

1 comment

How u r counting an add operation as a MOV operation.

Answer will be None of the options

Explanation:

Please refer the question number 51 here. I am also attaching the image file containing the explanation

Hi @nkg_master9 ! In case -1 when you see instruction SUB R1 , R2 [t1-t2] , please see the contents of R2 here and compare with what is given in question. You were going good the whole process but here is what i think it's incorrect. Correct me if i am wrong. Waiting for your response. Thanking you in advance.

Option D where case 1 involves 3 MOV.

1
2,824 views