汇编语言学习:实验十五

    安装一个新的int9中断例程,功能:在DOS下,按下“A”键后,除非不在松开,如果松开,就显示满屏幕的“A”;其他的键照常处理。

    提示:按下一个键时产生的扫描码称为通码,松开一个键产生的扫描码称为断码。断码=通码=80h。

assume cs:code

code segment
 start:
        sti                         ;防止在设置中断向量表之前出现有键盘输入导致错诿
        mov ax, cs
        mov ds, ax
        mov si, offset int9

        mov ax, 0
        mov es, ax
        mov di, 204h                ;[200]与[202]要存放原int 9的IP和CS

        mov cx, offset int9_end - offset int9
        cld                         ;正向复制

        rep movsb

        mov ax, es:[9*4]
        mov es:[200h], ax
        mov ax, es:[9*4+2]
        mov es:[202h], ax           ;保存原int 9中断例程入口地址

        mov word ptr es:[9*4], 204h
        mov word ptr es:[9*4+2], 0  ;设置中断向量衿
        sti                         ;IF设置1

        mov ax, 4c00h
        int 21h
 int9:
        push ds
        push ax
        push cx
        push si 

        in al, 60h              ;接受60h来的扫描砿
        pushf
        call dword ptr cs:[200h]

        cmp al, 1eh+80h         ;A是否被松开
        jne int9_ok             ;不是松开正常处理

        mov ax, 0b800h
        mov ds, ax
        mov si, 0
        mov cx, 2000            ;打满一屏是2000个字笿

    print_char:
        mov byte ptr [si], 'A'
        add si, 2
        loop print_char

    int9_ok:
        pop si
        pop cx
        pop ax
        pop ds
        iret

   int9_end:
        nop

code ends
end start

 

你可能感兴趣的:(汇编语言学习)