|
发表于 2017-4-11 14:37:22
|
显示全部楼层
上面怎么回事?
我重新发一下吧
show_hex.asm
- assume cs:code
- public show_hex
- code segment
- ;子程序需要远调用 call far ptr show_hex
- ;显示十六进制数到屏幕
- ;void show_hex(word data);
- show_hex:
- push bp
- mov bp, sp
- ;sub sp, 10h
-
- push ax
- push bx
- push cx
- push dx
-
- mov ax, [bp + 6] ;mov ax, data
-
- mov cx, 4
- show_hex_s:
- mov bx, ax
- and bx, 0f000h
-
- push cx
- mov cl, 12
- shr bx, cl
- pop cx
-
- cmp bx, 0ah
- jl show_hex_less_a
-
- sub bx, 0ah
- add bx, 'A'
- jmp show_hex_less_n
-
- show_hex_less_a:
- add bx, '0'
- show_hex_less_n:
- push ax
-
- ;输出bl中的字符
- mov ah, 0eh
- mov al, bl
- int 10h
-
- pop ax
-
-
- push cx
- mov cl, 4
- shl ax, cl
- pop cx
- loop show_hex_s
-
-
- pop dx
- pop cx
- pop bx
- pop ax
-
- mov sp, bp
- pop bp
- retf ;远调用返回
- code ends
- end
复制代码
test.asm
- assume cs:code, ds:data, ss:stack
- extrn show_hex:far
- stack segment
- db 100 dup(?)
- stack ends
- data segment
- debug_code_address dd 0
- original_int3_address dd 0
- int3_server_run db "int3_server_run!", 0dh, 0ah, "$"
- data ends
- code segment
- ;安装int3中断服务程序
- init:
- push es
-
- mov ax, 0
- mov es, ax
-
- push es:[1 * 4]
- pop word ptr [original_int3_address]
- push es:[1 * 4 + 2]
- pop word ptr [original_int3_address + 2]
-
-
- cli
- mov ax, int3_server
- push ax
- pop es:[1 * 4]
- push cs
- pop es:[1 * 4 + 2]
- sti
-
- pop es
- ret
- int3_server:
- push bp
- mov bp, sp
-
- push ax
- push bx
- push cx
- push dx
-
- push ds
-
- mov ax, data
- mov ds, ax
-
- mov ah, 9
- mov dx, offset int3_server_run
- int 21h
-
- ;********************************************************************
- ;显示寄存器
- push [bp - 2]
- call far ptr show_hex
- add sp, 2
-
- ;输出空格
- mov ah, 0eh
- mov al, ' '
- int 10h
-
- push [bp - 4]
- call far ptr show_hex
- add sp, 2
-
- mov ah, 0eh
- mov al, ' '
- int 10h
-
- push [bp - 6]
- call far ptr show_hex
- add sp, 2
-
- mov ah, 0eh
- mov al, ' '
- int 10h
-
- push [bp - 8]
- call far ptr show_hex
- add sp, 2
-
- mov ah, 0eh
- mov al, 0dh
- int 10h
-
- mov ah, 0eh
- mov al, 0ah
- int 10h
-
- ;*************************************************************************
-
- pop ds
-
- pop dx
- pop cx
- pop bx
- pop ax
-
- mov sp, bp
- pop bp
- iret ;返回到被中断程序的下一条指令
- start:
- mov ax, stack
- mov ss, ax
- mov sp, 100
-
- mov ax, data
- mov ds, ax
-
- call init; 安装中断向量
-
- mov ax, debug_it_start
- mov word ptr [debug_code_address], ax
- mov ax, debug_it_code
- mov word ptr [debug_code_address + 2], ax
-
- ;设置tf 和 if
- pushf
- pop ax
- or ah, 00000011b
- push ax
- popf
-
- push word ptr [debug_code_address + 2]
- push word ptr [debug_code_address]
-
- iret ;返回到调试程序,在这里返回到 debug_it_start,也就是 mov ax, debug_it_stack 这条指令
-
- mov ax,4c00h
- int 21h
- code ends
- ;********************** 被调试程序 ***********************************************
- debug_it_data segment
- string db "debuging!", 0dh, 0ah, '
- [code]ml show_hex.asm /c
- ml test.asm show_hex.obj
- cls
- test.exe
复制代码
- 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>
复制代码
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]
|
|