edited by
9,840 views
30 votes
30 votes

Consider the following program segment. Here $\text{R1, R2}$ and $\text{R3}$ are the general purpose registers.

$$\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 $3000$ is $10$ and the content of the register $\text{R3}$ is $2000.$ The content of each of the memory locations from $2000$ to $2010$ is $100.$ The program is loaded from the memory location $1000.$ All the numbers are in decimal.

Assume that the memory is byte addressable and the word size is $32$ bits. If an interrupt occurs during the execution  of the instruction “INC R3”, what return address will be pushed on to the stack?

  1. $1005$
  2. $1020$
  3. $1024$
  4. $1040$
edited by

2 Answers

Best answer
50 votes
50 votes

An interrupt is checked for after the execution of the current instruction and the contents of PC
(address of next instruction to be executed) is pushed on to stack.
Here, address of INC, R3 $= 1000 +\dfrac{ (2 + 1 + 1 + 1) \times 32}{8} = 1020$ and
next instruction address $= 1020 + 4 = 1024$  which is pushed on to stack. 
Reference: http://www.ece.utep.edu/courses/web3376/Notes_files/ee3376-interrupts_stack.pdf

Correct Answer: $C$

edited by
34 votes
34 votes

If memory is byte addressable so for each instruction it requires 1 word that is equal to 4 bytes which require 4 addresses

Instruction Word location
MOV R1,3000 2 1000-1007
MOV R2,R1 1 1008-1011
ADD R2,R1 1 1012-1015
MOV(R3),R2 1 1016-1019
INC R3 1 1020-1023
DEC R1 1 1024-1027

Interrupt occur during execution of instruction INC R3. So CPU will complete the execution of this instruction and push the next address 1024 in the stack. So after interrupt service program can be resumed for next instruction.

So (C) is correct option.

Answer:

Related questions

35 votes
35 votes
5 answers
1
go_editor asked Apr 23, 2016
9,356 views
Consider the following program segment. Here $\text{R1, R2}$ and $\text{R3}$ are the general purpose registers.$$\small \begin{array}{|c|l|l||c|} \hline & \text {Instruct...
54 votes
54 votes
5 answers
2
Kathleen asked Sep 21, 2014
21,900 views
Consider the following program segment. Here $\text{R1, R2}$ and $\text{R3}$ are the general purpose registers.$$\begin{array}{|l|l|l|c|} \hline & \text {Instruction} & \...
54 votes
54 votes
7 answers
3
Kathleen asked Sep 21, 2014
13,362 views
In a simplified computer the instructions are:$$\begin{array}{|l|l|} \hline \text {OP }R _j , R _i & \text{Perform }R _j \text{ OP } R _i \text{ and store the result in r...