in CO and Architecture edited by
4,449 views
6 votes
6 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
4.4k views

4 Comments

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
is this in gate syllabus 2024??
0
0

5 Answers

1 vote
1 vote

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.  

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

Case 1:

  1. t1 = a + b
    • R1 ← a , MOV
    • R1 = R1 + b, ADD
  2. t2 = c + d
    • R2 ← c, MOV
    • R2 = R2 + d, ADD
  3. t3 = e – t2
    • MEM[X] ← R1, MOV (store result t1 in memory)
    • R1 = e – R2, SUB
  4. t4 = t1 – t2
    • R1 = MEM[X] – R2, SUB
  5. Store the result
    • MEM[Y] ← R1, MOV

Case 2:

  1. t2 = c + d
    • R1 ← c, MOV
    • R1 = R1 + d, ADD
  2. t3 = e – t2
    • R2 = e – R1, SUB
  3. t1 = a + b
    • R2 ← a, MOV
    • R2 = R2 + b, ADD
  4. t4 = t1 – t2
    • R1 = R2 – R1, SUB
  5. Store result
    • MEM[Y] ← R1, MOV

 

 

Answer:

Related questions