鱼C论坛

 找回密码
 立即注册
楼主: wyuri

王爽汇编问题

[复制链接]
发表于 2017-4-11 14:29:47 | 显示全部楼层
wyuri 发表于 2017-4-11 12:27
你的意思是说只要我按键盘上的按键就产生中断了,然后就设置iftf为0 了是么?
书上是这样写的第十五章: ...

我花了点时间写了一个debug程序^_^
实现了debug程序的核心功能
你看看能不能看懂

test.asm
  1. assume cs:code, ds:data, ss:stack

  2. extrn show_hex:far

  3. stack segment
  4.         db 100 dup(?)
  5. stack ends

  6. data segment
  7.         debug_code_address dd 0
  8.         original_int3_address dd 0
  9.         int3_server_run db "int3_server_run!", 0dh, 0ah, "$"
  10. data ends

  11. code segment

  12. ;安装int3中断服务程序
  13. init:
  14.         push es
  15.        
  16.         mov ax, 0
  17.         mov es, ax
  18.        
  19.         push es:[1 * 4]
  20.         pop word ptr [original_int3_address]
  21.         push es:[1 * 4 + 2]
  22.         pop word ptr [original_int3_address + 2]
  23.        
  24.        
  25.         cli
  26.         mov ax, int3_server
  27.         push ax
  28.         pop es:[1 * 4]
  29.         push cs
  30.         pop es:[1 * 4 + 2]
  31.         sti
  32.        
  33.         pop es
  34.         ret

  35. int3_server:
  36.         push bp
  37.         mov bp, sp
  38.        
  39.         push ax
  40.         push bx
  41.         push cx
  42.         push dx
  43.        
  44.         push ds
  45.        
  46.         mov ax, data
  47.         mov ds, ax
  48.        
  49.         mov ah, 9
  50.         mov dx, offset int3_server_run
  51.         int 21h
  52.        
  53. ;********************************************************************       
  54.         ;显示寄存器
  55.         push [bp - 2]
  56.         call far ptr show_hex
  57.         add sp, 2
  58.        
  59.         ;输出空格
  60.         mov ah, 0eh
  61.         mov al, ' '
  62.         int 10h
  63.        
  64.         push [bp - 4]
  65.         call far ptr show_hex
  66.         add sp, 2
  67.        
  68.         mov ah, 0eh
  69.         mov al, ' '
  70.         int 10h
  71.        
  72.         push [bp - 6]
  73.         call far ptr show_hex
  74.         add sp, 2
  75.        
  76.         mov ah, 0eh
  77.         mov al, ' '
  78.         int 10h
  79.        
  80.         push [bp - 8]
  81.         call far ptr show_hex
  82.         add sp, 2
  83.        
  84.         mov ah, 0eh
  85.         mov al, 0dh
  86.         int 10h
  87.        
  88.         mov ah, 0eh
  89.         mov al, 0ah
  90.         int 10h
  91.        
  92. ;*************************************************************************       
  93.        
  94.         pop ds
  95.        
  96.         pop dx
  97.         pop cx
  98.         pop bx
  99.         pop ax
  100.        
  101.         mov sp, bp
  102.         pop bp
  103.         iret ;返回到被中断程序的下一条指令
  104. start:
  105.         mov ax, stack
  106.         mov ss, ax
  107.         mov sp, 100
  108.        
  109.         mov ax, data
  110.         mov ds, ax
  111.        
  112.         call init; 安装中断向量
  113.        
  114.         mov ax, debug_it_start
  115.         mov word ptr [debug_code_address], ax
  116.         mov ax, debug_it_code
  117.         mov word ptr [debug_code_address + 2], ax
  118.        
  119.         ;设置tf 和 if
  120.         pushf
  121.         pop ax
  122.         or ah, 00000011b
  123.         push ax
  124.         popf
  125.        
  126.         push word ptr [debug_code_address + 2]
  127.         push word ptr [debug_code_address]
  128.        
  129.         iret ;返回到调试程序,在这里返回到 debug_it_start,也就是 mov ax, debug_it_stack 这条指令
  130.        
  131.         mov ax,4c00h
  132.         int 21h
  133. code ends

  134. ;********************** 被调试程序 ***********************************************

  135. debug_it_data segment
  136.         string db "debuging!", 0dh, 0ah, '

  137. show_hex.asm
  138. [code]assume cs:code

  139. public show_hex

  140. code segment

  141. ;子程序需要远调用 call far ptr show_hex
  142. ;显示十六进制数到屏幕
  143. ;void show_hex(word data);
  144. show_hex:
  145.         push bp
  146.         mov bp, sp
  147.         ;sub sp, 10h
  148.         
  149.         push ax
  150.         push bx
  151.         push cx
  152.         push dx
  153.         
  154.         mov ax, [bp + 6] ;mov ax, data
  155.         
  156.         mov cx, 4
  157. show_hex_s:
  158.         mov bx, ax
  159.         and bx, 0f000h
  160.         
  161.         push cx
  162.         mov cl, 12
  163.         shr bx, cl
  164.         pop cx
  165.         
  166.         cmp bx, 0ah
  167.         jl show_hex_less_a
  168.         
  169.         sub bx, 0ah
  170.         add bx, 'A'
  171.         jmp show_hex_less_n
  172.         
  173. show_hex_less_a:
  174.         add bx, '0'

  175. show_hex_less_n:
  176.         push ax
  177.         
  178.         ;输出bl中的字符
  179.         mov ah, 0eh
  180.         mov al, bl
  181.         int 10h
  182.         
  183.         pop ax
  184.         
  185.         
  186.         push cx
  187.         mov cl, 4
  188.         shl ax, cl
  189.         pop cx
  190.         loop show_hex_s
  191.         
  192.        
  193.         pop dx
  194.         pop cx
  195.         pop bx
  196.         pop ax
  197.         
  198.         mov sp, bp
  199.         pop bp
  200.         retf ;远调用返回
  201. code ends

  202. end
