Ch2 Lec4 Interfacing Peripherals 3 Int
Ch2 Lec4 Interfacing Peripherals 3 Int
Interfacing
Ch2_lec4_ Interrupts and
Interrupt Response
Kassahun Tamir 1
Interrupt and Interrupt Response
An 8086 interrupt can come from any one of three
sources.
✗ One source is an external signal applied to the nonmaskable
interrupt (NMI) input pin or to the interrupt (INTR) input pin.
An interrupt caused by a signal applied to one of these inputs
is referred to as a hardware interrupt.
✗ A second source of an interrupt is execution of the Interrupt
instruction, INT. This is referred to as a software interrupt.
✗ The third source of an interrupt is some error condition
produced in the 8086 by the execution of an instruction. An
example of this is the divide-by-zero interrupt.
Kassahun Tamir 2
Interrupt and Interrupt Response
At the end of each instruction cycle, the 8086 checks to
see if any interrupts have been requested. If an
interrupt has been requested, the 8086 responds to the
interrupt by stepping through the following series of
major actions.
It decrements the stack pointer by 2 and pushes the
flag register on the stack.
It disables the 8086 INTR interrupt input by clearing the
interrupt flag (IF) in the flag register (It does this using
the CLI = Clear Interrupt instruction), and sets it by
running STI instruction.
Kassahun Tamir 3
Interrupt and Interrupt Response
It resets the trap flag (TF) in the flag register.
It decrements the stack pointer by 2 and pushes the
current code segment register contents on the stack.
It decrements the stack pointer again by 2 and pushes
the current instruction pointer contents on the stack.
It does an indirect far jump to the start of the
procedure.
Kassahun Tamir 4
Interrupt and Interrupt Response
Kassahun Tamir 5
Interrupt and Interrupt Response
In an 8086 system, the first 1 Kbytes of memory, from
00000H to 003FFH, is set aside as a table for storing the
starting addresses of interrupt service procedures.
The starting address of an interrupt service procedure
is often called the interrupt vector or the interrupt
pointer, so the table is referred to as the interrupt-
vector table or the interrupt-pointer table.
This table contains CS and IP values needed to access
the service routines
Four bytes (2 bytes for CS and 2 bytes for IP) are
assigned to each interrupt (NB: we multiply N by 4 when
INT N is executed to get the CS and IP values)
Kassahun Tamir 6
Interrupt and Interrupt Response
In 8086, there are 256 interrupts.
The starting address of the Interrupt Service Routine
(ISR) is found in the interrupt verctor/pointer table.
Each ISR requires 4 segments (2 for CS and 2 for IP), as
they are 16 bit registers
To access any address of nth interrupt, a general
formula is
✗ To access IPL address: (n*4)
✗ To access IPH address: (n*4)+1
✗ To access CSL address: (n*4)+2
✗ To access CSH address: (n*4)+3
Kassahun Tamir 7
Interrupt-Vector Table
Kassahun Tamir 8
INT Instruction
It is a 2-byte instruction. First byte provides the opcode
and the second byte provides the interrupt type
number.
✗ INT 00 (divide error)
✗ INT 01 (single step)
✗ INT 02 (NMI)
✗ INT 03 (breakpoint)
✗ INT 04 (signed number overflow)
Kassahun Tamir 9
Divide-by-zero Interrupt Type 0
The 8086 will automatically do a type 0 interrupt if the
result of a DIV operation or an IDIV operation is too
large to fit in the destination register
Kassahun Tamir 10
Single-step Interrupt Type 1
When you tell a system to single-step, it will execute
one instruction and stop.
Kassahun Tamir 11
Non-maskable Interrupt Type 2
The 8086 will automatically do a type 2 interrupt
response when it receives a low-to-high transition on its
NMI input pin.
When it does a type 2 interrupt, the 8086 will push the
flags on the stack. reset TF and IF, and push the CS
value and the IP value for the next instruction on the
stack.
Kassahun Tamir 12
Breakpoint Interrupt Type 3
The type 3 interrupt is produced by execution of the INT 3
instruction.
The main use of the type 3 interrupt is to implement a
breakpoint function in a system.
Kassahun Tamir 13
Overflow Interrupt Type 4
The 8086 overflow flag (OF) will be set if the signed
result of an arithmetic operation on two signed numbers
is too large to be represented in the destination register
or memory location.
Kassahun Tamir 14
HW Interrupt Applications
One of the most common uses of Interrupts is to relieve
a CPU of the burden of polling.
The disadvantage of polled input or output is that while
the microcomputer is polling the strobe or data ready
signal, it cannot easily be doing other tasks.
So interrupt input and output is used to avoid this
problem.
Kassahun Tamir 15
Hardware Interrupt Application
Kassahun Tamir 16
Counting Application
The interrupt-service procedure for that input can
simply increment a count stored in a named
memory location.
Kassahun Tamir 17
Questions?
Kassahun Tamir 18