The Gateway to Computer Science Excellence
+21 votes
2.4k views

Consider the following program segment. Here $\text{R1, R2}$ and $\text{R3}$ are the general purpose registers.
$$\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]} & \text{$2$}
\\\hline \text{LOOP:}& \text{MOV R2,(R3)} & \text{R2} \leftarrow \text{M[R3]} & \text{$1$}
\\\hline & \text{ADD R2,R1} & \text{R2} \leftarrow \text{R1 + R2} & \text{$1$}
\\\hline & \text{MOV (R3),R2} & \text{M[R3]} \leftarrow \text{R2} & \text{$1$}
\\\hline& \text{INC R3} & \text{R3} \leftarrow \text{R3 + 1} & \text{$1$}
\\\hline & \text{DEC R1} & \text{R1} \leftarrow \text{R1 – 1} & \text{$1$}
\\\hline& \text{BNZ LOOP} & \text{Branch on not zero} & \text{$2$}
\\\hline & \text{HALT} & \text{Stop} & \text{$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$
in CO and Architecture by Veteran (104k points)
edited by | 2.4k views
0

4 Answers

+33 votes
Best answer

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$

by Active (4.7k points)
edited by
0
what  is meaning of BNZ ?On which register it should apply ? how did we know it?
0
This checks result of prev but one instruction, so R1 applies here
+23 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.
by Active (5k points)
0
plz explain...how loop executed??
+1 vote
Answer is 100.because loop is terminated when address is 2009
by Junior (801 points)
–3 votes

Ist memory reference R1←M[3000] and then in the loop which runs for 10 times, because the content of memory location 3000 is 10 given in question and loop will run 10 times as

R2← M[R3]

M[R3] ←R2

There are two memory reference every iteration

10*2=20

Total=20+1=21

So  (D) is correct option.

http://www.geeksforgeeks.org/gate-gate-cs-2007-question-71/

by (169 points)
0
Why loop executed 10 times????

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,650 questions
56,242 answers
194,288 comments
95,938 users