Skip to content
Official PYQ · 2007

GATE CS 2007 Q71 — I/O Interface: Interrupt and DMA Mode

Explain with AI

Consider the following program segment. Here R1, R2\text{R1, R2} and R3\text{R3} are the general purpose registers.
InstructionOperation Instruction Size(no. of words)MOV R1,(3000)R1←M[3000]2LOOP:MOV R2,(R3)R2←M[R3]1ADD R2,R1R2←R1 + R21MOV (R3),R2M[R3]←R21INC R3R3←R3 + 11DEC R1R1←R1 – 11BNZ LOOPBranch on not zero2HALTStop1\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 30003000 is 1010 and the content of the register R3\text{R3} is 20002000. The content of each of the memory locations from 20002000 to 20102010 is 100100. The program is loaded from the memory location 10001000. 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

Choose one option
View worked solution

Answer: D

To find the number of memory references for accessing the data, we only count the memory read and write operations performed on data operands (excluding instruction fetches).

1. Instruction Outside the Loop

  • MOV R1, (3000): This instruction reads the data from memory location 3000 and loads it into register R1.
    Data memory references = 1 (Read operation).

After this instruction, the value in register R1 becomes 10.

2. Loop Execution

The loop starts at the label LOOP and ends with BNZ LOOP. Since R1 is initialized to 10 and decremented by 1 in each iteration (DEC R1), the loop will execute exactly 10 times.

Let's analyze the data memory references inside one iteration of the loop:

  1. MOV R2, (R3): Reads data from the memory location pointed to by R3.
    Data memory references = 1 (Read operation).
  2. ADD R2, R1: Register-to-register operation.
    Data memory references = 0.
  3. MOV (R3), R2: Writes data to the memory location pointed to by R3.
    Data memory references = 1 (Write operation).
  4. INC R3: Register operation.
    Data memory references = 0.
  5. DEC R1: Register operation.
    Data memory references = 0.
  6. BNZ LOOP: Branch instruction (control transfer).
    Data memory references = 0.

Thus, each iteration of the loop performs exactly 1+1=21 + 1 = 2 data memory references.

3. Total Data Memory References

Total References=References outside loop+(References per iteration×Number of iterations)=1+(2×10)=21\begin{align*} \text{Total References} &= \text{References outside loop} + (\text{References per iteration} \times \text{Number of iterations}) \\ &= 1 + (2 \times 10) \\ &= 21 \end{align*}

Therefore, the total number of memory references for accessing the data is 21.

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

Published
Report a correction
Keep exploringMore I/O Interface: Interrupt and DMA Mode questions