汇编学习(十)8086汇编拾遗 (9)

Bertha 。 2022-08-22 15:29 315阅读 0赞
  1. 8086 外中断
  2. 可屏蔽中断:
  3. 可屏蔽中断是CPU可以不响应的中断。CPU是否响应屏蔽中断,需要看标志寄存器IF的位置。当CPU检测到可屏蔽中断信息的时候如果IF = 1.CPU在执行完成当前指令后响应中断,引发中断过程;如果IF = 0,则不响应。
  4. 如果在中断处理程序中需要处理可屏蔽中断,可以用指令将IF18086CPU提供的设置IF指令如下:
  5. sti : 设置IF = 1
  6. cli: 设置IF = 0
  7. 不可屏蔽中断:
  8. 不可屏蔽中断是CPU必须响应的中断,当CPU监测到不可屏蔽中断信息的时候,则在执行完当前指令后,立即响应,禁止其它的可屏蔽中断。
  9. 键盘输入:
  10. 键盘的输入会被int 9中断例程所响应.
  11. 一个例子,循环显示a~z
  12. assume cs:code stack segment db 128 dup(0) stack ends code segment start: mov ax,stack mov ss,ax mov sp,128 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,4c00h int 21h delay: push ax push dx mov dx,10h 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 code ends end start

循环打印子母’a’ ~ ‘z’ ,当输入ESC的时候字母变色

  1. assume cs:code
  2. stack segment ;设置栈段
  3. db 128 dup(0)
  4. stack ends
  5. data segment
  6. dw 0,0 ;设置数据段
  7. data ends
  8. code segment
  9. start:
  10. mov ax,stack ;设置ss:sp
  11. mov ss,ax
  12. mov sp,128
  13. mov ax,data ;设置ds ,ds 将会保存原int 9 的中断地址
  14. mov ds,ax
  15. mov ax,0 ;保存原来的int 9 地址
  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 word ptr es:[9*4],offset int9 ;设置新的中断向量地址
  22. mov word ptr es:[9*4+2],cs
  23. mov ax,0b800h
  24. mov es,ax
  25. mov ah,'a'
  26. S:mov es:[160*12+40*2],ah ;循环显示'a'~'z'
  27. call delay
  28. inc ah
  29. cmp ah,'z'
  30. jna s
  31. mov ax,0
  32. mov es,ax
  33. push ds:[0] ;程序将要结束,恢复int9
  34. pop es:[9*4]
  35. push ds:[2]
  36. pop es:[9*4+2]
  37. mov ax,4c00h
  38. int 21h
  39. delay:
  40. push ax ;设置CPU空转时间
  41. push dx
  42. mov dx,10h ;空转指令数10 * 10000H
  43. mov ax,0
  44. s1: sub ax,1
  45. sbb dx,0
  46. cmp ax,0
  47. jne s1
  48. cmp dx,0
  49. jne s1
  50. pop dx
  51. pop ax
  52. ret
  53. int9:
  54. push ax
  55. push bx
  56. push es
  57. in al,60h ;获取中断字节信息
  58. pushf ;保存当前标志位
  59. pushf ;入栈当前标志
  60. pop bx ;标志进入bx
  61. and bh,11111100b ;将标志设置IF = 0 ,TF = 0
  62. push bx ;入栈当前设置标志
  63. popf ;使用当前标志
  64. call dword ptr ds:[0] ;调用原来的中断
  65. cmp al,1 ;比较al是不是ESC扫描码
  66. jne int9ret
  67. mov ax,0b800h
  68. mov es,ax
  69. inc byte ptr es:[160*12+40*2+1]
  70. int9ret:
  71. pop es
  72. pop bx
  73. pop ax
  74. iret
  75. code ends
  76. end start

新的中断程序,按F1就可以全屏变色

  1. assume cs:code
  2. stack segment
  3. db 128 dup(0)
  4. stack ends
  5. code segment
  6. start:
  7. mov ax,stack
  8. mov ss,ax
  9. mov sp,128
  10. push cs
  11. pop ds
  12. mov ax,0
  13. mov es,ax
  14. mov si,offset int9
  15. mov di,204h
  16. mov cx,offset int9end - offset int9
  17. cld
  18. rep movsb
  19. push es:[9*4]
  20. pop es:[200h]
  21. push es:[9*4+2]
  22. pop es:[202h]
  23. cli
  24. mov word ptr es:[9*4],204h
  25. mov word ptr es:[9*4+2],0
  26. sti
  27. mov ax,4c00h
  28. int 21h
  29. int9:
  30. push ax
  31. push bx
  32. push cx
  33. push es
  34. in al,60h
  35. pushf
  36. call dword ptr cs:[200h]
  37. cmp al,3bh
  38. jne int9ret
  39. mov ax,0b800h
  40. mov es,ax
  41. mov bx,1
  42. mov cx,2000
  43. s:
  44. inc byte ptr es:[bx]
  45. add bx,2
  46. loop s
  47. int9ret:pop es
  48. pop cx
  49. pop bx
  50. pop ax
  51. iret
  52. int9end:nop
  53. code ends
  54. end start

按下A 键松开后打印全屏的A

  1. assume cs:code
  2. code segment
  3. start:
  4. mov ax,cs
  5. mov ds,ax
  6. mov ax,0
  7. mov es,ax
  8. mov si,offset int9
  9. mov di,204h
  10. mov cx,offset int9end - offset int9
  11. cld
  12. rep movsb
  13. push es:[9*4]
  14. pop es:[200h]
  15. push es:[9*4+2]
  16. pop es:[202h]
  17. cli
  18. mov word ptr es:[9*4],204h
  19. mov word ptr es:[9*4+2],0
  20. sti
  21. mov ax,4c00h
  22. int 21h
  23. int9:
  24. push ax
  25. push cx
  26. push es
  27. push di
  28. in al,60h
  29. pushf
  30. call dword ptr cs:[200h]
  31. cmp al,1EH+80H
  32. jne int9ret
  33. mov ax,0b800h
  34. mov es,ax
  35. mov di,0
  36. mov cx,80*20
  37. s: mov byte ptr es:[di],'A'
  38. add di,2
  39. loop s
  40. int9ret:pop di
  41. pop es
  42. pop cx
  43. pop ax
  44. iret
  45. int9end:nop
  46. code ends
  47. end start

查看原文:http://zmrlinux.com/2016/06/01/%e6%b1%87%e7%bc%96%e5%ad%a6%e4%b9%a0%ef%bc%88%e5%8d%81%ef%bc%898086%e6%b1%87%e7%bc%96%e6%8b%be%e9%81%97-9/

发表评论

表情:
评论列表 (有 0 条评论,315人围观)

还没有评论,来说两句吧...

相关阅读