Instructions & Addressing Modes
![Question 71, GATE 2007: R1,R2,R3 are general-purpose registers. The program, operation, and size in words are:
MOV R1,(3000): R1←M[3000], 2 words
LOOP: MOV R2,(R3): R2←M[R3], 1 word
ADD R2,R1: R2←R1+R2, 1 word
MOV (R3),R2: M[R3]←R2, 1 word
INC R3: R3←R3+1, 1 word
DEC R1: R1←R1−1, 1 word
BNZ LOOP: branch if the result is nonzero, 2 words
HALT: stop, 1 word.
Initially M[3000]=10, R3=2000 and each location 2000–2010 contains 100. The program begins at location 1000; all these numbers are decimal.
Assume word-addressable memory. How many data-memory references occur while running the whole program?
Options:
(A) 10
(B) 11
(C) 20
(D) 21](../../assets/questions/CS-2007-Q71-1.webp)
![Question 71, GATE 2007: R1,R2,R3 are general-purpose registers. The program, operation, and size in words are:
MOV R1,(3000): R1←M[3000], 2 words
LOOP: MOV R2,(R3): R2←M[R3], 1 word
ADD R2,R1: R2←R1+R2, 1 word
MOV (R3),R2: M[R3]←R2, 1 word
INC R3: R3←R3+1, 1 word
DEC R1: R1←R1−1, 1 word
BNZ LOOP: branch if the result is nonzero, 2 words
HALT: stop, 1 word.
Initially M[3000]=10, R3=2000 and each location 2000–2010 contains 100. The program begins at location 1000; all these numbers are decimal.
Assume word-addressable memory. How many data-memory references occur while running the whole program?
Options:
(A) 10
(B) 11
(C) 20
(D) 21](../../assets/questions/CS-2007-Q71-2.webp)
Answer & solution
Answer: D (no official key was published)
1. Approach. R1 is the countdown and starts at ten. Separate instruction fetches from data accesses: only the initial load and the two memory-operand MOVs inside each iteration count.
2. Derivation and interpretation. The initial MOV reads M[3000] once and sets R1=10. Each of 10 iterations reads M[R3] once and writes it once. All other operand operations are on registers; instruction fetches are not data references. Total data memory references = 1+10*2=21, option D.