汇编中断程序
代码
1 DATA SEGMENT
2 INT_VECT EQU 072H ;中断0~7的向量为:08h~0fH,中断8~15的向量为70H~77H
3 IRQ_MASK_2_7 EQU 011111011B ;中断掩码,中断0~7时从低至高相应位为0,中断8~15时第2位为0
4 IRQ_MASK_9_15 EQU 011111011B ;中断0~7时全1,中断8~15时从低至高相应位为0
5 IOPORT_CENT EQU 0C000H ;TPC卡中9054芯片的io地址
6 CSREG DW ?
7 IPREG DW ? ;旧中断向量保存空间
8 IRQ_TIMES DW 00H ;中断计数
9 MSG1 DB 0DH,0AH,'TPC pci card Interrupt',0DH,0AH,'$'
10 MSG2 DB 0DH,0AH,'Press any key to exit!',0DH,0AH,'$'
11 MSG3 DB 0DH,0AH,'Press DMC to interrupt 10 times and exit!',0DH,0AH,'$'
12 DATA ENDS
13
14 STACKS SEGMENT
15 DB 100 DUP(?)
16 STACKS ENDS
17
18 CODE SEGMENT
19 ASSUME CS:CODE,DS:DATA,SS:STACKS,ES:DATA
20 START:CLI
21 MOV AX,DATA
22 MOV DS,AX
23 MOV ES,AX
24 MOV AX,STACKS
25 MOV SS,AX
26 MOV DX,IOPORT_CENT+68H ;设置tpc卡中9054芯片io口,使能中断
27 IN AX,DX
28 OR AX,0900H
29 OUT DX,AX
30 MOV AL,INT_VECT ;保存原来中断向量
31 MOV AH,35H
32 INT 21H
33 MOV AH,35H
34 INT 21H
35 MOV AX,ES
36 MOV CSREG,AX
37 MOV IPREG,BX
38 MOV AX,CS ;设置新中断向量
39 MOV DS,AX
40 MOV DX,OFFSET INT_PROC
41 MOV AL,INT_VECT
42 MOV AH,25H
43 INT 21H
44 IN AL,21H ;设置中断掩码
45 AND AL,IRQ_MASK_2_7
46 OUT 21H,AL
47 IN AL,0A1H
48 AND AL,IRQ_MASK_9_15
49 OUT 0A1H,AL
50 MOV AX,DATA
51 MOV DS,AX
52 MOV DX,OFFSET MSG2
53 MOV AH,09H
54 INT 21H
55 MOV DX,OFFSET MSG3
56 MOV AH,09H
57 INT 21H
58 MOV IRQ_TIMES,0AH
59 STI
60 LOOP1:CMP IRQ_TIMES,0 ;等待中断并判断10次后退出
61 JZ EXIT
62 MOV AH,1
63 INT 16H
64 JNZ EXIT ;按下任意键退出
65 JMP LOOP1
66 EXIT: CLI
67 MOV BL,IRQ_MASK_2_7 ;恢复中断掩码
68 NOT BL
69 IN AL,21H
70 OR AL,BL
71 OUT 21H,AL
72 MOV BL,IRQ_MASK_9_15
73 NOT BL
74 IN AL,0A1H
75 OR AL,BL
76 OUT 0A1H,AL
77 MOV DX,IPREG
78 MOV AX,CSREG
79 MOV DS,AX
80 MOV AH,25H
81 MOV AL,INT_VECT
82 INT 21H
83 MOV DX,IOPORT_CENT+68 ;设置天平秤卡中9054芯片io口,关闭中断
84 IN AX,DX
85 AND AX,0F7FFH
86 OUT DX,AX
87 MOV AX,4C00H
88 INT 21H
89 INT_PROC PROC FAR
90 CLI
91 PUSH AX
92 PUSH DX
93 PUSH DS
94 DEC IRQ_TIMES
95 MOV AX,DATA
96 MOV DS,AX
97 MOV DX,OFFSET MSG1
98 MOV AH,09H
99 INT 21H
100 MOV AL,20H
101 OUT 0A0H,AL
102 OUT 20H,AL
103 POP DS
104 POP DX
105 POP AX
106 STI
107 IRET
108 INT_PROC ENDP
109 CODE ENDS
110 END START
111