按键盘esc变字符颜色

;学习来自:汇编语言-王爽(第四版)。第15章:外中断

assume cs:codeseg,ds:dataseg ,ss:stackseg

dataseg segment

    ;保存原int9的初始地址,每个地址大小为2字节

    dw 0,0

dataseg ends

stackseg segment

    ;入栈用的空间

    db 128 dup (0)

stackseg ends



codeseg segment

    main:

        ;初始化寄存器ds,ss,es

        mov ax,dataseg

        mov ds,ax

        mov ax,stackseg

        mov ss,ax

        mov ax,0h

        mov es,ax



        ;保存int9的初始地址

        mov ax,word ptr es:[24h];

        mov word ptr ds:[0h],ax

        mov ax,word ptr es:[26h]

        mov word ptr ds:[2h],ax



        ;设置新int9的初始地址

        mov word ptr es:[24h],offset my_int9

        mov word ptr es:[26h],codeseg



        ;显示字符

        mov ax,0b800h

        mov es,ax

        mov ah,'a'

        show_char:

            mov byte ptr es:[07b0h],ah

            call stop_10;调用循环停留

            inc ah

            cmp ah,'z'

            jna show_char



        ;还原原int9中断处理程序初始地址

        mov ax,0h

        mov es ,ax

        mov ax,word ptr ds:[0h]

        mov word ptr es:[24h],ax

        mov ax,word ptr ds:[2h]

        mov word ptr es:[26h],ax



        mov ax,4c00h;设置ah中断子程序

        int 21h;中断



    ;循环停留

    stop_10:

        push ax

        push bx

        mov ax,0h

        mov bx,10h

        s:

            sub ax,1h;ffffffff减去直到为0

            sbb bx,0h;减去10次借位直到为0

            cmp ax,0h

            jne s

            cmp bx,0h

            jne s

        pop bx

        pop ax

        ret



    ;新中断处理程序

    my_int9:;按一下 esc键 中间文字的颜色变化

        push ax

        push bx

        push es



        ;读端口60h

        in al,60h;获取中断信息        

        ;所有标志寄存器入栈

        pushf

            ;修改if,tf=0

            pushf

            pop bx

            and bx,11111100b

            push bx

            popf

            ;调用原中断处理程序

        call dword ptr ds:[0h]

        cmp al,1

        jne my_int9_end

        mov ax,0b800h

        mov es,ax

        inc byte ptr es:[07b1h];属性加一

        my_int9_end:

        pop es

        pop bx

        pop ax

        iret;中断退出

codeseg ends



end main

  • 9
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值