复制代码



ml show_hex.asm /c
ml test.asm show_hex.obj
cls
test.exe

  1. D:\Masm615>test.exe
  2. int3_server_run!
  3. 3302 0000 00FF 0588
  4. int3_server_run!
  5. 3302 0000 00FF 0588
  6. int3_server_run!
  7. 3302 0000 00FF 0588
  8. int3_server_run!
  9. 05AF 0000 00FF 0588
  10. int3_server_run!
  11. 05AF 0000 00FF 0588
  12. int3_server_run!
  13. 05AE 0000 00FF 0588
  14. int3_server_run!
  15. 05AE 0000 00FF 0588
  16. int3_server_run!
  17. 09AE 0000 00FF 0588
  18. int3_server_run!
  19. 09AE 0000 00FF 0000
  20. debuging!
  21. int3_server_run!
  22. 4C00 0000 00FF 0000

  23. D:\Masm615>
复制代码

debug_it_data ends

debug_it_stack segment
        db 100 dup(?)
debug_it_stack ends

;只是显示一句话
debug_it_code segment
debug_it_start:
       
        mov ax, debug_it_stack
        mov ss, ax
        mov sp, 100
       
        mov ax, debug_it_data
        mov ds, ax
       
        mov ah, 9
        mov dx, offset string
        int 21h
       
        mov ax, 4c00h
        int 21h
       
debug_it_code ends

end start
[/code]

show_hex.asm



ml show_hex.asm /c
ml test.asm show_hex.obj
cls
test.exe

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

使用道具 举报

发表于 2017-4-11 14:37:22 | 显示全部楼层
人造人 发表于 2017-4-11 14:29
我花了点时间写了一个debug程序^_^
实现了debug程序的核心功能
你看看能不能看懂

上面怎么回事?
我重新发一下吧

show_hex.asm
  1. assume cs:code

  2. public show_hex

  3. code segment

  4. ;子程序需要远调用 call far ptr show_hex
  5. ;显示十六进制数到屏幕
  6. ;void show_hex(word data);
  7. show_hex:
  8.         push bp
  9.         mov bp, sp
  10.         ;sub sp, 10h
  11.         
  12.         push ax
  13.         push bx
  14.         push cx
  15.         push dx
  16.         
  17.         mov ax, [bp + 6] ;mov ax, data
  18.         
  19.         mov cx, 4
  20. show_hex_s:
  21.         mov bx, ax
  22.         and bx, 0f000h
  23.         
  24.         push cx
  25.         mov cl, 12
  26.         shr bx, cl
  27.         pop cx
  28.         
  29.         cmp bx, 0ah
  30.         jl show_hex_less_a
  31.         
  32.         sub bx, 0ah
  33.         add bx, 'A'
  34.         jmp show_hex_less_n
  35.         
  36. show_hex_less_a:
  37.         add bx, '0'

  38. show_hex_less_n:
  39.         push ax
  40.         
  41.         ;输出bl中的字符
  42.         mov ah, 0eh
  43.         mov al, bl
  44.         int 10h
  45.         
  46.         pop ax
  47.         
  48.         
  49.         push cx
  50.         mov cl, 4
  51.         shl ax, cl
  52.         pop cx
  53.         loop show_hex_s
  54.         
  55.        
  56.         pop dx
  57.         pop cx
  58.         pop bx
  59.         pop ax
  60.         
  61.         mov sp, bp
  62.         pop bp
  63.         retf ;远调用返回
  64. code ends

  65. end
