Return address after interrupting INC
Input/Output, DMA & Interrupts
![Question 73, GATE 2007: R1,R2,R3 are general-purpose registers. The program, operation, and size in words are:
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: branch if the result is nonzero, 2 words
HALT: stop, 1 word.
Initially M[3000]=10, R3=2000 and each location 2000–2010 contains 100. The program begins at location 1000; all these numbers are decimal.
Now assume byte-addressable memory and 32-bit words. If an ordinary interrupt occurs while INC R3 executes, what return address is pushed onto the stack?
Options:
(A) 1005
(B) 1020
(C) 1024
(D) 1040](../../../assets/questions/CS-2007-Q73-1.webp)
![Question 73, GATE 2007: R1,R2,R3 are general-purpose registers. The program, operation, and size in words are:
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: branch if the result is nonzero, 2 words
HALT: stop, 1 word.
Initially M[3000]=10, R3=2000 and each location 2000–2010 contains 100. The program begins at location 1000; all these numbers are decimal.
Now assume byte-addressable memory and 32-bit words. If an ordinary interrupt occurs while INC R3 executes, what return address is pushed onto the stack?
Options:
(A) 1005
(B) 1020
(C) 1024
(D) 1040](../../../assets/questions/CS-2007-Q73-2.webp)
Answer & solution
Answer: C (no official key was published)
1. Approach. Sum instruction lengths through the completed INC, multiply by four bytes per word, and add the program base. An ordinary interrupt resumes at the next instruction, not at the interrupted instruction’s starting address.
2. Derivation and interpretation. Instructions up through INC occupy 2+1+1+1+1=6 words. At 4 bytes per word, the next instruction DEC R1 is at byte address 1000+6*4=1024. An ordinary interrupt is serviced after the current instruction completes and saves the next instruction address, so C. The INC itself starts at 1020.
![Question 63, GATE 2004: A CPU has user registers R1,R2,R3. Program in order (operation; instruction size in words): MOV R1,5000 (R1←Memory[5000];2); MOV R2,(R1) (R2←Memory[R1];1); ADD R2,R3 (R2←R2+R3;1); MOV 6000,R2 (Memory[6000]←R2;2); HALT (machine halts;1). Memory is byte-addressable with 32-bit words and the program starts at decimal 1000. If an interrupt occurs after HALT has executed, what decimal return address is saved on the stack?
Options:
(A) 1007
(B) 1020
(C) 1024
(D) 1028](../../../assets/questions/CS-2004-Q63-1.webp)
![Question 63, GATE 2004: A CPU has user registers R1,R2,R3. Program in order (operation; instruction size in words): MOV R1,5000 (R1←Memory[5000];2); MOV R2,(R1) (R2←Memory[R1];1); ADD R2,R3 (R2←R2+R3;1); MOV 6000,R2 (Memory[6000]←R2;2); HALT (machine halts;1). Memory is byte-addressable with 32-bit words and the program starts at decimal 1000. If an interrupt occurs after HALT has executed, what decimal return address is saved on the stack?
Options:
(A) 1007
(B) 1020
(C) 1024
(D) 1028](../../../assets/questions/CS-2004-Q63-2.webp)
![Question 63, GATE 2004: A CPU has user registers R1,R2,R3. Program in order (operation; instruction size in words): MOV R1,5000 (R1←Memory[5000];2); MOV R2,(R1) (R2←Memory[R1];1); ADD R2,R3 (R2←R2+R3;1); MOV 6000,R2 (Memory[6000]←R2;2); HALT (machine halts;1). Memory is byte-addressable with 32-bit words and the program starts at decimal 1000. If an interrupt occurs after HALT has executed, what decimal return address is saved on the stack?
Options:
(A) 1007
(B) 1020
(C) 1024
(D) 1028](../../../assets/questions/CS-2004-Q63-3.webp)