lea edi, DWORD PTR dest ;注意指针src和数组dest取地址的区别 mov ecx, DWORD PTR src test ecx, 3 je short main_loop_entrance src_misaligned: mov dl,byte ptr [ecx] inc ecx test dl,dl je short byte_0 mov [edi],dl inc edi test ecx,3 jne short src_misaligned jmp short main_loop_entrance
je short main_loop ; found zero byte in the loop ; main_loop_end: test dl,dl je short byte_0 test dh,dh je short byte_1 test edx,00ff0000h je short byte_2 test edx,0ff000000h je short byte_3 jmp short main_loop byte_3: mov [edi],edx jmp copy_end byte_2: mov [edi],dx mov byte ptr [edi+2],0 jmp copy_end byte_1: mov [edi],dx jmp copy_end byte_0: mov [edi],dl
copy_end: pop ecx pop edi } printf("%s\n", dest); return 0; }
#include <stdio.h>6int main(int argc, char* argv[])
{
char *src = argv[0];
char dest[1024] = {0}; __asm
{
push edi
push ecx
lea edi, DWORD PTR dest ;注意指针src和数组dest取地址的区别
mov ecx, DWORD PTR src
test ecx, 3
je short main_loop_entrance src_misaligned:
mov dl,byte ptr [ecx]
inc ecx
test dl,dl
je short byte_0
mov [edi],dl
inc edi
test ecx,3
jne short src_misaligned
jmp short main_loop_entrance
main_loop:
mov [edi],edx
add edi,4
main_loop_entrance:
mov edx,7efefeffh
mov eax,dword ptr [ecx]
add edx,eax
xor eax,-1
xor eax,edx
mov edx,[ecx]
add ecx,4
test eax,81010100h
je short main_loop
; found zero byte in the loop
; main_loop_end:
test dl,dl
je short byte_0
test dh,dh
je short byte_1
test edx,00ff0000h
je short byte_2
test edx,0ff000000h
je short byte_3
jmp short main_loop
byte_3:
mov [edi],edx
jmp copy_end byte_2:
mov [edi],dx
mov byte ptr [edi+2],0
jmp copy_end byte_1:
mov [edi],dx
jmp copy_end byte_0:
mov [edi],dl
copy_end:
pop ecx
pop edi
} printf("%s\n", dest);
return 0;
}