Module III - Stack and Interrupts
Module III - Stack and Interrupts
bb
One of the advantages of the subroutine is that, a recurring
sequence of instructions can be assigned with a procedure name,
which may be called again and again whenever required, resulting
in a comparatively smaller sequence of instructions.
Broadly, there are two types of interrupts.
The first out of them is external interrupt and the second is internal interrupt.
In external interrupt, an external device or a signal interrupts the processor from
outside or, in other words, the interrupt is generated outside the processor, for
example, a keyboard interrupt.
The internal interrupt, on the other hand, is generated internally by the processor
circuit, or by the execution of an interrupt instruction. The examples of this type are
divide by zero interrupt, overflow interrupt, interrupts due to INT instructions, etc.
Suppose an external device interrupts the CPU at the interrupt pin, either NMI or
INTR of the 8086, while the CPU is executing an instruction of a program.
The CPU first completes the execution of the current instruction.
The IP is then incremented to point to the next instruction.
The CPU then acknowledges the requesting device on its INTA pin immediately if it is
a NMI, TRAP or Divide by Zero interrupt.
If it is an INT request, the CPU checks the IF flag. If the IF is set, the interrupt
request is acknowledged using the INTA pin. If the IF is not set, the interrupt
requests are ignored.
After an interrupt is acknowledged, the CPU computes the vector address from
the type of the interrupt that may be passed to the interrupt structure of the
CPU internally (in case of software interrupts, NMI, TRAP and Divide by Zero
interrupts) or externally, i.e. from an interrupt controller in case of external
interrupts.
The Interrupt Flag (IF) is cleared. The TF is also cleared, after every response
to the single step interrupt.
The control is then transferred to the interrupt service routine for serving the
interrupting device.
The new address of ISR is found out from the interrupt vector table. The
execution of the ISR starts. If further interrupts are to be responded to during
the time the first interrupt is being serviced, the IF should again be set to 1 by
the ISR of the first interrupt.
If the interrupt flag is not set, the subsequent interrupt signals will not be
acknowledged by the processor, till the current one is completed.
The programmable interrupt controller is used for managi ng such multiple
interrupts based on their priorities.
At the end of ISR the last instruction should be IRET. When the CPU executes
IRET, the contents of flags, IP and CS which were saved at the start by the
CALL instruction are now retrieved to the respective registers. The execution
continues onwards from this address, received by IP and CS.
The processor 8086/88 has a Non-Masksable Interrupt input pin (NMI), that has the
highest priority among the external interrupts.
TRAP(Single Step-Type 1) is an internal interrupt having the highest priority
amongst all the interrupts except the Divide By Zero (Type0) exception.
The NMI is activated on a positive transition (low to high voltage). The assertion of
the NMI interrupt is equivalent to an execution of instruction INT 02, i.e. Type 2
INTR interrupt.
The NMI pin should remain high for at least two clock cycles and need not
synchronized with the clock for being sensed.
When the NMI is activated, the current instruction being executed is completed and
then the NMI is served.
In case of string type instructions, this interrupt will be served only after the
complete string has been manipulated.
Another high going edge on the NMI pin of 8086, during the period in which the first
NMI is served, triggers another response. The signal on the NMI pin must be free
oflogical bounces to avoid erratic NMI responses.
The processor 8086/88 also provides a pin INTR, that has lower priority as
compared to NMI.
The priorities within the INTR types are decided by the type of the INTR signall that
is to be passed to the pro cessor via data bus by some external device like the
programmable interrupt controller.
The INTR signal is level triggered and can be masked by resetting the interrupt flag.
It is internally synchronized with the high transition of the CLK.
For the INTR signal, to be responded to in the next instruction cycle, it must go high
in the last clock cycle of the current instruction or before that.
The INTR requests appearing after the last clock cycle of the current instruction will
be responded to after the execution of the next instruction.
The status of the pending interrupts is checked at the end of each instruction cycle.
If the IF is set, the processor is ready to respond to any INTR interrupt and if the IF
is reset, the processor will not serve any interrupt appearing at this pin.
However, once the processor responds to an INTR signal, the IF is automatically
reset.
If one wants the processor to further respond to any type ofINTR signal, the IF
should again be set.
While programming for any type of interrupt, the programmer must, either externally
or through the program, set the interrupt vector table for that type preferrably with
the CS and IP addresses of the interrupt service routine.
The method of defining the interrupt service routine for software as well as hardware
interrupt is the same
Figure shows the execution
sequence in case of a software
interrupt. It is assumed that
the interrupt vector table is
initialised suitably to point to
the interrupt service routine.
Figure shows the transfer of control for the nested interrupts.