中断的定义就不再叙述了,自行百度
中断向量号:
中断向量:
中断向量表:
中断服务程序:
sti,cli的作用以及什么时候用?
中断的过程,到底干了什么事?
(理解)中断向量的存放的内存地址在哪里、中断向量的值、中断向量值的含义。
中断向量存放在地址为0000:0000h~0000:03ffh的内存空间中。
中断向量号为n,则中断向量就存放在地址为0000:4n,0000:4n+1,0000:4n+2,0000:4n+3中。
中断向量就是cs:ip的值,
中断向量号为n,则中断向量的ip = 0000:[4n],cs = 0000:[4n+2]
每个中断都有自己的作用,所以要明确int n的作用就好了。
内部中断服务程序:
①获取原来中断向量号n的对应的中断向量的值,并保存
第一种方法:
INTNO EQU 1CH ;设中断向量号为1CH DATA SEGMENT OLDISR DW ?,? DATA ENDS ;代码段 MOV AL, INTNO MOV AH,35H INT 21H ;ES:BX MOV OLDISR[0], BX MOV AX,ES MOV OLDISR[2], AX
第二种方法:
INTNO EQU 1CH ;设中断向量号为1CH DATA SEGMENT OLDISR DW ?,? DATA ENDS ;代码段 MOV AX,0 MOV ES,AX CLI MOV AX, ES:[INTNO*4] MOV OLDISR[0],AX MOV AX,ES:[INTNO*4+2] MOV OLDISR[2], AX STI
②将你写好的子程序的段地址:偏移地址赋值给原中断向量
③调用新中断向量,int n
④将现在中断向量的值修改为刚开始保存原中断向量的值。
int 1ch作用:每秒18.2次时钟中断所调用的子程序,没修改之前,它只有iret这样一句。
理解下面两个程序,中断就学会了!。
INTNO EQU 1CH USEINT = 0 DATA SEGMENT STRING DB ' 1CH IS HOOKED!',0DH,0AH,'$' OLDISR DW ?,? TIMER DB 0 DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX MOV AX,0 MOV ES,AX ;PROTECT IF USEINT MOV AL, INTNO MOV AH,35H INT 21H ;ES:BX MOV OLDISR[0], BX MOV AX,ES MOV OLDISR[2], AX ELSE CLI MOV AX, ES:[INTNO*4] MOV OLDISR[0],AX MOV AX,ES:[INTNO*4+2] MOV OLDISR[2], AX STI ENDIF ;SET NEW ISR IF USEINT PUSH DS MOV AX, SEG ISR MOV DS,AX MOV DX, OFFSET ISR MOV AL, INTNO MOV AH, 25H INT 21H POP DS ELSE CLI MOV WORD PTR ES:[INTNO*4], OFFSET ISR MOV WORD PTR ES:[INTNO*4+2],SEG ISR STI ENDIF ;COUNT HERE AGAIN: CMP TIMER, 10 JAE EXIT JMP AGAIN EXIT: ;RESTORE IF USEINT PUSH DS MOV DX,OLDISR[0] MOV AX,OLDISR[2] MOV DS,AX MOV AL, INTNO MOV AH, 25H INT 21H POP DS ELSE CLI MOV AX,OLDISR[0] MOV ES:[INTNO*4],AX MOV AX,OLDISR[2] MOV ES:[INTNO*4+2],AX STI ENDIF MOV AX,4C00H INT 21H ISR PROC FAR PUSH DX PUSH AX MOV AX,DATA MOV DS,AX STI ;便于中断嵌套 MOV AH,2 MOV DL,TIMER ADD DL,30H INT 21H LEA DX,STRING MOV AH,9 INT 21H INC TIMER DONE: PUSHF CALL DWORD PTR OLDISR CLI POP AX POP DX IRET ;中断返回 ISR ENDP CODE ENDS END START
INTNO EQU 1CH USEINT = 1 DATA SEGMENT OLDISR DW ?,? TIMER DB 100 COUNTER DW 30 ISDONE DB 0 DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX MOV AX,0 MOV ES,AX ;PROTECT IF USEINT MOV AL, INTNO MOV AH,35H INT 21H ;ES:BX MOV OLDISR[0], BX MOV AX,ES MOV OLDISR[2], AX ELSE CLI MOV AX, ES:[INTNO*4] MOV OLDISR[0],AX MOV AX,ES:[INTNO*4+2] MOV OLDISR[2], AX STI ENDIF ;SET NEW ISR IF USEINT PUSH DS MOV AX, SEG ISR MOV DS,AX MOV DX, OFFSET ISR MOV AL, INTNO MOV AH, 25H INT 21H POP DS ELSE CLI MOV WORD PTR ES:[INTNO*4], OFFSET ISR MOV WORD PTR ES:[INTNO*4+2],SEG ISR STI ENDIF ;WAIT HERE WAITHERE: CMP ISDONE,1 JNZ WAITHERE EXIT: ;RESTORE IF USEINT PUSH DS MOV DX,OLDISR[0] MOV AX,OLDISR[2] MOV DS,AX MOV AL, INTNO MOV AH, 25H INT 21H POP DS ELSE CLI MOV AX,OLDISR[0] MOV ES:[INTNO*4],AX MOV AX,OLDISR[2] MOV ES:[INTNO*4+2],AX STI ENDIF MOV AX,4C00H INT 21H ISR PROC FAR PUSH DX PUSH AX MOV AX,DATA MOV DS,AX STI ;便于中断嵌套 ;COUNT HERE INC TIMER AGAIN: CMP TIMER, 1000/55 ;18 JB DONE MOV TIMER,0 ;carriage MOV AH,2 MOV DL,13 INT 21H ;print time MOV AX,COUNTER MOV DL,10 DIV DL MOV DH,AH MOV DL,AL MOV AH,2 ADD DL,30H INT 21H MOV DL,DH ADD DL,30H INT 21H DEC COUNTER JGE DONE MOV ISDONE,1 DONE: PUSHF CALL DWORD PTR OLDISR CLI POP AX POP DX IRET ;中断返回 ISR ENDP CODE ENDS END START