GATE / CS ARCHIVE

GATE CSE 2021 SET 1 / QUESTION 55

GATE CSE 2021 Set 1 Q55

Computer Organization & Architecture · Instructions & Addressing Modes · Full GATE CSE 2021 Set 1 paper

GATE 2021 Set 1, Q55 2 marks · NAT
Report issue

Instructions & Addressing Modes

Question 55, GATE 2021: A byte-addressable machine starts this sequence at address 1000. Instruction, semantics, size in bytes: MOV R1,(5000): R1=MEMORY[5000],4; MOV R2,(R3): R2=MEMORY[R3],4; ADD R2,R1: R2=R1+R2,2; MOV (R3),R2: MEMORY[R3]=R2,4; INC R3: R3=R3+1,2; DEC R1: R1=R1−1,2; BNZ 1004: branch to absolute address 1004 if not zero,2; HALT: stop,1. Initially MEMORY[5000]=10, R3=3000, and MEMORY[3000] through MEMORY[3010] are all 50. All numbers are decimal. Find MEMORY[3010] after execution.
Tap to enlarge
Answer & solution

Official answer: 50

The four-byte first instruction at address 1000 initializes R1=10, and address 1004 is the next instruction, the loop entry. Each loop iteration updates MEMORY[R3], then increments R3 and decrements R1. BNZ tests the zero condition left by that decrement and returns to 1004 while R1 is nonzero. Exactly ten iterations update locations 3000 through 3009. After the tenth, R3 is 3010 and R1 is zero, so the program halts before writing location 3010. Its original value 50 is unchanged.

Instruction addresses are 1000,1004,1008,1010,1014,1016,1018,1020. Thus branching to 1004 skips the initialization at 1000. At iteration k=1,...,10 the address updated is 2999+k and R1 before decrement is 11−k, so memory values written are 60,59,...,51 at 3000,...,3009. The final increment makes R3=3010, but DEC makes R1=0 and the branch falls through to HALT. Merely pointing at 3010 does not write to it.

Original paper, page 41 · Answer key