王爽《汇编语言》实验15:安装新的int 9中断例程

安装一个新的int 9中断例程,功能:按下“A”键,除非不松开,若松开则显示满屏“A”

代码如下:

assume cs:codesg,ss:stacksg
stacksg segment
    dw 16 dup (0)
stacksg ends

codesg segment
start:
    mov ax,stacksg
    mov ss,ax
    mov sp,20h      ;初始化栈空间

    mov ax,cs
    mov ds,ax
    mov si,offset int9
    mov ax,0        ;ds:si->程序
    mov es,ax
    mov di,204h     ;es:di->要存放的位置
    mov cx,(offset int9_end - offset int9)
    cld
    rep movsb       ;复制程序

    push es:[4*9]
    pop es:[200h]
    push es:[4*9+2]
    pop es:[202h]   ;保存原int 9地址

    cli
    mov word ptr es:[4*9],204h
    mov word ptr es:[4*9+2],0h
    sti             ;更新新int 9地址

    mov ax,4c00h
    int 21h

int9:
    push ax
    push bx
    push cx
    push es         ;保存要用的寄存器

    in al,60h
    
    pushf
    call dword ptr cs:[200h]
                    ;调用原int 9中断例程,处理键盘输入
    cmp al,(1eh + 80h)
    jne int9_ret    ;若非A键断码,返回即可

    mov ax,0b800h
    mov es,ax
    mov cx,80*25
    xor bx,bx
s1: mov byte ptr es:[bx],'a'
    add bx,2
    loop s1

int9_ret:
    pop es          ;恢复用到的寄存器
    pop cx
    pop bx
    pop ax
    iret
int9_end:
    nop
codesg ends
end start

运行截图:
在这里插入图片描述

posted @ 2021-02-28 22:01  while(n!=1)  阅读(128)  评论(0)    收藏  举报