GATE / CS ARCHIVE

SIMILAR QUESTIONS / COMPUTER ORGANIZATION & ARCHITECTURE

Compute the byte address saved on interrupt entry

2 questions solved the same way, newest first. Back to Computer Organization & Architecture

How these are solved

Sum instruction sizes from the program start, converting 32-bit instruction words to bytes, and save the next-instruction PC after the current instruction completes. HALT-completed versus interrupt-during-INC endpoints differ.

2 marks · MCQ
Report issue

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
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
Tap to enlarge
Your answer
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.

Original paper, page 18

2 marks · MCQ
Report issue

Interrupt return address after halt

Input/Output, DMA & Interrupts

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
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
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
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. The five instructions occupy 2+1+1+2+1=7 words. Each word is 32 bits=4 bytes, so the program occupies 28 bytes starting at 1000.

2. Under the ordinary next-instruction-PC convention, after fetching/executing HALT the saved return address is 1000+28=1028. HALT itself begins at 1024;1007 would confuse word and byte addressing.

3. Teaching check: Instruction start addresses are 1000,1008,1012,1016,1024. HALT occupies one four-byte word, so the next sequential address is 1028. Saving 1024 would resume at HALT itself; saving 1007 wrongly treats byte-addressed memory as word-addressed.

Original paper, page 9