汇编代码 按ESC改变屏幕显示的颜色

assume cs:code
code segment
start:
;保存原来的中断入口
mov ax,0
mov es,ax
mov ax,es:[94]
mov es:[200h],ax
mov ax,es:[9
4+2]
mov es:[202h],ax

;将自己编写的中断程序送入0:204h
mov ax,cs
mov ds,ax
mov si,offset int9
mov di,204h
mov cx,offset int9_end - offset int9
cld
rep movsb

;修改中断向量表(不加cli sti的话万一在修改中断向量表的途中发生了中断就会引发错误)
cli
mov word ptr es:[9*4],204h
mov word ptr es:[9*4+2],0
sti



;在屏幕中间显示'a'-'z'
mov ax,0b800h
mov es,ax
mov ah,'a'

display:
    mov es:[160*12+40*2],ah
    call delay
    inc ah
    cmp ah,'z'
    jna display

;将原来的中断入口装回以方便下次继续使用
cli
mov ax,0
mov es,ax
mov ax,es:[200h]
mov es:[9*4],ax
mov ax,es:[202h]
mov es:[9*4+2],ax
sti

mov ax,4c00h
int 21h

;手动延迟
delay:
    push ax
    push dx
    mov dx,4h
    mov ax,0
    delay_s:
        sub ax,1
        sbb dx,0
        cmp ax,0
        jne delay_s
        cmp dx,0
        jne delay_s
    pop dx
    pop ax
    ret


;自己的中断处理程序
int9:
    push ax
    push bx
    push es
    ;1.读取60h端口中的输入
    in al,60h
    ;2.调用原始的int9 中断处理我们处理不了的细节
    ;a.取中断类型码
    ;b.标志寄存器入栈,IF = 0,TF = 0
    pushf

    pushf
    pop ax
    and ah,11111100b
    push ax
    popf
    ;c.cs,ip入栈
    ;d.IP = n*4,CS = n*4+2
    mov bx,0
    mov es,bx
    call dword ptr es:[200h]
    ;3.看看是不是ESC键,如果是,就改变颜色
    cmp al,01h
    jne int9_ret
    mov bx,0b800h
    mov es,bx
    inc byte ptr es:[160*12+40*2+1]
    int9_ret:
        pop es
        pop bx
        pop ax
        iret
int9_end:
    nop

code ends
end start

自己敲的代码,运行按下ESC不会改变颜色,不知道哪错了。。。。。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值