edited by
43,460 views
89 89 votes

Consider the following program segment for a hypothetical CPU having three user registers $R_1, R_2$ and $R_3.$ $$\begin{array}{|l|l|c|} \hline \text {Instruction}  &  \text{Operation }& \text{Instruction size} \\&& \text{(in words)} \\\hline \text{MOV $R_1,5000$} & \text{$R_1$} \leftarrow  \text{Memory$[5000]$}& \text{$2$} \\\hline\text{MOV $R2,(R1)$} & \text{$R2$} \leftarrow  \text{Memory$[(R_1)]$}& \text{$1$} \\\hline \text{ADD $R_2,R_3$} & \text{$R2$} \leftarrow  \text{$R_2 + R_3$} & \text{$1$} \\\hline \text{MOV $6000,R_2$} & \text{Memory$[6000]$} \leftarrow  \text{$R_2$} & \text{$2$} \\\hline \text{HALT} & \text{Machine Halts} & \text{$1$} \\\hline \end{array}$$Consider that the memory is byte addressable with size $32$ bits, and the program has been loaded starting from memory location $1000$ (decimal). If an interrupt occurs while the CPU has been halted after executing the HALT instruction, the return address (in decimal) saved in the stack will be

  1. $1007$
  2. $1020$
  3. $1024$
  4. $1028$

5 Answers

Best answer
126 126 votes

Option is D.

Word size is $32$ $bits$ ($4$ $bytes$). Interrupt occurs after execution of HALT instruction NOT during,  So address of next instruction will be saved on to the stack which is $1028$.  

(We have $5$ instructions starting from address $1000$, each of size $2, 1, 1, 2, 1$ totaling $7$ words $= 7 *4 =28$ $bytes$). 

$1000+ 28 = 1028$,

$1028$ is the starting address of NEXT Instruction .

After HALT instruction CPU enters a HALT state and if an interrupt happens the return address will be that of the instruction after the HALT. 

 References :

  1.  https://x86.puri.sm/html/file_module_x86_id_134.html [ X86 Instructors Manual ]
  2. http://electronics.stackexchange.com/questions/277735/what-happens-if-the-interrupt-occurs-during-the-execution-of-halt-instruction
  3. https://en.wikipedia.org/wiki/HLT_(x86_instruction)
edited by
14 14 votes
answer should be 1024 because consider the case where halt statement is succeeded by some AlU instructions now if you'll store the next intruction as the return address when an interrupt occur while executing halt then in that case after executing the interrupt program will execute those alu instruction which should not happen as program is already halted
2 flags:
✌ Edit necessary (js__ “answer is 1028 - air 80 :)”)
✌ Low quality (JHighlight “i cant blv she is air 80 ? bcoz thats the worst answer i see”)
9 9 votes

It is clearly mentioned that HALT instruction has executed completely.

Now some other instruction just began its fetch at 1028, interrupt came, so it is bit OBVIOUS that 1028 will be the answer,

1007, 1020 are useless options

 

D is the corect answer

5 5 votes

Working of HALT:

HALT instruction stops the execution of a program by changing the PC value to the current instruction program counter value (1028 is replaced with 1024 in this case) so when the HLT instruction is completed, the CPU fetches the instruction from the location specified in PC (PC contains 1024, ie HLT instruction) and increments the PC value to 1028 and does the same thing.

Now the fetched HALT instruction does the same thing again and again ( ie Changing the PC value to 1024 from 1028). It halts the program only from the user point of view, but HALT is simply busy waiting from the CPU point of view. 

So ans is 1024

 

PS: From Chottu’s comment "Interrupt comes during the halt instruction" and "Interrupt comes after halt instruction", both are the same. Because interrupt is served only after execution of current instruction.

1 flag:
✌ Insulting (ananthsaibhargavtata)
0 0 votes
Instruction1Instruction2Instruction3Instruction4Instruction5

1000        1008        1012           1016          1024          1028

After HALT Instruction PC will contain 1028. So,1028 will be pushed into the top of the stack so that it can execute this Program after servicing the Interrupt.

 

Answer:
Position:
Show:

Related questions

79 79 votes
6 answers 6 answers
29.7k
29.7k views
go_editor asked Apr 24, 2016
29,728 views
Consider the following program segment for a hypothetical CPU having three user registers $R_1, R_2$ and $R_3.$$$ \begin{array}{|l|l|c|} \hline \text{Instruction} & \text...
54 54 votes
5 answers 5 answers
28.1k
28.1k views
Kathleen asked Sep 18, 2014
28,146 views
A 4-stage pipeline has the stage delays as $150$, $120$, $160$ and $140$ $nanoseconds$, respectively. Registers that are used between the stages have a delay of $5$ $nano...
82 82 votes
11 answers 11 answers
41.6k
41.6k views
Kathleen asked Sep 18, 2014
41,557 views
A hard disk with a transfer rate of $10$ Mbytes/second is constantly transferring data to memory using DMA. The processor runs at $600$ MHz, and takes $300$ and $900$ clo...
51 51 votes
2 answers 2 answers
19.8k
19.8k views
Kathleen asked Sep 18, 2014
19,779 views
The microinstructions stored in the control memory of a processor have a width of $26$ bits. Each microinstruction is divided into three fields: a micro-operation field o...