数据段:
intoff word ? ; 用于保存原中断服务程序的偏移地址
intseg word ? ; 用于保存原中断服务程序的段基地址
intmsg db 'A Instruction Interrupt!', 0dh, 0ah, 0 ; 字符串(以0结尾)
代码段:
mov ax, 3580h ; 获取系统的原80H中断向量表项
int 21h
mov intoff, bx ; 保存偏移地址
mov intseg, es ; 保存段基地址
堆栈操作:
push ds ; 在堆栈上保存数据段
设置新的中断向量表项:
mov dx, offset new80h
mov ax, seg new80h
mov ds, ax
mov ax, 2580h ; 设置本程序的80H中断向量表项
int 21h
恢复数据段:
pop ds ; 恢复原始的数据段
调用80H中断服务例程:
mov dx, intoff ; 恢复系统的原80H中断向量表项的偏移
mov ax, intseg ; 恢复系统的原80H中断向量表项的段基地址
mov ds, ax
mov ax, 2580h
int 21h
80H内部中断服务例程 (new80h
):
new80h proc
sti ; 开中断
push ax ; 保护寄存器
push bx
push si
mov si, dx ; 设置 SI 到缓冲区地址
new1:
mov al, [si] ; 获取要显示的字符
cmp al, 0 ; 检查是否是字符串结束
jz new2
mov bx, 0 ; 使用 ROM-BIOS 调用显示一个字符
mov ah, 0eh
int 10h
inc si ; 移动到缓冲区的下一个字符
jmp new1 ; 为整个字符串重复这个过程
new2:
pop si ; 恢复寄存器
pop bx
pop ax
iret ; 从中断返回
new80h endp