复制代码



test.asm
  1. assume cs:code, ds:data, ss:stack

  2. extrn show_hex:far

  3. stack segment
  4.         db 100 dup(?)
  5. stack ends

  6. data segment
  7.         debug_code_address dd 0
  8.         original_int3_address dd 0
  9.         int3_server_run db "int3_server_run!", 0dh, 0ah, "$"
  10. data ends

  11. code segment

  12. ;安装int3中断服务程序
  13. init:
  14.         push es
  15.        
  16.         mov ax, 0
  17.         mov es, ax
  18.        
  19.         push es:[1 * 4]
  20.         pop word ptr [original_int3_address]
  21.         push es:[1 * 4 + 2]
  22.         pop word ptr [original_int3_address + 2]
  23.        
  24.        
  25.         cli
  26.         mov ax, int3_server
  27.         push ax
  28.         pop es:[1 * 4]
  29.         push cs
  30.         pop es:[1 * 4 + 2]
  31.         sti
  32.        
  33.         pop es
  34.         ret

  35. int3_server:
  36.         push bp
  37.         mov bp, sp
  38.        
  39.         push ax
  40.         push bx
  41.         push cx
  42.         push dx
  43.        
  44.         push ds
  45.        
  46.         mov ax, data
  47.         mov ds, ax
  48.        
  49.         mov ah, 9
  50.         mov dx, offset int3_server_run
  51.         int 21h
  52.        
  53. ;********************************************************************       
  54.         ;显示寄存器
  55.         push [bp - 2]
  56.         call far ptr show_hex
  57.         add sp, 2
  58.        
  59.         ;输出空格
  60.         mov ah, 0eh
  61.         mov al, ' '
  62.         int 10h
  63.        
  64.         push [bp - 4]
  65.         call far ptr show_hex
  66.         add sp, 2
  67.        
  68.         mov ah, 0eh
  69.         mov al, ' '
  70.         int 10h
  71.        
  72.         push [bp - 6]
  73.         call far ptr show_hex
  74.         add sp, 2
  75.        
  76.         mov ah, 0eh
  77.         mov al, ' '
  78.         int 10h
  79.        
  80.         push [bp - 8]
  81.         call far ptr show_hex
  82.         add sp, 2
  83.        
  84.         mov ah, 0eh
  85.         mov al, 0dh
  86.         int 10h
  87.        
  88.         mov ah, 0eh
  89.         mov al, 0ah
  90.         int 10h
  91.        
  92. ;*************************************************************************       
  93.        
  94.         pop ds
  95.        
  96.         pop dx
  97.         pop cx
  98.         pop bx
  99.         pop ax
  100.        
  101.         mov sp, bp
  102.         pop bp
  103.         iret ;返回到被中断程序的下一条指令
  104. start:
  105.         mov ax, stack
  106.         mov ss, ax
  107.         mov sp, 100
  108.        
  109.         mov ax, data
  110.         mov ds, ax
  111.        
  112.         call init; 安装中断向量
  113.        
  114.         mov ax, debug_it_start
  115.         mov word ptr [debug_code_address], ax
  116.         mov ax, debug_it_code
  117.         mov word ptr [debug_code_address + 2], ax
  118.        
  119.         ;设置tf 和 if
  120.         pushf
  121.         pop ax
  122.         or ah, 00000011b
  123.         push ax
  124.         popf
  125.        
  126.         push word ptr [debug_code_address + 2]
  127.         push word ptr [debug_code_address]
  128.        
  129.         iret ;返回到调试程序,在这里返回到 debug_it_start,也就是 mov ax, debug_it_stack 这条指令
  130.        
  131.         mov ax,4c00h
  132.         int 21h
  133. code ends

  134. ;********************** 被调试程序 ***********************************************

  135. debug_it_data segment
  136.         string db "debuging!", 0dh, 0ah, '


  137. [code]ml show_hex.asm /c
  138. ml test.asm show_hex.obj
  139. cls
  140. test.exe
