(i) both operands in registers (AND/OR)

(ii) one in register and other in memory

Dark Mode

2,186 views

5 votes

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?

- $\text{Case 2,2}$
- $\text{Case 2,3}$
- $\text{Case 1,2}$
- $\text{Case 1,3}$

0

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.

1

0 votes

Answer will be None of the options

Explanation:

https://solutionsadda.in/isro-cs-2020/ques?questionid=8922&quiz_name=ISRO%20CS%202020

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

In case -1 when you see instruction

Correct me if i am wrong. Waiting for your response.

Thanking you in advance.

0