鱼C论坛

 找回密码
 立即注册
查看: 4548|回复: 5

[已解决]汇编语言(王爽)实验16_功能子程序跳转问题

[复制链接]
发表于 2021-1-10 16:49:41 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 j450n 于 2021-1-10 16:57 编辑

问题描述:

在原实验基础上结合实验15和16,把该程序写入int9键盘中断,运行后可以输入0~3来检验4个子程序功能。

参考过网上的答案,直接定址表已避开因程序copy而造成偏移地址改变的坑,采用  offset sub1 - offset setscreen + 204h的方式。

实际运行后,只有功能1、2能实现,功能0、3无法实现。通过改变(call word ptr cs:[bx+204h])(即204h改为202,206,208)检验子程序本身并无问题,但不能同时实现4个功能正常运行。

debuge 对int9中断无法单步跟踪,一直找不出问题所在,向论坛大神求助!

代码如下:
  1. assume cs:code

  2. code segment
  3. start:

  4.     mov ax,0
  5.     mov es,ax

  6.     push es:[9*4]
  7.     pop es:[200h]
  8.     push es:[9*4+2]
  9.     pop es:[200h+2]
  10.     ;save BIOS origin int9 to 0:200h~202h

  11.     cli ;IF = 0
  12.     mov word ptr es:[9*4],204h
  13.     mov word ptr es:[9*4+2],0
  14.     sti ;IF = 1
  15.     ;set new int9 entry address as 0:204h

  16.     mov ax,cs
  17.     mov ds,ax
  18.     mov si,offset int9
  19.     mov di,204h
  20.     mov cx,offset int9end-offset int9
  21.     cld ;DF = 0 forward
  22.     rep movsb

  23.     mov ax,4c00h
  24.     int 21h

  25. int9:
  26.     setscreen:        jmp short set
  27.    
  28.         table                dw offset sub1 - offset setscreen + 204h
  29.                                 dw offset sub2 - offset setscreen + 204h
  30.                                 dw offset sub3 - offset setscreen + 204h
  31.                                 dw offset sub4 - offset setscreen + 204h
  32.                        
  33. set:       
  34.     push bx
  35.     push ax
  36.     push es
  37.     push cx
  38.     push di

  39.     mov ax,0
  40.     mov es,ax
  41.     pushf           
  42.     call dword ptr es:[200h]
  43.     ;call original int9

  44.     in al,60h
  45.     mov ah,al
  46.     mov al,4
  47.         cmp ah,3
  48.         ja sret
  49.         mov bl,ah
  50.         mov bh,0
  51.         add bx,bx
  52.         call word ptr cs:[bx+204h]

  53. sret:
  54.     pop di
  55.     pop cx
  56.     pop es
  57.     pop ax
  58.     pop bx
  59.     ;CAN NOT add popf here, it's done in call original int9
  60.     iret

  61. sub1:                                        ;1号子程序
  62.         push bx
  63.         push cx
  64.         push es
  65.         mov bx,0b800h
  66.         mov es,bx
  67.         mov bx,0
  68.         mov cx,2000
  69.   sub1s:
  70.         mov byte ptr es:[bx],' '
  71.         add bx,2
  72.         loop sub1s
  73.         pop es
  74.         pop cx
  75.         pop bx
  76.         ret

  77. sub2:                                        ;2号子程序
  78.         push bx
  79.         push cx
  80.         push es
  81.         mov bx,0b800h
  82.         mov es,bx
  83.         mov bx,1
  84.         mov cx,2000
  85. sub2s:
  86.         and byte ptr es:[bx],11111000b
  87.         or es:[bx],al
  88.         add bx,2
  89.         loop sub2s
  90.         pop es
  91.         pop cx
  92.         pop bx
  93.         ret

  94. sub3:                                        ;3号子程序
  95.         push bx
  96.         push cx
  97.         push es
  98.         mov cl,4
  99.         shl al,cl
  100.         mov bx,0b800h
  101.         mov es,bx
  102.         mov bx,1
  103.         mov cx,2000
  104. sub3s:
  105.         and byte ptr es:[bx],10001111b
  106. ;        shl al,1
  107. ;        shl al,1
  108. ;        shl al,1
  109. ;        shl al,1
  110.         or es:[bx],al
  111.         add bx,2
  112.         loop sub3s
  113.         pop es
  114.         pop cx
  115.         pop bx
  116.         ret

  117. sub4:                                        ;4号子程序
  118.         push cx
  119.         push si
  120.         push di
  121.         push es
  122.         push ds

  123.         mov si,0b800h
  124.         mov es,si
  125.         mov ds,si
  126.         mov si,160
  127.         mov di,0
  128.         cld
  129.         mov cx,24
  130. sub4s:
  131.         push cx
  132.         mov cx,160
  133.         rep movsb
  134.         pop cx
  135.         loop sub4s

  136.         mov cx,80
  137.         mov si,0
  138. sub4s1:
  139.         mov byte ptr [160*24+si],' '
  140.         add si,2
  141.         loop sub4s1
  142.        
  143.         pop ds
  144.         pop es
  145.         pop di
  146.         pop si
  147.         pop cx
  148.         ret

  149. int9end: nop

  150. code ends
  151. end start
复制代码
最佳答案
2021-1-11 01:55:47
in al,60h 获取的是键盘扫描码
输入 0, 1, 2, 3 得到的扫描码为 B, 2, 3, 4
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-1-11 01:55:47 | 显示全部楼层    本楼为最佳答案   
in al,60h 获取的是键盘扫描码
输入 0, 1, 2, 3 得到的扫描码为 B, 2, 3, 4
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-1-11 11:25:12 | 显示全部楼层
本帖最后由 j450n 于 2021-1-11 11:27 编辑
wtchou 发表于 2021-1-11 01:55
in al,60h 获取的是键盘扫描码
输入 0, 1, 2, 3 得到的扫描码为 B, 2, 3, 4


多谢大神提醒!问题解决了!
结果最头疼的bug其实是最低级的错误


终于运行正常了
(功能号改为1-4)
Screenshot from 2021-01-11 11-20-29.png
Screenshot from 2021-01-11 11-21-33.png
Screenshot from 2021-01-11 11-21-42.png
Screenshot from 2021-01-11 11-21-53.png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-2-19 09:45:17 | 显示全部楼层
wtchou 发表于 2021-1-11 01:55
in al,60h 获取的是键盘扫描码
输入 0, 1, 2, 3 得到的扫描码为 B, 2, 3, 4
  1. int9:
  2.     setscreen:        jmp short set
  3.    
  4.         table                dw offset sub1 - offset setscreen + 204h
  5.                                 dw offset sub2 - offset setscreen + 204h
  6.                                 dw offset sub3 - offset setscreen + 204h
  7.                                 dw offset sub4 - offset setscreen + 204h
  8.                        
复制代码


接原帖里的代码,想再请教一下
直接定址表如果被安装到内存中另外一个位置,是不是就无法再用了,必须按上述引用的计算地址的方式来写吗?有没有其他的解决方法?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-2-20 20:18:25 | 显示全部楼层
定址表里的内容都是原程序的地址, 所以我自己也是用类似的方法去处理
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-2-22 10:17:21 | 显示全部楼层
wtchou 发表于 2021-2-20 20:18
定址表里的内容都是原程序的地址, 所以我自己也是用类似的方法去处理

好的,tks
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-6-8 10:25

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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