in CO and Architecture edited by
2,186 views
5 votes
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?

  1. $\text{Case 2,2}$
  2. $\text{Case 2,3}$
  3. $\text{Case 1,2}$
  4. $\text{Case 1,3}$
in CO and Architecture edited by
by
2.2k views

4 Comments

Question should state whether operations accept:
(i) both operands in registers (AND/OR)
(ii) one in register and other in memory
0
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
1
yes
0
0

3 Answers

0 votes
0 votes

For CASE 1 and CASE 2 Assembly language code

1 comment

How u r counting an add operation as a MOV operation.
0
0
0 votes
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

 

1 comment

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.  

0
0
0 votes
0 votes
Option D where case 1 involves 3 MOV.
Answer:

Related questions

4 votes
4 votes
4 answers
3