Similar questions 1 more →
Instructions & Addressing Modes
![Question 72, 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. What is the final content of location 2010?
Options:
(A) 100
(B) 101
(C) 102
(D) 110](../../assets/questions/CS-2007-Q72-1.webp)
![Question 72, 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. What is the final content of location 2010?
Options:
(A) 100
(B) 101
(C) 102
(D) 110](../../assets/questions/CS-2007-Q72-2.webp)
Answer & solution
Answer: A (no official key was published)
1. Approach. Track the address used before INC R3, not after it. The first iteration uses 2000; after ten iterations R3 reaches 2010 only when the loop is about to terminate.
2. Derivation and interpretation. R3 starts at 2000. The 10 loop iterations access addresses 2000 through 2009, then R3 becomes 2010 and R1 becomes zero, ending the loop. Address 2010 is never written, so its initial content 100 remains. Answer A.