Project ForgeSign up free
Computer Organization & Architecture
Pipelining & Instruction Sets
GATE 2007
Expert

Consider the following program segment (R1, R2, R3 are general purpose registers): 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 [2 words]; HALT [1 word]. Assume M[3000]=10, R3=2000, and M[2000..2010]=100 each, all decimal. Assume memory is word addressable. The number of memory references for accessing the data in executing the program completely is

  • A10
  • B11
  • C20
  • 21

Explanation

1 data reference for the initial MOV R1,(3000). R1 starts at 10 and DEC'd each iteration until it reaches 0, so the loop runs exactly 10 iterations. Each iteration does 1 read (MOV R2,(R3)) + 1 write (MOV (R3),R2) = 2 data references. Total = 1 + 10×2 = 21.

Source: GATE CS 2007 (2007)

This question is part of a 15-day revision cycle — sign in and Project Forge will bring it back the day before you'd forget it.

Start revising free