|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- ;编程:在屏幕中间依次显示“a”~“z”,并可以让人看清。在显示的过程中,按下'Esc'键后,改变显示的颜色。
- ;对更改中断向量时间间隔内可能发生的中断状况作了进一步安全保障 cli ,sti的使用
- ;完整功能代码:
- assume cs:code
- stack segment
- db 128 dup (0)
- stack ends
- data segment
- dw 0,0
- data ends
- code segment
- start: 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] ;将原来的int 9中断例程的入口地址保存在ds:0、ds:2单元中
- cli ;置屏蔽中断标志位IF=0
- mov word ptr es:[9*4],offset int9
- mov es:[9*4+2],cs ;在中断向量表中设置新的int 9中断例程的入口地址
- sti ;撤消屏蔽,置屏蔽中断标志位IF=1
- 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
- cli ;置屏蔽中断标志位IF=0
- push ds:[0]
- pop es:[9*4]
- push ds;[2]
- pop es;[9*4+2] ;将中断向量表中int 9中断例程的入口恢复为原来的地址
- sti ;撤消屏蔽,置屏蔽中断标志位IF=1
- mov ax,4c00h
- int 21h
- delay: push ax
- push dx
- mov dx,2000h
- 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
- ;------以下为新的int 9中断例程--------------------
- 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] ;对int指令进行模拟,调用原来的int 9中断例程
- cmp al,1
- jne int9ret
- mov ax,0b800h
- mov es,ax
- inc byte ptr es:[160*12+40*2+1] ;属性增加1,改变颜色
- int9ret:pop es
- pop bx
- pop ax
- iret
- code ends
- end start
复制代码 上面是习题代码
问题1:
正常运行结束,但按下任意键后,dos就死掉了
问题2:当按键速度过快时,将会出现dos运行终止,并可能会关闭
以上错误,在我写的代码却没有出现,但我始终找不到问题出现在哪里。
我的代码如下
- assume cs:codesg
- data segment
- dw 16 dup (0)
- data ends
- stack segment
- dw 128 dup (0)
- stack ends
- codesg segment
- start:
- 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 ax,0
- mov es,ax
- cli
- mov word ptr es:[9*4],offset int9
- mov es:[9*4+2],cs
- sti
- ; call print_warn
- ; call print_a_z
- push ax
- push ds
- mov ax,0b800h
- mov ds,ax
- mov al,'a'
- mprint_lo:
- call delay
- mov ds:[160*12+40*2],al
- inc al
- cmp al,'z'
- jna mprint_lo
- pop ds
- pop ax
- ;ret
- cli
- push ds:[0]
- pop es:[9*4]
- push ds:[2]
- pop es:[9*4+2]
- sti
- mov ax,4c00h
- int 21h
- int9:
- push ax
- push ds
- push bx
- in al,60h
- pushf
- pushf
- pop bx
- and bh,11111100b
- push bx
- popf
- mov bx,data
- mov ds,bx
- call dword ptr ds:[0]
- cmp al,1
- jne int9_ret
- mov ax,0b800h
- mov ds,ax
- inc byte ptr ds:[160*12+40*2+1]
- int9_ret:
- pop bx
- pop ds
- pop ax
- iret
- print_a_z:
- push ax
- push ds
- mov ax,0b800h
- mov ds,ax
- mov al,'a'
- print_lo:
- call delay
- mov ds:[160*12+40*2],al
- inc al
- cmp al,'z'
- jna print_lo
- pop ds
- pop ax
- ret
- ;--------------------------------------------
- print_warn:
- push ax
- push ds
- mov ax,0b800h
- mov ds,ax
- mov al,'a'
- warn_lo:
- call delay
- mov ds:[160*12+43*2],al
- inc al
- cmp al,'z'
- jna warn_lo
- pop ds
- pop ax
- ret
- delay:
- push ax
- push bx
- mov ax,4000
- mov bx,0
- delay_lo:
- sub bx,1
- sbb ax,0
- cmp bx,0
- jne delay_lo
- cmp ax,0
- jne delay_lo
- pop bx
- pop ax
- ret
- codesg ends
- end start
复制代码
|
|