复制代码

  1. D:\Masm615>test.exe
  2. int3_server_run!
  3. 3302 0000 00FF 0588
  4. int3_server_run!
  5. 3302 0000 00FF 0588
  6. int3_server_run!
  7. 3302 0000 00FF 0588
  8. int3_server_run!
  9. 05AF 0000 00FF 0588
  10. int3_server_run!
  11. 05AF 0000 00FF 0588
  12. int3_server_run!
  13. 05AE 0000 00FF 0588
  14. int3_server_run!
  15. 05AE 0000 00FF 0588
  16. int3_server_run!
  17. 09AE 0000 00FF 0588
  18. int3_server_run!
  19. 09AE 0000 00FF 0000
  20. debuging!
  21. int3_server_run!
  22. 4C00 0000 00FF 0000

  23. D:\Masm615>
复制代码

debug_it_data ends

debug_it_stack segment
        db 100 dup(?)
debug_it_stack ends

;只是显示一句话
debug_it_code segment
debug_it_start:
       
        mov ax, debug_it_stack
        mov ss, ax
        mov sp, 100
       
        mov ax, debug_it_data
        mov ds, ax
       
        mov ah, 9
        mov dx, offset string
        int 21h
       
        mov ax, 4c00h
        int 21h
       
debug_it_code ends

end start
[/code]




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

使用道具 举报

发表于 2017-4-11 14:38:54 | 显示全部楼层
无语了,怎么还是这样?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-4-11 14:42:26 | 显示全部楼层
ml show_hex.asm /c
ml test.asm show_hex.obj
cls
test.exe

test_asm__show_hex_asm.zip (1.5 KB, 下载次数: 1)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-4-11 14:43:14 | 显示全部楼层
D:\Masm615>test.exe
int3_server_run!
3302 0000 00FF 0588
int3_server_run!
3302 0000 00FF 0588
int3_server_run!
3302 0000 00FF 0588
int3_server_run!
05AF 0000 00FF 0588
int3_server_run!
05AF 0000 00FF 0588
int3_server_run!
05AE 0000 00FF 0588
int3_server_run!
05AE 0000 00FF 0588
int3_server_run!
09AE 0000 00FF 0588
int3_server_run!
09AE 0000 00FF 0000
debuging!
int3_server_run!
4C00 0000 00FF 0000

D:\Masm615>
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-4-13 15:26:29 | 显示全部楼层
人造人 发表于 2017-4-11 14:29
我花了点时间写了一个debug程序^_^
实现了debug程序的核心功能
你看看能不能看懂

I'm very very very thankyou
我非常非常非常感谢,能耗时间管我这个菜鸟,我真的真的真的非常感谢,谢谢。
不过我看了一下程序,我理解的就是下面图片显示的,我尝试着去理解,但还是不太清楚,程序在说明什么,他与我问的问题很密切相关么
问题22.jpg
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-4-13 15:54:57 | 显示全部楼层
wyuri 发表于 2017-4-13 15:26
I'm very very very thankyou
我非常非常非常感谢,能耗时间管我这个菜鸟,我真的真的真的非常感谢,谢 ...

无标题.png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-4-13 16:04:11 | 显示全部楼层
wyuri 发表于 2017-4-13 15:26
I'm very very very thankyou
我非常非常非常感谢,能耗时间管我这个菜鸟,我真的真的真的非常感谢,谢 ...


int 9中断例程 和 int 1 中断例程(单步中断例程) ,都是中断例程,有什么区别?

你不明白为什么可以那样调用int 9中断例程,我举了一个int 1的例子
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-4-13 16:18:59 | 显示全部楼层
一个程序(test.exe)正在执行,突然来了一个中断,一般情况下,处理器响应中断,那么处理器需要保存当前工作状态,转去执行中断服务程序,那么处理器是如何保存当前的工作状态的?保存在哪里?执行完中断服务程序后,为什么能继续执行之前的那个(test.exe)程序?在中断服务程序中堆栈中有些什么?为什么还可以像这样调用int 9中断例程?
无标题.png

