|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- ;本程序中用入栈、出栈的方式完成了 数据 在不同的寄存器之间的交换
- ;可以减少代码量,是个很不错的方法
- assume cs:code,ss:stack
- stack segment
- db 128 dup (0) ;定义128个字节空间,用于中转数据
- stack ends
- code segment
- start:
- mov ax,stack
- mov ss,ax
- mov sp,128
- ;安装中断例程到0:204
- push cs
- pop ds ;设置ds为代码段
- mov ax,0
- mov es,ax ;设置附加段
- mov si,offset int9 ;设置ds:si指向源地址
- mov di,204h ;设置es:di指向目的地址0:204h
- mov cx,offset int9end - offset int9 ;设置cx为传输长度
- cld ;设置传输方向为正
- rep movsb ;安装自定义的int9中断例程
- ;保存旧的int9中断向量到0:200h-203h
- push es:[9*4]
- pop es:[200h]
- push es:[9*4+2]
- pop es:[202h]
- ;设置新的int9中断向量为0:204h
- cli ;置IF=0,CPU禁止响应外部中断
- mov word ptr es:[9*4],204h ;(0:9*4)=204h
- mov word ptr es:[9*4+2],0 ;(0:9*4+2)=0
- sti ;置IF=1,使CPU允许向应外部中断
-
- ;进行88次读取BIOS键盘缓冲区的操作,也就是说程序响应你按键多少次
- mov cx,88
- lp: mov ah,0
- int 16h
- loop lp
- ;这段代码是方便测试的
- mov ax,4c00h
- int 21h
- int9: ;自定义的int9中断例程
- push ax
- push bx
- push cx
- push es
- in al,60h ;从60h端口读入数据
- pushf ;保存标志寄存器,对应下面的iret返回
- call dword ptr cs:[200h] ;当此中断例程执行时(CS)=0
- cmp al,9eh ;判断是否为A的断码9eh
- jne int9ret
- mov ax,0b800h ;设置显示缓冲区
- mov es,ax
- mov bx,0 ;偶数位为字符码位
- mov cx,2000
- s: mov byte ptr es:[bx],'A' ;第0屏字符码位全用'A'填充
- add bx,2
- loop s
- int9ret:
- pop es
- pop cx
- pop bx
- pop ax
- iret ;popf; ret
- int9end:nop
- code ends
- end start
复制代码 另外附上15.5,- assume cs:code,ss:stack
- stack segment
- db 128 dup (0) ;定义128个字节空间,用于中转数据
- stack ends
- code segment
- start:
- mov ax,stack
- mov ss,ax
- mov sp,128
- ;安装中断例程到0:204
- push cs
- pop ds ;设置ds为代码段
- mov ax,0
- mov es,ax ;设置附加段
- mov si,offset int9 ;设置ds:si指向源地址
- mov di,204h ;设置es:di指向目的地址0:204h
- mov cx,offset int9end - offset int9 ;设置cx为传输长度
- cld ;设置传输方向为正
- rep movsb ;安装自定义的int9中断例程
- ;保存旧的int9中断向量到0:200h-203h
- push es:[9*4]
- pop es:[200h]
- push es:[9*4+2]
- pop es:[202h]
- ;设置新的int9中断向量为0:204h
- cli ;置IF=0,CPU禁止响应外部中断
- mov word ptr es:[9*4],204h ;(0:9*4)=204h
- mov word ptr es:[9*4+2],0 ;(0:9*4+2)=0
- sti ;置IF=1,使CPU允许向应外部中断
-
- ;进行88次读取BIOS键盘缓冲区的操作,也就是说程序响应你按键多少次
- mov cx,88
- lp: mov ah,0
- int 16h
- loop lp
- ;这段代码是方便测试的
- mov ax,4c00h
- int 21h
- int9: ;自定义的int9中断例程
- push ax
- push bx
- push cx
- push es
- in al,60h ;从60h端口读入数据
- pushf ;保存标志寄存器,对应下面的iret返回
-
- call dword ptr cs:[200h] ;当此中断例程执行时(CS)=0
- cmp al,3bh ;判断是否为F1的通码
- jne int9ret
- mov ax,0b800h ;设置显示缓冲区
- mov es,ax
- mov bx,1 ;奇数位为属性值
- mov cx,2000
- s: add byte ptr es:[bx],10h ;每个背景之间相差10h
- add bx,2
- loop s
- int9ret:
- pop es
- pop cx
- pop bx
- pop ax
- iret ;popf; ret
- int9end:nop
- code ends
- end start
复制代码 |
|