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

dev4.1

;*******************************;
;*           中断实验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

dev4.2

include io.inc
.model small
.stack
.data
msg byte 'TCP Interrupt No.10!',13,10,0
cnt byte 0
intoff  word ?
intseg  word ?
intimr  byte ?

.code
start:
    mov ax,@data
    mov ds,ax
    mov ax,3572H
    int 21h
    mov intseg,es
    mov intoff,bx
    
    cli
    push ds
    mov dx, offset serv
    mov ax, seg serv
    mov ds,ax
    mov ax,2572H
    int 21h
    pop ds
    in al, 0a1h 
    mov intimr,al
    and al,0fbh
    out 0a1h,al
    
    mov cnt,0
    sti

again:
    cmp cnt,5
    jb  again
     cli
        mov al,intimr
        out 0a1h,al
        mov dx,intoff
        mov ax,intseg
        mov ds,ax
        mov ax,2572h
        int 21h
        sti
    .exit 0
serv    proc
    sti
    push ds
    push ax
    push si
    mov ax,@data
    mov ds,ax
    inc cnt
    mov si, offset msg
    call print
    
    mov al,20h
    out 20h,al
    out 0a0h,al
    pop si
    pop ax
    pop ds
    iret
serv    endp


print   proc
    push bx
x:
    mov al,[si]
    test al,al
    jz ed
    mov bx,0
    mov ah,0eh
    int 10h
    inc si
    jmp x
ed:    
    pop bx
    ret
print   endp
end start

dev5.3

;********************************
;*  8253定时1秒中断,显示信息   *
;********************************
    include io.inc
    .model small
    .stack
    .data
msg    byte 'one second passed !',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
        ;
        cli
        push ds
        mov dx,offset intproc
        mov ax,seg intproc
        mov ds,ax
        mov ax,250bh
        int 21h
        pop ds
        ;
        in al,21h
        mov intimr,al
        and al,0f7h
        out 21h,al
        ;
    mov dx,283h      ;向8253写控制字
    mov al,36h       ;使通道0为工作方式3
    out dx,al
    mov ax,1000      ;写入循环计数初值1000
    mov dx,280h
    out dx,al        ;先写入低字节
    mov al,ah
    out dx,al        ;后写入高字节
    ;
    mov dx,283h
    mov al,76h       ;设8253通道1工作方式3
    out dx,al
    mov ax,1000      ;写入循环计数初值1000
    mov dx,281h
    out dx,al        ;先写低字节
    mov al,ah
    out dx,al        ;后写高字节
    ;
        mov byte ptr counter,0
        sti
        ;
again:  cmp byte ptr 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 byte ptr 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
posted @   cxy8  阅读(86)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
点击右上角即可分享
微信分享提示