- UID
- 2198
注册时间2005-6-29
阅读权限255
最后登录1970-1-1
副坛主
该用户从未签到
|
紧凑模式:
seg000:01BC ; int __cdecl main(int argc, const char **argv, const char *envp)
seg000:01BC _main proc near ; CODE XREF: start+FDp
seg000:01BC mov ax, 17h
seg000:01BF push ax ; n
seg000:01C0 push ds
seg000:01C1 mov ax, 94h ; '?
seg000:01C4 push ax ; src
seg000:01C5 mov dx, 0B000h
seg000:01C8 mov ax, 8544h
seg000:01CB push dx
seg000:01CC push ax ; dest
seg000:01CD call _memcpy
seg000:01D0 add sp, 0Ah
seg000:01D3 retn
seg000:01D3 _main endp
seg000:0892 ; void *__cdecl memcpy(void *dest, const void *src, size_t n)
seg000:0892 _memcpy proc near ; CODE XREF: _main+11p
seg000:0892
seg000:0892 dest = dword ptr 4
seg000:0892 src = dword ptr 8
seg000:0892 n = word ptr 0Ch
seg000:0892
seg000:0892 push bp
seg000:0893 mov bp, sp
seg000:0895 push si
seg000:0896 push di
seg000:0897 mov dx, ds
seg000:0899 les di, [bp+dest] // 将前两位(偏移地址)装入DI 后俩字节(段地址)装入ES
seg000:089C lds si, [bp+src] // 将前两位(偏移地址)装入SI 后俩字节(段地址)装入DS
seg000:089F mov cx, [bp+n]
seg000:08A2 shr cx, 1
seg000:08A4 cld
seg000:08A5 rep movsw
seg000:08A7 jnb short loc_108AA
seg000:08A9 movsb
seg000:08AA
seg000:08AA loc_108AA: ; CODE XREF: _memcpy+15j
seg000:08AA mov ds, dx
seg000:08AC mov dx, word ptr [bp+dest+2]
seg000:08AF mov ax, word ptr [bp+dest]
seg000:08B2 jmp short $+2
seg000:08B4 pop di
seg000:08B5 pop si
seg000:08B6 pop bp
seg000:08B7 retn
seg000:08B7 _memcpy endp
在Debug中看到的执行情况:
AX=8544 BX=0088 CX=000D DX=0C5C SP=0FE0 BP=0FE4 SI=100C DI=05AA
DS=0C5C ES=0B63 SS=0C73 CS=0BD0 IP=0899 NV UP EI PL ZR NA PE NC
0BD0:0899 C47E04 LES DI,[BP+04] SS:0FE8=8544
-t
AX=8544 BX=0088 CX=000D DX=0C5C SP=0FE0 BP=0FE4 SI=100C DI=8544
DS=0C5C ES=B000 SS=0C73 CS=0BD0 IP=089C NV UP EI PL ZR NA PE NC
0BD0:089C C57608 LDS SI,[BP+08] SS:0FEC=0094
-t
AX=8544 BX=0088 CX=000D DX=0C5C SP=0FE0 BP=0FE4 SI=0094 DI=8544
DS=0C5C ES=B000 SS=0C73 CS=0BD0 IP=089F NV UP EI PL ZR NA PE NC
0BD0:089F 8B4E0C MOV CX,[BP+0C] SS:0FF0=0017
-d ss:0fe0
0C73:0FE0 AA 05 0C 10 02 10 D0 01-44 85 00 B0 94 00 5C 0C ........D.....\.
0C73:0FF0 17 00 00 01 01 00 FE 0F-73 0C 08 00 74 0D 06 10 ........s...t...
==================================================================
Small 模式:
seg000:01FA ; int __cdecl main(int argc, const char **argv, const char *envp)
seg000:01FA _main proc near ; CODE XREF: start+11Ap
seg000:01FA mov ax, 17h
seg000:01FD push ax
seg000:01FE mov ax, 194h
seg000:0201 push ax ; src
seg000:0202 mov dx, 0B000h
seg000:0205 mov ax, 8544h
seg000:0208 push dx
seg000:0209 push ax ; dest
seg000:020A call _memcpy
seg000:020D add sp, 8
seg000:0210 retn
seg000:0210 _main endp
seg000:0567 ; void *__cdecl memcpy(void *dest, const void *src, size_t n)
seg000:0567 _memcpy proc near ; CODE XREF: _main+10p
seg000:0567
seg000:0567 dest = word ptr 4
seg000:0567 arg_2 = word ptr 6
seg000:0567 src = word ptr 8
seg000:0567 n = word ptr 0Ch
seg000:0567
seg000:0567 push bp
seg000:0568 mov bp, sp
seg000:056A push si
seg000:056B push di
seg000:056C push ds
seg000:056D pop es
seg000:056E assume es:dseg
seg000:056E mov di, [bp+dest]
seg000:0571 mov si, [bp+arg_2] // 这里把段地址给放到SI中去了
seg000:0574 mov cx, [bp+src] // 这里把 本应该放SI中的源数据地址给整CX中去了 晕死 ~~
seg000:0577 shr cx, 1
seg000:0579 cld
seg000:057A rep movsw
seg000:057C jnb short loc_1057F
seg000:057E movsb
seg000:057F
seg000:057F loc_1057F: ; CODE XREF: _memcpy+15j
seg000:057F mov ax, [bp+dest]
seg000:0582 jmp short $+2
seg000:0584 pop di
seg000:0585 pop si
seg000:0586 pop bp
seg000:0587 retn
seg000:0587 _memcpy endp
seg000:0587
在Debug中跟踪到的数据:
AX=8544 BX=07F8 CX=000D DX=B000 SP=FFDA BP=FFDE SI=05AB DI=07B2
DS=0C29 ES=0C29 SS=0C29 CS=0BD0 IP=056C NV UP EI PL ZR NA PE NC
0BD0:056C 1E PUSH DS
-t
AX=8544 BX=07F8 CX=000D DX=B000 SP=FFD8 BP=FFDE SI=05AB DI=07B2
DS=0C29 ES=0C29 SS=0C29 CS=0BD0 IP=056D NV UP EI PL ZR NA PE NC
0BD0:056D 07 POP ES
-t
AX=8544 BX=07F8 CX=000D DX=B000 SP=FFDA BP=FFDE SI=05AB DI=07B2
DS=0C29 ES=0C29 SS=0C29 CS=0BD0 IP=056E NV UP EI PL ZR NA PE NC
0BD0:056E 8B7E04 MOV DI,[BP+04] SS:FFE2=8544
-t
AX=8544 BX=07F8 CX=000D DX=B000 SP=FFDA BP=FFDE SI=05AB DI=8544
DS=0C29 ES=0C29 SS=0C29 CS=0BD0 IP=0571 NV UP EI PL ZR NA PE NC
0BD0:0571 8B7606 MOV SI,[BP+06] SS:FFE4=B000
-t
AX=8544 BX=07F8 CX=000D DX=B000 SP=FFDA BP=FFDE SI=B000 DI=8544
DS=0C29 ES=0C29 SS=0C29 CS=0BD0 IP=0574 NV UP EI PL ZR NA PE NC
0BD0:0574 8B4E08 MOV CX,[BP+08] SS:FFE6=0194 |
|