微机原理与接口技术中断实验

发布时间 2023-10-28 14:39:45作者: cxy8
;*******************************;
;*           中断实验IRQ3       *;
;*******************************;
    include io.inc
    .model small    ; 定义程序的存储模式
    .stack    ; 定义堆栈段(默认是1KB空间)
    .data
msg    byte 'TPCA interrupt No.3!',0dh,0ah,0
counter    byte 0
intseg    word ?
intoff    word ?
intimr    byte ?
    .code
start:    
        mov ax,@data
        mov ds,ax
        mov ax,350bh
        int 21h
        ;获取原中断向量表项
        mov intseg,es
        mov intoff,bx
        ;
        ;设置新0BH中断向量表项,这时应该关中断
        cli
        push ds
        mov dx,offset intproc
        mov ax,seg intproc
        mov ds,ax
        mov ax,250bh
        ;调用DOS功能调用,讲intproc的中断向量表项写入0bh
        int 21h
        pop ds
        ;设置imr允许IR3中断
        in al,21h
        mov intimr,al
        and al,0f7h
        out 21h,al
        ;开始直到3次中断结束
        mov counter,0
        ;当我们完成中断前的处理工作就可以开中断了
        sti
        ;
again:  cmp counter,5
        jb again
        ;
        ;中断返回程序,也要关中断
        cli
        mov al,intimr
        out 21h,al
        mov dx,intoff
        mov ax,intseg
        mov ds,ax
        mov ax,250bh
        int 21h
        sti
        ;中断返回程序开中断
    .exit 0

intproc proc
        sti
        push ax
        push si
        push ds
        ;
        mov ax,@data
        mov ds,ax
        ;
        inc counter
        mov si,offset msg
        call dpstri
        ;设置中断结束方式
        mov al,20h
        out 20h,al
        pop ds
        pop si
        pop ax
        iret
intproc endp
;
dpstri    proc
        push bx
disp1:  mov al,[si]
        test al,al
        jz disp2
        mov bx,0
        mov ah,0eh
        int 10h
        inc si
        jmp disp1
disp2:    pop bx
    ret
dpstri endp
    end start