Question:

Consider the following instruction sequence where registers \( R1 \), \( R2 \), and \( R3 \) are general purpose and MEMORY[X] denotes the content at the memory location \( X \): 
\[\begin{array}{|l|l|c|} \hline \textbf{Instruction} & \textbf{Semantics} & \textbf{Instruction Size (bytes)} \\ \hline \text{MOV R1, (5000)} & \text{\( R1 \leftarrow \text{MEMORY}[5000] \)} & \text{4} \\ \hline \text{MOV R2, (R3)} & \text{\( R2 \leftarrow \text{MEMORY}[R3] \)} & \text{4} \\ \hline \text{ADD R2, R1} & \text{\( R2 \leftarrow R1 + R2 \)} & \text{2} \\ \hline \text{MOV (R3), R2} & \text{\( \text{MEMORY}[R3] \leftarrow R2 \)} & \text{4} \\ \hline \text{INC R3} & \text{\( R3 \leftarrow R3 + 1 \)} & \text{2} \\ \hline \text{DEC R1} & \text{\( R1 \leftarrow R1 - 1 \)} & \text{2} \\ \hline \text{BNZ 1004} & \text{Branch if not zero to the given absolute address} & \text{2} \\ \hline \text{HALT} & \text{Stop} & \text{1} \\ \hline \end{array}\]Assume that the content of memory location 5000 is 10, and the content of register \( R3 \) is 3000. The content of each of the memory locations from 3000 to 3010 is 50. The instruction sequence starts from memory location 1000. All numbers are in decimal format and the memory is byte addressable. 
After the execution of the program, the content of memory location 3010 is \(\underline{\hspace{2cm}}\).

Show Hint

Always track loop bounds carefully to determine exactly which memory locations are updated.
Updated On: Jan 2, 2026
Hide Solution
collegedunia
Verified By Collegedunia

Correct Answer: 50

Solution and Explanation

Step 1: Initialization.
From the first instruction:
\[ R1 = \text{MEMORY}[5000] = 10 \] Given initially:
\[ R3 = 3000 \] Memory locations from 3000 to 3010 each contain 50.

Step 2: Identify loop structure.
The instruction \texttt{BNZ 1004} causes the program to loop back as long as \( R1 \neq 0 \).
Since \( R1 \) starts at 10 and is decremented once per iteration, the loop runs exactly 10 times.

Step 3: Effect of one loop iteration.
In each iteration:
- MEMORY[\( R3 \)] is read into \( R2 \)
- \( R1 \) is added to \( R2 \)
- The result is stored back into MEMORY[\( R3 \)]
- \( R3 \) is incremented by 1
- \( R1 \) is decremented by 1
Thus, memory locations modified are:
\[ 3000, 3001, \dots, 3009 \]

Step 4: Analyze memory location 3010.
The loop updates only the first 10 locations starting from 3000.
Memory location 3010 is never accessed or modified.

Step 5: Final value.
Since MEMORY[3010] was initially 50 and never changed:
\[ \text{MEMORY}[3010] = 50 \] % Final Answer

Final Answer: \[ \boxed{50} \]

Was this answer helpful?
0
0

Questions Asked in GATE CS exam

View More Questions