The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+22 votes
3.1k views

Consider the following program segment. Here R1, R2 and R3 are the general purpose registers.

  Instruction Operation Instruction size (no. of words)
  MOV R1, (3000) R1 $\leftarrow$ m[3000] 2
LOOP: MOV R2, (R3) R2 $\leftarrow$ M[R3] 1
  ADD R2, R1 R2 $\leftarrow$ R1 + R2 1
  MOV (R3), R2 M[R3] $\leftarrow$ R2 1
  INC R3 R3 $\leftarrow$ R3 +1 1
  DEC R1 R1 $\leftarrow$ R1 - 1 1
  BNZ LOOP Branch on not zero 2
  HALT Stop 1

Assume that the content of memory location 3000 is 10 and the content of the register 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. The number of memory references for accessing the data in executing the program completely is

  1. 10
  2. 11
  3. 20
  4. 21
asked in CO & Architecture by Veteran (69k points)
edited by | 3.1k views
In this question why haven't we have c onsidered memory references for instruction Fetch and Instruction Decode............

plzz read qustion carefully "The number of memory references for accessing the data in executing the program completely "

why we are counting MOV (R3), R2 as part of accessing the data instruction.It is simple storing and also later this value of memory we are not using.. :O
What the ans, if we consider the memory reference because of instructions also?

Is it 94? Please confirm and explain your answer.
@reena I also have same doubt that it should be 11 and not 21...please help

@gari, Language of CO's qsns is always seems  ambiguous to me.Question will be very easy but what they exactly want to ask by their wording is hard to interpret.Here also same thing is happening .

we access memory only for two reasons either to access the data or storing back it there.Here it is clearly asked memory reference for accessing the data.So, I think answer should be $11$

@Arjun sir can you plz help here.

Other question in sequence

https://gateoverflow.in/43516/gate2007-73

@reena

 inside loop there are 2 memory reference

isnot it?

1) R2 ← M[R3]

2) M[R3] ← R2

So, 2 memory reference inside loop

Where is ur problem

it will be 2*10(inside loop)+1(outside loop)

3 Answers

+22 votes
Best answer

Loop is executed $10$ times and there are two memory reference in the loop (each MOV
is loading $1$ word, so $1$ memory reference for each MOV inside the loop). So number
of memory reference inside loop is

$2 \text{(MOV)}\times 10\text{ (times iteration)}\times 1\text{(1 word access/ MOV)}
=20\text{ memory accesses.}$

One memory access is outside the loop for the first instruction

MOV R1, (3000)

So, totally $20+1 = 21$

answered by Boss (5.2k points)
edited by
memory reference outside of loop is 1 why u havent added it ?
@Arjun sir look here 21 is answer?
sir plz clear my confusion why not to take that value ?
i will be included but why they not include is not known ! wait for response from arjun ji
@arjun sir , Why it is not 21 ?
yes, its 21.
thx :)
why not 20+2

bcoz size of instruction is 2 word bt size of memory operand is of 1 word 
if u r fetching instruction= 2 mem ref
fetching operand= 1 mem ref

But the question says number of memory references for accessing the data.

Should not we ignore STORE instruction and anss should be 11 ?

+8 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

So total memory access will be 21

answered by Boss (8.4k points)

But the question says number of memory references for accessing the data.

Should not we ignore STORE instruction and anss should be 11 ?

forr accessing the data you need that stored value of R2 in loop so it must also be included.

R2<-M[R3]

M[R3]<-R2

so it must be 21.
@Prerna , for accessing the data why we need that stored value of R2 in loop ?

R2<-M[R3]

M[R3]<-R2

 R3 is being incremented every time and a memory location from 2000 to 2009 is accessed just once.
+2 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

answered by Boss (8.6k points)
Answer:

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

33,646 questions
40,193 answers
114,178 comments
38,665 users