鱼C论坛

 找回密码
 立即注册
查看: 2262|回复: 0

[争议讨论] 15-4中断例程int9-代码运行不正常-自己写的却能很好的运行,找不出问题出在哪

[复制链接]
发表于 2013-3-31 15:08:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. ;编程:在屏幕中间依次显示“a”~“z”,并可以让人看清。在显示的过程中,按下'Esc'键后,改变显示的颜色。

  2. ;对更改中断向量时间间隔内可能发生的中断状况作了进一步安全保障 cli ,sti的使用

  3. ;完整功能代码:

  4. assume cs:code

  5. stack segment
  6.         db 128 dup (0)
  7. stack ends

  8. data segment
  9.         dw 0,0
  10. data ends

  11. code segment
  12. start:        mov ax,stack
  13.         mov ss,ax
  14.         mov sp,128
  15.         mov ax,data
  16.         mov ds,ax
  17.         mov ax,0
  18.         mov es,ax



  19.         push es:[9*4]
  20.         pop ds:[0]
  21.         push es:[9*4+2]
  22.         pop ds:[2]                ;将原来的int 9中断例程的入口地址保存在ds:0、ds:2单元中

  23.         cli                        ;置屏蔽中断标志位IF=0

  24.         mov word ptr es:[9*4],offset int9
  25.         mov es:[9*4+2],cs        ;在中断向量表中设置新的int 9中断例程的入口地址

  26.         sti                        ;撤消屏蔽,置屏蔽中断标志位IF=1

  27.         mov ax,0b800h
  28.         mov es,ax
  29.         mov ah,'a'
  30.     s:        mov  es:[160*12+40*2],ah
  31.         call delay
  32.         inc ah
  33.         cmp ah,'z'
  34.         jna s
  35.         mov ax,0
  36.         mov es,ax

  37.         cli                        ;置屏蔽中断标志位IF=0

  38.         push ds:[0]
  39.         pop es:[9*4]
  40.         push ds;[2]
  41.         pop es;[9*4+2]           ;将中断向量表中int 9中断例程的入口恢复为原来的地址

  42.         sti                        ;撤消屏蔽,置屏蔽中断标志位IF=1

  43.         mov ax,4c00h
  44.         int 21h

  45. delay:        push ax
  46.         push dx
  47.         mov dx,2000h
  48.         mov ax,0
  49.   s1:         sub ax,1
  50.         sbb dx,0
  51.         cmp ax,0
  52.         jne s1
  53.         cmp dx,0
  54.         jne s1
  55.         pop dx
  56.         pop ax
  57.         ret

  58. ;------以下为新的int 9中断例程--------------------

  59. int9:        push ax
  60.         push bx
  61.         push es

  62.         in al,60h

  63.         pushf
  64.         ;pushf
  65.         ;pop bx
  66.         ;and bh,11111100b
  67.         ;push bx
  68.         ;popf                        ;去掉了中断处理程序中没有意义的指令语句
  69.         call dword ptr ds:[0]         ;对int指令进行模拟,调用原来的int 9中断例程

  70.         cmp al,1
  71.         jne int9ret

  72.         mov ax,0b800h
  73.         mov es,ax
  74.         inc byte ptr es:[160*12+40*2+1]  ;属性增加1,改变颜色

  75. int9ret:pop es
  76.         pop bx
  77.         pop ax
  78.         iret

  79. code ends
  80. end start
复制代码
上面是习题代码
问题1: 10.jpg 正常运行结束,但按下任意键后,dos就死掉了
问题2:当按键速度过快时,将会出现dos运行终止,并可能会关闭


以上错误,在我写的代码却没有出现,但我始终找不到问题出现在哪里。
我的代码如下
  1. assume cs:codesg

  2. data segment
  3.         dw 16 dup (0)
  4. data ends

  5. stack segment
  6.         dw 128 dup (0)
  7. stack ends
  8. codesg segment
  9.     start:
  10.         mov ax,stack
  11.         mov ss,ax
  12.         mov sp,128

  13.         mov ax,data
  14.         mov ds,ax

  15.         mov ax,0
  16.         mov es,ax

  17.         push es:[9*4]
  18.         pop ds:[0]
  19.         push es:[9*4+2]
  20.         pop ds:[2]

  21.         mov ax,0
  22.         mov es,ax
  23.         cli
  24.         mov word ptr es:[9*4],offset int9
  25.         mov es:[9*4+2],cs
  26.         sti

  27.         ; call print_warn
  28.         ; call print_a_z


  29.         push ax
  30.         push ds

  31.         mov ax,0b800h
  32.         mov ds,ax
  33.         mov al,'a'
  34.     mprint_lo:
  35.         call delay
  36.         mov ds:[160*12+40*2],al
  37.         inc al
  38.         cmp al,'z'

  39.         jna mprint_lo

  40.         pop ds
  41.         pop ax
  42.         ;ret



  43.         cli

  44.         push ds:[0]
  45.         pop es:[9*4]
  46.         push ds:[2]
  47.         pop es:[9*4+2]
  48.         sti
  49.         mov ax,4c00h
  50.         int 21h

  51.     int9:
  52.         push ax
  53.         push ds
  54.         push bx

  55.         in al,60h


  56.         pushf
  57.         pushf
  58.         pop bx
  59.         and bh,11111100b
  60.         push bx
  61.         popf

  62.         mov bx,data
  63.         mov ds,bx
  64.         call dword ptr ds:[0]

  65.         cmp al,1
  66.         jne int9_ret
  67.         mov ax,0b800h
  68.         mov ds,ax
  69.         inc byte ptr ds:[160*12+40*2+1]
  70.   int9_ret:
  71.         pop bx
  72.         pop ds
  73.         pop ax
  74.         iret


  75.     print_a_z:
  76.         push ax
  77.         push ds

  78.         mov ax,0b800h
  79.         mov ds,ax
  80.         mov al,'a'
  81.     print_lo:
  82.         call delay
  83.         mov ds:[160*12+40*2],al
  84.         inc al
  85.         cmp al,'z'

  86.         jna print_lo

  87.         pop ds
  88.         pop ax
  89.         ret

  90.     ;--------------------------------------------
  91.     print_warn:
  92.         push ax
  93.         push ds

  94.         mov ax,0b800h
  95.         mov ds,ax
  96.         mov al,'a'
  97.     warn_lo:
  98.         call delay
  99.         mov ds:[160*12+43*2],al
  100.         inc al
  101.         cmp al,'z'

  102.         jna warn_lo

  103.         pop ds
  104.         pop ax
  105.         ret


  106.     delay:
  107.         push ax
  108.         push bx

  109.         mov ax,4000
  110.         mov bx,0

  111.    delay_lo:
  112.         sub bx,1
  113.         sbb ax,0
  114.         cmp bx,0
  115.         jne delay_lo
  116.         cmp ax,0
  117.         jne delay_lo

  118.         pop bx
  119.         pop ax
  120.         ret

  121. codesg ends
  122. end start
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-3 17:53

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表