中断例程执行,需要什么环境?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-4-13 16:20:22 | 显示全部楼层
这一切需要从正在执行的那个test.exe程序说起
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-4-13 16:35:20 | 显示全部楼层
假设 test.exe 程序中有这些
  1.         mov ax, stack
  2.         mov ss, ax
  3.         mov sp, 100
  4.         
  5.         mov ax, data
  6.         mov ds, ax
复制代码


处理器正在执行 mov ax, data,突然来了中断
那么处理器执行完mov ax, data 这条指令后响应中断,
  1. 1 从中断信息中 取得中断类型码

  2. 2 标志寄存器的值入栈 因为在中断过程
  3. 中要改变标志寄存器的值所以先将其保存在栈中

  4. 3 设置标志寄存器的第8位TF 和第9位IF的值为0

  5. 4 CS的内容入栈

  6. 5 IP的内容入栈

  7. 6 从内存地址为中断类型码*4 和中断类型码*4+2 的两个字单元中读取中断处理程序的入口地址设置IP和CS。
复制代码


pushf
TF = 0, IF = 0
push CS
push IP

无标题.png
无标题1.png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-4-13 20:00:30 | 显示全部楼层
人造人 发表于 2017-4-13 16:18
一个程序(test.exe)正在执行,突然来了一个中断,一般情况下,处理器响应中断,那么处理器需要保存当前工 ...

您没明白我的意思,这样吧,我现在发不了图了,我明天发图,好好组织一下我的疑惑,您能仔细看完么?因为这两天的我的问题,和您给的答案有点对不上^_^   ̄▽ ̄
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-4-13 20:07:51 | 显示全部楼层
人造人 发表于 2017-4-13 16:35
假设 test.exe 程序中有这些

对,我的意思就是要设置if和tf等于0,而程序的后面课后题说,if和tf不用设置了。我一直都是在问你这个问题,为什么不用设置了。
大哥我只求你一件事,如果您忙的话你可以不用理我,如果想帮我这个菜鸟解惑,麻烦您把下面我发的图片内容仔细看完好么,这两天由于我语言组织能力问题,说不清楚导致您帮我解惑的问题都是答非所问,因为我语言组织能力的问题所以我问的大家都不明白什么意思,没人理我,就您总告诉,真的真的真的超级感谢。我从新组织一下我的疑惑。 好么,拜托了。真心感谢谢谢^_^
问题23.jpg
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-4-13 20:10:28 | 显示全部楼层
wyuri 发表于 2017-4-13 20:07
对,我的意思就是要设置if和tf等于0,而程序的后面课后题说,if和tf不用设置了。我一直都是在问你这个问 ...

拜托各位,看完这个图片说的内容好不好
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-4-13 20:41:54 | 显示全部楼层
wyuri 发表于 2017-4-13 20:07
对,我的意思就是要设置if和tf等于0,而程序的后面课后题说,if和tf不用设置了。我一直都是在问你这个问 ...

tf 和 if 不是中断例程设置的
是在进入中断例程之前,硬件设置的(应该是cpu设置的)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-4-18 09:30:45 | 显示全部楼层
人造人 发表于 2017-4-13 20:41
tf 和 if 不是中断例程设置的
是在进入中断例程之前,硬件设置的(应该是cpu设置的)

那寄存器的push 和pop 的顺序呢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-4-18 09:39:00 | 显示全部楼层
人造人 发表于 2017-4-13 20:41
tf 和 if 不是中断例程设置的
是在进入中断例程之前,硬件设置的(应该是cpu设置的)

那这个怎么解释啊
问题24.jpg
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-4-18 12:20:50 | 显示全部楼层
wyuri 发表于 2017-4-18 09:30
那寄存器的push 和pop 的顺序呢

在int 9 内部使用 iret 返回了呀
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-4-18 12:23:41 | 显示全部楼层
wyuri 发表于 2017-4-18 09:30
那寄存器的push 和pop 的顺序呢

push 和 pop 的顺序没有问题呀
建议你重新看看第12章
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-4-18 12:29:34 | 显示全部楼层
wyuri 发表于 2017-4-18 09:39
那这个怎么解释啊

int 指令相当于一个特殊的 call 指令
call指令 call的是一个内存地址
int指令 call的是中断向量表中指向的一个过程
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-7-1 16:56

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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