Documente Academic
Documente Profesional
Documente Cultură
PIC – 8259A
CEN433
King Saud University
Dr. Mohammed Amer Arafah
1
Methods to Service an I/O Device
JMP START
FLAGS O D I T S Z A P C
15 11 10 9 8 7 6 5 4 3 2 1 0
INT n Instruction.
Special cases:
n = 1: Single step (trap)
Enabled if TF (Trap flag) bit in Flags is set
n = 3: INT 3 (Breakpoint)
n = 4: INTO (Overflow)
n = 5: BOUND (Check limits)
Unconditional:
INT n: Executes the interrupt with the vector type n.
Instruction takes 2 bytes: a byte for the opcode and a byte for n.
e.g. INT 80H Start of the 4-byte vector address = 4 x 80H = 200H
(200H – 203H).
INT 3: is a special case of INT n which fits into one byte only. Useful
in inserting a break point in the software for debugging purposes
00 00104
Offset 00105
05 Interrupt Vector
00106 for type 41H interrupt
00
Segment
FE 00107
ORG 41H * 4
INT41 LABEL DWORD
DD FIRST
IVT ENDS
Interrupt Service
Main Routine (ISR)
Program • Push FLAG Register
• Clear IF Push Registers
• Clear TF
• Push Return Address (IP & CS)
• Fetch ISR Address
Interrupt
• Pop IP
• Pop CS Pop Registers
• Pop Flag Registers IRET
current instruction is
completed
IP
Interrupted
PIC sends interrupt signal
Current Flag, CS, Program
ISR
and IP are pushed
into stack . .
OLD (IP) . .
. .
OLD (CS)
Stack ISR begins .
.
IRET causes IP, OLD (Flag) .
. .
CS, and Flag to . .
be popped from IRET
stack
Return to interrupted program
CEN433 - King Saud University 17 Mohammed Amer Arafah
When an Interrupt Occurs
Flags register is pushed onto the stack.
Both the interrupt (IF) and trap (TF) flags are cleared. This
disables the INTR input and the trap from interrupting the
interrupt being handled.
The code segment register (CS) is pushed onto the stack.
The instruction pointer (IP) is pushed onto the stack.
The interrupt vector contents are fetched from the interrupt
vector table and then placed into the IP and CS so that the
next instruction executes at the interrupt service procedure
addressed by the vector.
Internally decoded
as type 2 interrupt
After a positive edge, the NMI pin must remain a logic 1 two T
states at minimum.
The NMI input is often used for major system faults such as
power failures. Power failures are easily detected by
monitoring the AC power line and causing an NMI interrupt
whenever AC power drops out.
There are two INTA/ pulses generated by the microprocessor that are
used to insert the vector type number on the data bus.
The INTR can be disabled by a CLI instruction which clears the IF, and
enabled by a STI instruction which sets the IF.
CEN433 - King Saud University 21 Mohammed Amer Arafah
Interrupt Types
Vector
Acknowledge Interrupt
Name Initiated by Maskable Trigger Priority Table
Signal Latency
Address
NMI External No edge, hold 2 None 00008H- Current
Hardware 2T states min. 0000BH Instruction +
51 T states
INTR External Yes via IF High level until 3 INTA/ n4 Current
Hardware acknowledged Instruction +
61 T states
INT n Internal via No None 1 None n4 51 T states
Software
INT 3 Internal via No None 1 None 0000CH- 52 T states
(Breakpoint) Software 0000FH
INTO Internal via No None 1 None 00010H- 53 T states
Software 00013H
Divide-by- Internal via No None 1 None 00000H- 51 T states
0 CPU 00003H
Single- Internal via Yes via TF None 4 None 00004H- 51 T states
Step CPU 00007H
All interrupt types cause the Flags, CS, and IP registers to be pushed onto the stack. In addition, the IF and TF are cleared.
• INTR must be kept high for enough time for processor to “see” it.
POP AX
POP DX
IRET
INT41_SR_PROC ENDP
INT41_SR ENDS
;----------------------------------------------------------------------------------------------------------------------------
CODE SEGMENT AT 0FFFFH
ASSUME CS:CODE,SS:STACK
ORG 0H
;
START: CLI
MOV AX,STACK
MOV SS,AX
MOV SP,OFFSET STK_TOP
JMP BEGIN
CODE ENDS
END START
BD[0:7]
U1
BD0 11 18 IR0
BD1 10 D0 IR0 19 IR1
BD2 9 D1 IR1 20 IR2
BD3 8 D2 IR2 21 IR3
BD4 7 D3 IR3 22 IR4
U2 BD5 6 D4 IR4 23 IR5
1 15 BD6 5 D5 IR5 24 IR6
BA4
2 A Y0 14 BD7 4 D6 IR6 25 IR7
BA5
3 B Y1 13 D7 IR7
BA6
C Y2 12 27
BA0
Y3 11 1 A0
6 Y4 10 VCC 3 CS
BA15 IOR/
4 G1 Y5 9 2 RD
BA13 IOW/
5 G2A Y6 7 16 WR 12
BA14
G2B Y7 INTR 17 SP/EN CAS0 13
26 INT CAS1 15
74LS138 INTA/
INTA CAS2
8259A
IMR7
CLEAR
HOLD CLEAR
EOI
INTA/
FREEZE/
Input OCW1
No Yes
OCW1=00
Input OCW1
No Yes
OCW1=FF
Infinite Loop
No Correct
Code?
Use your editor to fix the syntax
errors assembly program
Yes
8255A
8088
PA0 - PA7
NMI INPUT
STBA
INTEA PC4 DEVICE
INTR
IBFA
PC5
INTA
INTRA
PC3
I/O
2
PC6,7
28 ; Checking Status
29 ;----------------------------------------------------
30 ; PC7 | PC6 | IBFA | INTEA | INTRA | PC2 | PC1 | PC0 |
31 ;----------------------------------------------------
000E BA0280 32 AGAIN: MOV DX, PORTC
0011 EC 33 IN AL, DX
0012 A808 34 TEST AL ,00001000B
0014 74F8 35 JZ AGAIN
0016 BA0080 36 MOV DX, PORTA
0019 EC 37 IN AL, DX ; Service I/O: Read Port A
001A 42 38 INC DX
001B EE 39 OUT DX, AL ; Write to Port B
001C EBF0 40 JMP AGAIN
---- 41 EPROM ENDS
42 ;---------------------------------------------------------------------
---- 43 CODE SEGMENT AT 0FFFFH
44 ASSUME CS:CODE, SS:STACK
45 ;
0000 46 ORG 0H
0000 FA 47 START: CLI
0001 B85000 48 MOV AX,STACK
0004 8ED0 49 MOV SS,AX
0006 BC6400 50 MOV SP,OFFSET STK_TOP
0009 EA000000FE 51 JMP BEGIN
---- 52 CODE ENDS
53 END START
IBFA
READ STATUS PORT READ STATUS PORT
YES
(PORT C) (PORT C)
NO NO NO NO NO NO
INTRA
IOR/
READ PORT A
IOW/
WRITE TO PORT B
8255A INITIALIZATION
8255A
8088
PA0 - PA7
NMI INPUT
STBA
INTEA PC4 DEVICE
INTR
IBFA
PC5
INTA
INTRA
PC3
2 I/O
PC6,7
3 00504
4 00506
… … … …
Stack
Segment 45 00558
AH AL 0055A 005A SP
46 0055A
47 0055C DH DL 0055C
49 00560 00560
CS (H) CS (L)
50 00562
FLAG (H) FLAG (L) 00562
00564 0064 SP
…
007FF
4- Reading from the interrupt vector table (location 8 and 9) the IP of ISR of
NMI, which is 0500H.
5- Reading from the interrupt vector table (location A and B) the CS of ISR
of NMI, which is FE00H.
6- Writing to the stack the current flag.
7- Writing to the stack the current CS of the infinite loop, which is FE00H.
8- Writing to the stack the current IP of the infinite loop.
9- IF and TF are cleared.
8255A
Buffered 8088
PA0 - PA7
NMI
STBA INPUT
INTEA PC4
INTR DEVICE
IBFA
PC5
BD0
BD1
BD2
BD3 INTRA
BD4 Buffered PC3
BD5 Data Bus
BD6
BD7 I/O
2
PC6,7
74LS244
G1/ G2/
INTA
10 KOhm Network
Type 90H 8 Switches
3 00504
4 00506
… … … …
Stack
Segment 45 00558
AH AL 0055A 005A SP
46 0055A
47 0055C DH DL 0055C
49 00560 00560
CS (H) CS (L)
50 00562
FLAG (H) FLAG (L) 00562
00564 0064 SP
…
007FF
8259A 8255A
8088
Type 50
IR0 PA0 - PA7
IR1 Type 51
INPUT
IR2 STBA
IR3
Type 52
PC4 DEVICE
INTEA
INT IR4 Type 53
INTR
IR5 IBFA
Type 54 PC5
IR6
INTA INTA IR7 Type 55
Type 56
NMI
Type 57 INTRA
PC3
ICW1 13H
2 I/O
50H PC6,7
ICW2
ICW4 01H
OCW1 FDH
3 00504
4 00506
… … … …
Stack
Segment 45 00558
AH AL 0055A 005A SP
46 0055A
47 0055C DH DL 0055C
49 00560 00560
CS (H) CS (L)
50 00562
FLAG (H) FLAG (L) 00562
00564 0064 SP
…
007FF
00010001
00100000
00000000
00000001
00010001
xxxxxxxx
11111111
00000001
00010001
01011000
00000111
00000001
00010001
00101000
00000001
00000001
00010001
10110000
10000010
00000001
00010001
01011000
00000111
00000001
The software must determine if any other slave interrupts are still in
service before issuing an EOI command to the master. This is
done by resetting the appropriate slave ISR bit with an EOI and
then reading its ISR. If the ISR contains all zeros, there are not any
interrupts from the slave in service and an EOI command can be
sent to the master. If the ISR is no all zeros, an EOI should not be
sent to the master.