The Gateway to Computer Science Excellence
+32 votes
6.2k 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} & \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. The number of memory references for accessing the data in executing the program completely is

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

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

+3
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
+1
What the ans, if we consider the memory reference because of instructions also?

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

@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.

0

Other question in sequence

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

0
@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)
+2

 programs can access memory, which means they read data from or write data to the main memory.

That is the reason for considering accessing data for even storing the values in main memory

0

what is the meaning of bracket () here ??

MOV R1,(3000)
MOV R2,(R3)

 Is the content of 3000/R3 memory location moving into the register R1/R2 ??

+1
Bracket means indirect addressing or memory based addressing

3 Answers

+33 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$

Correct Answer: $D$

by Active (5k points)
edited by
+7
Or I think they are asking number of memory access for data means how many times the program is using memory for data... therefore 21
0

Here, address of INC, R3 = 2000 + (2 + 1 + 1 + 1) * 32/8 = 2020 pls explain little bit more ? 

+1
1000 - 1007 // one byte take 8 bit .. so 32 bit= 4byte

1011

1015

1019

1023

1024 -1029 since starting address is stored in stack so ans is 1024
0

why this alone took "1000 - 1007 // one byte " one byte remaining all took 4-bit ?

+1

8 bits 1 byte 

so for 32 bits = 4 bytes. data access as byte b/c given byte addressable.

if 1 word then 1000, 1001 , 1002, 1003 are taken .

0
@anurag

Location       Operation

1000-1007     R1 <- M[3000] ( 8  bytes)

1008-1011    R2 <- M[R3] (4 bytes)

1012-1015    R2 <-R1 + R2 ( 4 bytes)

1016-1019    M[R3]<-R2 ( 4 bytes)

1020-1023    R3<-R3 +1 (4 bytes)

And PC will be 1024 right ?
+1
Yes, that's correct and after executing INC R3, Interrupt will be serviced & 1024 will be pushed onto the stack.
+1
Thank you so much. +1K votes for you
0
Starting location is 1000 so ans for 73 will be 1024 right?
+1
Answer should be 21....

Correct me if I'm wrong
0
answer should be 21, 1 m/m reference initially and 20 i for loop, i believe 20 is wrong answer given in selected best solution
0
memory reference outside of loop is 1 why u havent added it ?
+3
@Arjun sir look here 21 is answer?
0
sir plz clear my confusion why not to take that value ?
+2
i will be included but why they not include is not known ! wait for response from arjun ji
0
@arjun sir , Why it is not 21 ?
0
yes, its 21.
0
thx :)
0
why not 20+2
+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

+3

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

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

0

@VS

 programs can access memory, which means they read data from or write data to the main memory.

That is the reason for considering accessing data for even storing the values in main memory

+2

One silly doubt.. 

BNZ LOOP Branch on not zero

How do we know which register to check for condition BNZ?

+1
the result of the condition code register (zero flag)of ALU is checked on branch and the immediate instruction altering its value is R1=R1-1.
+11 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

by Boss (10k points)
+6

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

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

0
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.
0
@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.
0
I cannot understand how loop runs 10 times..
please explain
+1

@shipra tressa
R1 is 10 initially and then r1 is decremented by 1 and BNZ will not return true till the immediate value isn't 0;
 so 10,9,8 till 0

 

0

@Aari did your doubt got resolved?
I have same doubt after reading your comment:o

0 votes
Answer is 21
by Junior (799 points)

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,645 questions
56,597 answers
195,837 comments
102,138 users