定制键盘输入处理(1503)

来源:互联网 发布:centos搭建git服务器 编辑:程序博客网 时间:2024/06/05 06:14

本文为《汇编语言程序设计》1503小节例程。点击链接…进课程主页。

任务:在屏幕中间依次显示 ‘a’~’z’ ,并可以让人看清,在显示的过程中,按下Esc键后,改变显示的颜色。
程序:
v0.2

assume cs:codecode segmentstart:  mov ax,0b800h            mov es,ax            mov ah,'a'        s: mov es:[160*12+40*2],ah            inc ah            cmp ah,'z'           jna s          mov ax,4c00h          int 21hcode endsend start

v0.4

assume cs:codestack segment        db 128 dup (0)stack endscode segmentstart:  mov ax,stack        mov ss,ax        mov sp,128        ; 显示字符        mov ax,0b800h        mov es,ax        mov ah,'a'    s:  mov es:[160*12+40*2],ah        call delay        inc ah        cmp ah,'z'        jna s        mov ax,4c00h        int 21h        ; 定义延时函数delay:  push ax        push dx        mov dx,10h        mov ax,0   s1:  sub ax,1        sbb dx,0        cmp ax,0        jne s1        cmp dx,0        jne s1        pop dx        pop ax        retcode endsend start

v1.0

assume cs:codestack segment         db 128 dup (0)stack endsdata segment         dw 0,0data endscode segmentstart:  mov ax,stack        mov ss,ax        mov sp,128        mov ax,data        mov ds,ax        ; 改中断例程入口地址        mov ax,0        mov es,ax        push es:[9*4]        pop ds:[0]        push es:[9*4+2]        pop ds:[2]        mov word ptr es:[9*4],offset int9        mov es:[9*4+2],cs        ; 显示'a'~'z'        mov ax,0b800h        mov es,ax        mov ah,'a'   s:   mov  es:[160*12+40*2],ah        call delay        inc ah        cmp ah,'z'        jna s        mov ax,0        mov es,ax        ; 恢复原来的地址        push ds:[0]        pop es:[9*4]        push ds;[2]        pop es;[9*4+2]        mov ax,4c00h        int 21h        ; 定义延迟程序delay:  push ax        push dx        mov dx,10h        mov ax,0   s1:  sub ax,1        sbb dx,0        cmp ax,0        jne s1        cmp dx,0        jne s1        pop dx        pop ax        ret        ; 定义中断例程int9:   push ax        push bx        push es        in al,60h        pushf        pushf        pop bx        and bh,11111100b        push bx        popf        call dword ptr ds:[0]        cmp al,1 ; ESC扫描码1        jne int9ret        ;改变颜色        mov ax,0b800h        mov es,ax        inc byte ptr es:[160*12+40*2+1]int9ret:pop es        pop bx        pop ax        iretcode endsend start

注:此程序运行后,键盘功能将失效。程序中潜伏着一个不引人注目的小bug。——先请自行找一找

原创粉丝点击