Skip to content
Official PYQ · 2021

GATE CS 2021 Set 1 Q55 — Machine Instructions and Addressing Modes

Explain with AI
Consider the following instruction sequence where registers R1,R2\text{R1}, \text{R2} and R3\text{R3} are general purpose and MEMORY[X]\text{MEMORY[X]} denotes the content at the memory location X.\text{X}.

InstructionSemanticsInstruction Size (bytes)MOV R1,(5000)R1←MEMORY[5000]4MOV R2,(R3)R2←MEMORY[R3]4ADDR2,R1R2←R1+R22MOV (R3),R2MEMORY[R3]←R24INC R3R3←R3+12DEC R1R1←R1−12BNZ 1004Branch if not zero to the2given absolute addressHALTStop1\begin{array}{llc} \textbf{Instruction} & \textbf{Semantics} & \textbf{Instruction Size} \text{ (bytes)} \\ \hline \text{MOV } \text{R1}, (5000) & \text{R1} \leftarrow \text{MEMORY}[5000] & 4 \\ \hline \text{MOV } \text{R2}, (\text{R3}) & \text{R2} \leftarrow \text{MEMORY[R3]} & 4 \\ \hline \text{ADD} \text{R2}, \text{R1} & \text{R2} \leftarrow \text{R1} + \text{R2} & 2 \\ \hline \text{MOV } (\text{R3}), \text{R2} & \text{MEMORY[R3]} \leftarrow \text{R2} & 4 \\ \hline \text{INC } \text{R3} & \text{R3} \leftarrow \text{R3}+1 & 2 \\ \hline \text{DEC } \text{R1} & \text{R1} \leftarrow \text{R1}-1 & 2 \\ \hline \text{BNZ } 1004 & \text{Branch if not zero to the} & 2 \\ & \text{given absolute address}& \\ \hline \text{HALT} & \text{Stop} & 1 \\ \hline \end{array}

Assume that the content of the memory location 50005000 is 1010, and the content of the register R3\text{R3} is 30003000. The content of each of the memory locations from 30003000 to 30203020 is 5050. The instruction sequence starts from the memory location 10001000. All the numbers are in decimal format. Assume that the memory is byte addressable.

After the execution of the program, the content of memory location 30103010 is ____________
View worked solution

Answer: 50 : 50

To find the content of memory location 30103010 after execution, let us first determine the instruction addresses based on their sizes starting from address 10001000:

  • 1000: MOV R1, (5000) (4 bytes)
  • 1004: MOV R2, (R3) (4 bytes)
  • 1008: ADD R2, R1 (2 bytes)
  • 1010: MOV (R3), R2 (4 bytes)
  • 1014: INC R3 (2 bytes)
  • 1016: DEC R1 (2 bytes)
  • 1018: BNZ 1004 (2 bytes)
  • 1020: HALT (1 byte)

Before the loop starts, we have:

  • R1=MEMORY[5000]=10R1 = \text{MEMORY}[5000] = 10
  • R3=3000R3 = 3000

The loop at address 10041004 executes as long as R1≠0R1 \neq 0. In each iteration kk (from 11 to 1010):

  1. The value at MEMORY[R3]\text{MEMORY}[R3] is read into R2R2.
  2. R2R2 is updated to R1+R2R1 + R2.
  3. The updated value of R2R2 is written back to MEMORY[R3]\text{MEMORY}[R3].
  4. R3R3 is incremented by 11.
  5. R1R1 is decremented by 11.

Tracing the memory updates and register values at the end of each iteration:

  • Iteration 1: Updates MEMORY[3000]\text{MEMORY}[3000]. R3R3 becomes 30013001, R1R1 becomes 99.
  • Iteration 2: Updates MEMORY[3001]\text{MEMORY}[3001]. R3R3 becomes 30023002, R1R1 becomes 88.
  • …\dots
  • Iteration 10: Updates MEMORY[3009]\text{MEMORY}[3009]. R3R3 becomes 30103010, R1R1 becomes 00.

At the end of the 10th10^{\text{th}} iteration, since R1=0R1 = 0, the loop condition for BNZ 1004 fails, and the program halts. Thus, the memory location 30103010 is never modified, and its content remains at its initial value of 50.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Machine Instructions and Addressing Modes questions