edited by
9,356 views
35 votes
35 votes

Consider the following program segment. Here $\text{R1, R2}$ and $\text{R3}$ are the general purpose registers.
$$\small \begin{array}{|c|l|l||c|} \hline & \text {Instruction} &  \text{Operation }& \text{Instruction Size} 
\\ & & & \text{(no. of words)} \\\hline & \text{MOV R1,(3000)} & \text{R1} \leftarrow \text{M[3000]} & 2
\\\hline \text{LOOP:}& \text{MOV R2,(R3)} & \text{R2} \leftarrow \text{M[R3]} & 1
\\\hline & \text{ADD R2,R1} & \text{R2} \leftarrow \text{R1 + R2} & 1
\\\hline & \text{MOV (R3),R2} & \text{M[R3]} \leftarrow \text{R2} & 1
\\\hline& \text{INC R3} & \text{R3} \leftarrow \text{R3 + 1} & 1
\\\hline & \text{DEC R1} & \text{R1} \leftarrow \text{R1 – 1} & 1
\\\hline& \text{BNZ LOOP} & \text{Branch on not zero} & 2
\\\hline & \text{HALT} & \text{Stop} & 1
\\\hline\end{array}$$

Assume that the content of memory location $3000$ is $10$ and the content of the register $\text{R3}$ is $2000$. The content of each of the memory locations from $2000$ to $2010$ is $100$. The program is loaded from the memory location $1000$. All the numbers are in decimal.

Assume that the memory is word addressable. After the execution of this program, the content of memory location $2010$ is:

  1. $100$
  2. $101$
  3. $102$
  4. $110$
edited by

5 Answers

Best answer
60 votes
60 votes

The loop runs $10$ times.

  1. When $R1=10 , \text{Memory}[2000] = 110,$
  2. When $R1=9 , \text{Memory}[2001] = 109,$
  3. When $R1=8 , \text{Memory}[2002] = 108,$
  4. When $R1=7 , \text{Memory}[2003] = 107,$
  5. When $R1=6 , \text{Memory}[2004] = 106,$
  6. When $R1=5 , \text{Memory}[2005] = 105,$
  7. When $R1=4 , \text{Memory}[2006] = 104,$
  8. When $R1=3 , \text{Memory}[2007] = 103,$
  9. When $R1=2 , \text{Memory}[2008] = 102,$
  10. When $R1=1 , \text{Memory}[2009] = 101,$


When $R1=0$ the loop breaks., $\text{Memory}[2010]= 100$

Correct Answer: $A$

edited by
32 votes
32 votes
The loop is executed 10 times and it modifies the contents from memory location 2000-2009. Memory location 2010 is untouched - contains 100 as before.
9 votes
9 votes

Answer : A

R1 = 10

initial 2000-2010

100 100 100 100 100 100 100 100 100 100 100

2000     2001    2002    2003    2004     2005        2006       2007    2008      2009     2010

1. R1 = 10 , R2 = M[R3]= 100 , R2=R1+R2=110 , R3=2000 , M[2000] = R2=110 , R3 = 2000+1 = 2001

2. R1 = 9 , R2 = M[R3]= 100 , R2=R1+R2=109 , R3=2001 , M[2001] = R2=109 , R3 = 2001 + 1 = 2002 

3. R1 = 8 , R2 = M[R3]= 100 , R2=R1+R2=108 , R3=2002 , M[2002] = R2=108 ,  R3 = 2002 + 1 = 2003 

4. R1 = 7 , R2 = M[R3]= 100 , R2=R1+R2=107 , R3=2003 , M[2003] = R2=107 , R3 = 2003 + 1 = 2004  

5. R1 = 6 , R2 = M[R3]= 100 , R2=R1+R2=106 , R3=2004 , M[2004] = R2=106  , R3 = 2004 + 1 = 2005 

6. R1 = 5 , R2 = M[R3]= 100 , R2=R1+R2=105 , R3=2005 , M[2005] = R2=105   , R3 = 2005 + 1 = 2006 

7. R1 = 4 , R2 = M[R3]= 100 , R2=R1+R2=104 , R3=2006 , M[2006] = R2=104   , R3 = 2006 + 1 = 2007 

8. R1 = 3 , R2 = M[R3]= 100 , R2=R1+R2=103 , R3=2007 , M[2007] = R2=103   , R3 = 2008 + 1 = 2009 

9. R1 = 2 , R2 = M[R3]= 100 , R2=R1+R2=102 , R3=2008 , M[2008] = R2=102    , R3 = 2009 + 1 = 2010 

10. R1 = 1, R2 = M[R3]= 100 , R2=R1+R2=101 , R3=2009 , M[2009] = R2=101 , R3 = 2010 + 1 = 2011

10. R1 = 0 HALT

Final

110 109 108 107 106 105 104 103 102 101 100

 2000   2001  2002 2003    2004   2005      2006      2007      2008      2009      2010

 

edited by
Answer:

Related questions

30 votes
30 votes
2 answers
1
go_editor asked Apr 23, 2016
9,841 views
Consider the following program segment. Here $\text{R1, R2}$ and $\text{R3}$ are the general purpose registers.$$\begin{array}{|l|l|l|c|} \hline & \text {Instruction} & \...
54 votes
54 votes
5 answers
2
Kathleen asked Sep 21, 2014
21,900 views
Consider the following program segment. Here $\text{R1, R2}$ and $\text{R3}$ are the general purpose registers.$$\begin{array}{|l|l|l|c|} \hline & \text {Instruction} & \...
54 votes
54 votes
7 answers
3
Kathleen asked Sep 21, 2014
13,363 views
In a simplified computer the instructions are:$$\begin{array}{|l|l|} \hline \text {OP }R _j , R _i & \text{Perform }R _j \text{ OP } R _i \text{ and store the result in r...