6 - Interrupt
6 - Interrupt
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-2 林達德
1
INTERRUP INTERFACE OF THE 8088
AND 8086 MICROPROCESSOR
2
11.1 Interrupt Mechanism, Types and
Priority
Interrupt program context switching
mechanism
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-5 林達德
3
11.1 Interrupt Mechanism, Types and
Priority
Types of interrupts and their priority
Increasing priority
Reset
Internal interrupts and exceptions
Software interrupts
Nonmaskable interrupts
External hardware interrupts
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-7 林達德
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-8 林達德
4
11.2 Interrupt Vector Table
Interrupt vector table of the 8088/8086
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-9 林達德
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-10 林達德
5
11.3 Interrupt Instructions
Mnemonic Meaning Format Operation Flags affected
CLI Clear interrupt flag CLI 0 → (IF) IF
STI Set interrupt flag STI 1 → (IF) IF
INT n Type n software INT n (Flags) → ((SP)-2) TF, IF
interrupt 0 → TF, IF
(CS) → ((SP) – 4)
(2+4xn) → (CS)
(IP) → ((SP) – 6 )
(4xn) → (IP)
IRET Interrupt return IRET ((SP)) → (IP) All
((SP)+2) →(CS)
((SP)+4) →(Flags)
(SP) + 6 → (SP)
INTO Interrupt on overflow INTO INT 4 steps TF, IF
HLT Halt HLT Wait for an external None
interrupt or reset to occur
WAIT Wait WAIT Wait for TEST input to go
active
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-11 林達德
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-12 林達德
6
11.5 External Hardware-Interrupt
Interface Signals
Minimum-mode interrupt interface
Key interrupt interface signals: INTR and INTA
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-13 林達德
7
11.5 External Hardware-Interrupt
Interface Signals
Maximum-mode interrupt interface
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-15 林達德
YES
INTERNAL
INTERRUPT?
NO
YES
NMI
NO
YES 1
ACKNOWLEDGE READ TYPE
INTR IF
INTERRUPT NUMBER
NO 0
1 COMPLET CURRENT
TF INSTRUCTION
0
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-16 林達德
8
11.6 External Hardware-Interrupt
Sequence
CLEAR IF & TF
PUSH CS & IP
CALL INTERRUPT
SERVICE ROUTINE
EXECUTE USER
INTERRUPT ROUTINE
POP IP & CS
POP FLAGS
Flow chart of the interrupt
processing sequence of the 8088 RESUME INTERRUPT
PROCEDURE
and 8086 microprocessor
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-17 林達德
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-18 林達德
9
11.6 External Hardware-Interrupt
Sequence
Interrupt service routine
PUSH XX
To save registers and PUSH YY
parameters on the stack
PUSH ZZ
.
.
Main body of the .
service routine .
.
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-20 林達德
10
11.6 External Hardware-Interrupt
Sequence
EXAMPLE
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-21 林達德
11
11.6 External Hardware-Interrupt
Sequence
Solution:
c. The memory organization is
in the right figure
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-23 林達德
Wait for
Return
interrupt
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-24 林達德
12
11.6 External Hardware-Interrupt
Sequence
Solution:
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-25 林達德
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-26 林達德
13
11.7 82C59A Programmable Interrupt
Controller
Block diagram of the 82C59A
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-28 林達德
14
11.7 82C59A Programmable Interrupt
Controller
Internal architecture of the 82C59A
Eight functional parts of the 82C59A
• The data bus buffer
• The read/write logic
• The control logic
• The in-service register
• The interrupt-request register
• The priority resolver
• The interrupt-mask register
• The cascade buffer/comparator
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-29 林達德
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-30 林達德
15
11.7 82C59A Programmable Interrupt
Controller
Programming the 82C59A
ICW1
ICW2
NO (SNGL=1)
IN CASCADE
MODE ?
YES (SNGL=0)
ICW3
NO (IC4=0) IS ICW4
NEEDED ?
YES (IC4=1)
ICW4
Initialization sequence of
the 82C59A
READY TO ACCEPT
INTERRUPT REQUESTS
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-31 林達德
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-32 林達德
16
11.7 82C59A Programmable Interrupt
Controller
EXAMPLE
What value should be written into ICW1 in order to configure the
82C59A so that ICW4 is needed in the initialization sequence, the
system is going to use multiple 82C59As, and its inputs are to be
level sensitive? Assume that all unused bits are to be logic 0.
Solution:
Since ICW4 is to be initialized, D0 must be logic 1, D0 = 1
For cascaded mode of operation, D1 must be 0, D1 = 0
And for level-sensitive inputs, D3 must be 1, D3 = 1
Bits D2 and D5 through D7 are don’t-care states and are 0.
D2 = D5 = D6 = D7 = 0
Moreover, D4 must be fixed at the 1 logic level, D4 = 1
This gives the complete command word
D7D6D5D4D3D2D1D0 = 000110012 = 1916
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-33 林達德
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-34 林達德
17
11.7 82C59A Programmable Interrupt
Controller
EXAMPLE
What should be programmed into register ICW2 if the type
numbers output on the bus by the device are to range from F016
through F716?
Solution:
To set the 82C59A up so that type numbers are in the range of F016
through F716, its device code bits must be
D7D6D5D4D3 = 111102
The lower three bits are don’t-care states and all can be 0s. This
gives the word
D7D6D5D4D3D2D1D0 = 111100002 = F016
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-35 林達德
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-36 林達德
18
11.7 82C59A Programmable Interrupt
Controller
EXAMPLE
Assume that a master PIC is to be configured so that its IR0
through IR3 inputs are to accept inputs directly from external devices,
but IR4 through IR7 are to be supplied by the INT outputs of slaves.
What code should be used for the initialization command word ICW3?
Solution:
For IR0 through IR3 to be configured to allow direct inputs from
external devices, bits D0 through D3 of ICW3 must be logic 0:
D3D2D1D0 = 00002
The other IR inputs of the master are to be supplied by INT outputs
of slaves. Therefore, their control bits must be all 1:
D7D6D5D4 = 11112
This gives the complete command word
D7D6D5D4D3D2D1D0 = 111100002 = F016
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-37 林達德
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-38 林達德
19
11.7 82C59A Programmable Interrupt
Controller
Operational command words
OCW1 is used to access the contents of the
interrupt-mask register (IMR). Setting a bit to logic
1 masks out the associated interrupt input.
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-39 林達德
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-40 林達德
20
11.7 82C59A Programmable Interrupt
Controller
Operational command words
OCW2 is used to select appropriate priority scheme and
assigns an IR level for the scheme.
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-41 林達德
Solution:
To enable the rotate on nonspecific EOI command priority scheme,
bits D7 through D5 must be set to 101. Since a specific level does
not have to be considered, the rest of the bits in the command word
can be 0. This gives OCW2 as
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-42 林達德
21
11.7 82C59A Programmable Interrupt
Controller
Operational command words
OCW3 permits reading of the contents of the ISR or IRR
registers through software.
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-43 林達德
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-44 林達德
22
11.7 82C59A Programmable Interrupt
Controller
Next we will create a data segment starting at address 0000016:
MOV AX, 0 ;Create a data segment at 00000H
MOV DS, AX
Now we are ready to write the command words to the 82C59A:
MOV AL, 19H ;Load ICW1
MOV [0A000H], AL ;Write ICW1 to 82C59A
MOV AL, 0F0H ;Load ICW2
MOV [0A001H], AL ;Write ICW2 to 82C59A
MOV AL, 0F0H ;Load ICW3
MOV [0A001H], AL ;Write ICW3 to 82C59A
MOV AL, 1FH ;Load ICW4
MOV [0A001H], AL ;Write ICW4 to 82C59A
Initialization is now complete and the interrupts can be enabled
STI ;Enable interrupts
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-45 林達德
Minimum-mode interrupt interface for the 8088 microcomputer using the 82C59A
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-46 林達德
23
11.8 Interrupt Interface Circuits Using
the 82C59A
Minimum-mode interrupt interface for the 8086 microcomputer using the 82C59A
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-47 林達德
24
11.8 Interrupt Interface Circuits Using
the 82C59A
Maximum-mode interrupt interface for the 8088 microcomputer using the 82C59A
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-49 林達德
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-50 林達德
25
11.8 Interrupt Interface Circuits Using
the 82C59A
Solution:
Lets first determine the I/O addresses of the 82C59A registers:
A15A14A13A12A11A10A9A8A7A6A5A4A3A2A1A0
= 11111111000000002 for A1 = 0, M/IO = 0 and
= 11111111000000102 for A1 = 1, M/IO = 0
These two I/O addresses are FF00H and FF02H, respectively. The
address FF00H is for the ICW1 and FF02H is for the ICW2, ICW3,
ICW4, and OCW1 command words.
The command words are:
ICW1 = 000100112 = 13H
ICW2 = 010010002 = 48H
ICW3 = not needed
ICW4 = 000000112 = 03H
OCW1 = 111111102 = FEH
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-51 林達德
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-52 林達德
26
11.8 Interrupt Interface Circuits Using
the 82C59A
Flowcharts of the main program and service routine:
Main Program SRV72
Set up data segment,
Save processor
stack segment, and
status
stack pointer
Wait for
interrupt
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-53 林達德
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-54 林達德
27
11.8 Interrupt Interface Circuits Using
the 82C59A
Program:
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-55 林達德
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-56 林達德
28
11.9 Software Interrupts
The 8088 and 8086 microcomputer systems are
capable of implementing up to 256 software
interrupts.
The INT n instruction is used to initiate a software
interrupt. The software interrupt service routine
vectors are also located in the memory locations in
the vector table.
Software interrupts are of higher priority than the
external interrupts and are not masked out by IF.
The software interrupts are actually vectored
subroutine calls.
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-57 林達德
29
11.11 Reset
The RESET input of the 8088 and 8086
microprocessors provides a hardware means for
initializing the microcomputer.
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-59 林達德
11.11 Reset
30
11.11 Reset
When the MPU recognizes the RESET input, it
initiates its internal initialization routine. At completion
of initialization, the flags are all cleared, the registers
are set to the values in the following table.
CPU COMPONENT CONTENT
Flags Clear
Instruction pointer 0000H
CS Register FFFFH
DS Register 0000H
SS Register 0000H
ES Register 0000H
Queue Empty
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-61 林達德
11.11 Reset
The external hardware interrupts are disabled after
the initialization.
Program execution begins at address FFFF016 after
reset. This storage location contains an instruction
that will cause a jump to the startup (boot-strap)
program that is used to initialize the reset of the
microcomputer system’s resources, such as I/O ports,
the interrupt flag, and data memory.
After the system-level initialization is complete,
another jump can be performed to the starting point
of the microcomputer’s operating system or
application program.
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-62 林達德
31
11.12 Internal Interrupt Functions
Four of the 256 interrupts of the 8088 and 8086 are
dedicated to internal interrupt functions.
Internal interrupts differ from external hardware
interrupts in that they occur due to the result of
executing an instruction, not an event that takes
place in external hardware.
Internal interrupts are not masked out with IF flag.
Internal interrupts of the 8088 and 8086 MPU:
Divide error (Type number 0)
Single step (Type number 1)
Breakpoint interrupt (Type number 3)
Overflow error (Type number 4)
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-63 林達德
國立台灣大學
生物機電系
611 37100 微處理機原理與應用 Lecture 11-64 林達德
32