定时器10s中断

    技术2024-10-11  50

    dseg       segment           count    dw    0           sec      dw    0           min      dw    0           hours    dw    0dseg       endscseg       segmentmain       proc     far           assume   cs:cseg,ds:dseg,es:dsegstart:     push     ds           sub      ax,ax           push     ax           mov      ax,dseg           mov      ds,ax           mov      al,1ch;Save old interrupt;           mov      ah,35h;取中断向量把AL指定的中断类型的中断向量从中断向量表中取到ES:BX中;           int      21h           push     es           push     bx                      push     ds           mov      dx,offset clint           mov      ax,seg clint           mov      ds,ax           mov      al,1ch;中断类型号1CH;           mov      ah,25h;设置中断向量,把AL指定的中断类型的中断向量DS:DX放在中断向量表中;           int      21h           pop      ds           in       al,21h;中断屏蔽寄存器21H;           and      al,0feh           out      21h,al  ;设置中断屏蔽位;           sti ;设置中断使能位;                      mov      cx,60000mainp:     mov      ax,60000again:     dec      ax           jne      again           loop     mainp                pop      dx;将es:bx值弹出到ds:dx中,恢复1CH中断;           pop      ds           mov      al,1ch           mov      ah,25h           int      21h           retmain       endp

    clint      proc     near           push     ds           push     bx           mov      bx,seg count           mov      ds,bx           lea      bx,count           inc      word ptr [bx]  ;把位移量为bx的直接寻址方式,把存储器中的一个字加1;           mov      ax,word ptr [bx]                                        cmp      word ptr [bx],18;每秒18.2次;大概1s;           jne      exit           call     inctest           adj:       cmp      hours,12           jle      timeok;小于或等于转移;           sub      hours,12timeok:    mov      ax,sec           and      ax,0007h;0007&5;0007&15;每隔10s响铃一次;           cmp      ax,5;每隔           jne      exit           mov      dl,07h;the bell ring;响铃;           mov      ah,2           int      21hexit:      mov      al,20h;EOI送中断结束命令给中断命令寄存器;           out      20h,al           pop      bx           pop      ds           iretclint      endp

    inctest    proc    near           mov     word ptr[bx], 0           add     bx,2;时分秒都是字为单位,所以加2个偏移地址;           inc     word ptr [bx];让秒分时个单元加一;           cmp     word ptr [bx],60;如果秒分时等于60时,高位加一;如果为60s,那么min加一;           jne     return           call    inctestreturn:    retinctest    endp

    cseg       ends           end     start                       ;IRET 中断返回1,IP,CS和FLAGS出栈;2,返回断点继续执行下一条指令;                                ;INT 3 程序debug调试指令;

    最新回复(0)