正文

中断及驻留程序(汇编)2007-04-10 13:27:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/lingdlz/24744.html

分享到:

;---------------------------------------------------------
;修改除数为 0 的中断处理程序,并驻留内存
;由于 windows 的多任务环境,任务之间相互隔离,该程序在
;windows 下并不能真正驻留到内存中作为除0的中断处理程序
;---------------------------------------------------------

.model small
.stack
.code 

;---------------------------------------------------------
;结束程序,回到 DOS,用到寄存器 ax,dx
;---------------------------------------------------------
macExit macro
 mov ah,4ch
 int 21h
 endm

;---------------------------------------------------------
;屏幕打印回车换行符,用到寄存器
;---------------------------------------------------------
macPutEnt macro 
 push ax
 push dx
 mov dl,0dh
 mov ah,02h
 int 21h
 mov dl,0ah
 mov ah,02h
 int 21h
 pop dx
 pop ax
 endm

;---------------------------------------------------------
;屏幕输出以 '$' 结尾的字符串,OPR为字符串变量
;用到寄存器 ax,dx
;---------------------------------------------------------
macPutTxt macro OPR
 push ax
 push dx
 mov dx,offset OPR
 mov ah,09h
 int 21h
 pop dx
 pop ax
 endm

;---------------------------------------------------------
;主过程
;---------------------------------------------------------
main proc far
 mov dx,offset zdiv  ;修改中断处理程序
 mov ax,seg zdiv
 mov ds,ax
 mov al,0
 mov ah,25h
 int 21h
 
 mov ax,@code
 mov ds,ax
 macPutTxt msg_ok

 mov ax,1   ;演示
 mov dl,0
 div dl

 macExit
main endp

;---------------------------------------------------------
;除0中断的处理程序
;---------------------------------------------------------
zdiv proc far
 irp reg,<ax,bx,cx,dx,si,di,bp,ds,es>
 push reg
 endm
 
 mov ax,@code
 mov ds,ax
 macPutTxt msg_show

input: mov ah,1
 int 21h
 macPutEnt
 cmp al,'c'
 je continue
 cmp al,'q'
 je exit

 macPutTxt beep
 jmp input

exit: mov ah,31h   ;终止驻留
 mov al,0
 mov dx,((prog_len+15)/16)+16
 int 21h

continue:
 irp reg,<es,ds,bp,di,si,dx,cx,bx,ax>
 pop reg
 endm
 iret
zdiv endp
;--------------------------------------------------------- 
; 数据
msg_ok  db 'Zero-division handler installed !',13,10,'$'
msg_show db 'Zero-division detected'
  db 'continue or Quit(c/q):','$'
beep  db 07h,'Please enter c or q:','$'
prog_len equ $-main   ;驻留区大小
 end main

  

阅读(4224) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册