某 8086 系统中,采用单片 8259A 进行中断管理。假设 8259A 工作在普通全嵌套方式,采用普通 EOI 命令结束中断、电平沿触发方式请求中断,IR0 对应的中断类型号为88H。8259A 占用的端口地址是 300H 和 301H。请编写 8259A 的初始化程序段。(包括设置中断向量)
时间: 2024-02-16 07:00:26 浏览: 109
8259a中断控制程序
3星 · 编辑精心推荐
以下是8259A的初始化程序段:
```assembly
; 8259A initialization code
; assume 8259A is at port 300h
; start initialization sequence
mov al, 0x11 ; initialize 8259A
out 0x20, al ; write to master command register
jmp short init2 ; jump to init2
; initialize master and slave
init2:
mov al, 0x20 ; set master base IRQ to 20h
out 0x21, al ; write to master data register
mov al, 0x04 ; tell slave about master IRQ2
out 0x21, al ; write to master data register
mov al, 0x01 ; set 8259A to 8086 mode
out 0x21, al ; write to master data register
mov al, 0x11 ; initialize 8259A
out 0xA0, al ; write to slave command register
jmp short init4 ; jump to init4
init4:
mov al, 0x28 ; set slave base IRQ to 28h
out 0xA1, al ; write to slave data register
mov al, 0x02 ; tell slave about master IRQ2
out 0xA1, al ; write to slave data register
mov al, 0x01 ; set 8259A to 8086 mode
out 0xA1, al ; write to slave data register
mov al, 0xFC ; mask all interrupts except IRQ0
out 0x21, al ; write to master data register
mov al, 0xFF ; mask all interrupts on slave
out 0xA1, al ; write to slave data register
; set interrupt vector for IRQ0
mov al, 0x88 ; IRQ0 interrupt type is 88h
mov ah, 0 ; clear upper 8 bits of AX
mov bl, 0x20 ; IRQ0 is mapped to INT 20h
mov bh, 0 ; clear upper 8 bits of BX
mov [0:0x20], bx ; set interrupt vector for IRQ0
; enable interrupts
sti
ret
```
上述程序段中,首先向主片发送0x11,表示初始化8259A。然后设置主片和从片的基本中断号分别为0x20和0x28,告诉从片主片的IRQ2是从片的中断。接着设置8259A为8086模式,并关闭所有中断。最后设置IRQ0的中断向量,并打开中断。
阅读全文