|
1: int myTransform(int nInput){ 00401000 push ebp ; 保护现场原先的EBP指针 00401001 mov ebp,esp 2: return (nInput*2 + 3) % 7; 00401003 mov eax,dword ptr [nInput] ; 取参数 00401006 lea eax,[eax+eax+3] ; LEA比ADD加法更快 0040100A cdq ; DWORD->QWORD(扩展字长) 0040100B mov ecx,7 ; 除数 00401010 idiv eax,ecx ; 除 00401012 mov eax,edx ; 商->eax(eax中保存返回值) 3: } 00401014 pop ebp ; 恢复现场的ebp指针 00401015 ret ; 返回 ; 此处删除10条int 3指令,它们是方便调试用的,并不影响程序行为。 4: 5: int main(int argc, char* argv[]) 6: { 00401020 push ebp ; 保护现场原先的EBP指针 00401021 mov ebp,esp 00401023 sub esp,10h ; 为取argc, argv修正堆栈指针。 7: int a[3]; 8: for(register int i=0; i<3; i++){ 00401026 mov dword ptr ,0 ; 0->i 0040102D jmp main+18h (00401038) ; 判断循环条件 0040102F mov eax,dword ptr ; i->eax 00401032 add eax,1 ; eax ++ 00401035 mov dword ptr ,eax ; eax->i 00401038 cmp dword ptr ,3 ; 循环条件: i与3比较 0040103C jge main+33h (00401053) ; 如果不符合条件,则应结束循环 9: a = myTransform(i); 0040103E mov ecx,dword ptr ; i->ecx 00401041 push ecx ; ecx (i) -> 堆栈 00401042 call myTransform (00401000); 调用myTransform 00401047 add esp,4 ; esp+=4: 在堆中的新单元 ; 准备存放返回结果 0040104A mov edx,dword ptr ; i->edx 0040104D mov dword ptr a[edx*4],eax ; 将eax(myTransform返回值) ; 放回a 10: } 00401051 jmp main+0Fh (0040102f) ; 计算i++,并继续循环 11: return 0; 00401053 xor eax,eax ; 返回值应该是0 12: } 00401055 mov esp,ebp ; 恢复堆栈指针 00401057 pop ebp ; 恢复BP 00401058 ret ; 返回调用者(C++运行环境) |
00401003 mov eax,dword ptr [nInput]; 取参数 |
00401003 mov eax,dword ptr [ebp+8] ; 取参数 |
void myTransform1(int nCount, char* sBytes){ for(register int i=1; i<nCount; i++) sBytes += sBytes[i-1]; for(i=0; i<nCount; i++) sBytes <<= 1; } void myTransform2(int nCount, char* sBytes){ for(register int i=0; i<nCount; i++) sBytes <<= 1; } |
for(i=0; i<nCount; i++) sBytes <<= 1; |
1: void myTransform1(int nCount, char* sBytes){ 00401000 push ebp 00401001 mov ebp,esp 00401003 push ecx 2: for(register int i=1; i<nCount; i++) 00401004 mov dword ptr ,1 0040100B jmp myTransform1+16h (00401016) 0040100D mov eax,dword ptr 00401010 add eax,1 00401013 mov dword ptr ,eax 00401016 mov ecx,dword ptr 00401019 cmp ecx,dword ptr [nCount] 0040101C jge myTransform1+3Dh (0040103d) 3: sBytes += sBytes[i-1]; 0040101E mov edx,dword ptr [sBytes] 00401021 add edx,dword ptr 00401024 movsx eax,byte ptr [edx-1] 00401028 mov ecx,dword ptr [sBytes] 0040102B add ecx,dword ptr 0040102E movsx edx,byte ptr [ecx] 00401031 add edx,eax 00401033 mov eax,dword ptr [sBytes] 00401036 add eax,dword ptr 00401039 mov byte ptr [eax],dl 0040103B jmp myTransform1+0Dh (0040100d) 4: for(i=0; i<nCount; i++) 0040103D mov dword ptr ,0 00401044 jmp myTransform1+4Fh (0040104f) 00401046 mov ecx,dword ptr 00401049 add ecx,1 0040104C mov dword ptr ,ecx 0040104F mov edx,dword ptr 00401052 cmp edx,dword ptr [nCount] 00401055 jge myTransform1+6Bh (0040106b) 5: sBytes <<= 1; 00401057 mov eax,dword ptr [sBytes] 0040105A add eax,dword ptr 0040105D mov cl,byte ptr [eax] 0040105F shl cl,1 00401061 mov edx,dword ptr [sBytes] 00401064 add edx,dword ptr 00401067 mov byte ptr [edx],cl 00401069 jmp myTransform1+46h (00401046) 6: } 0040106B mov esp,ebp 0040106D pop ebp 0040106E ret 7: 8: void myTransform2(int nCount, char* sBytes){ 00401070 push ebp 00401071 mov ebp,esp 00401073 push ecx 9: for(register int i=0; i<nCount; i++) 00401074 mov dword ptr ,0 0040107B jmp myTransform2+16h (00401086) 0040107D mov eax,dword ptr 00401080 add eax,1 00401083 mov dword ptr ,eax 00401086 mov ecx,dword ptr 00401089 cmp ecx,dword ptr [nCount] 0040108C jge myTransform2+32h (004010a2) 10: sBytes <<= 1; 0040108E mov edx,dword ptr [sBytes] 00401091 add edx,dword ptr 00401094 mov al,byte ptr [edx] 00401096 shl al,1 00401098 mov ecx,dword ptr [sBytes] 0040109B add ecx,dword ptr 0040109E mov byte ptr [ecx],al 004010A0 jmp myTransform2+0Dh (0040107d) 11: } 004010A2 mov esp,ebp 004010A4 pop ebp 004010A5 ret 12: 13: int main(int argc, char* argv[]) 14: { 004010B0 push ebp 004010B1 mov ebp,esp 004010B3 sub esp,0CCh 15: char a[200]; 16: for(register int i=0; i<200; i++)a=i; 004010B9 mov dword ptr ,0 004010C3 jmp main+24h (004010d4) 004010C5 mov eax,dword ptr 004010CB add eax,1 004010CE mov dword ptr ,eax 004010D4 cmp dword ptr ,0C8h 004010DE jge main+45h (004010f5) 004010E0 mov ecx,dword ptr 004010E6 mov dl,byte ptr 004010EC mov byte ptr a[ecx],dl 004010F3 jmp main+15h (004010c5) 17: myTransform1(200, a); 004010F5 lea eax,[a] 004010FB push eax 004010FC push 0C8h 00401101 call myTransform1 (00401000) 00401106 add esp,8 18: myTransform2(200, a); 00401109 lea ecx,[a] 0040110F push ecx 00401110 push 0C8h 00401115 call myTransform2 (00401070) 0040111A add esp,8 19: return 0; 0040111D xor eax,eax 20: } 0040111F mov esp,ebp 00401121 pop ebp 00401122 ret |
|
|
void strcpy(char* lpszDest, char* lpszSrc){ while(*dest++=*src++); *dest=0; } |
char cTemp; // 全局变量 void SwapChar(char* lpcX, char* lpcY){ cTemp = *lpcX; *lpcX = *lpcY; lpcY = cTemp; // 引用了全局变量,在分享内存的多个线程中可能造成问题 } |
void SwapChar2(char* lpcX, char* lpcY){ static char cTemp; // 静态变量 cTemp = *lpcX; *lpcX = *lpcY; lpcY = cTemp; // 引用了静态变量,在分享内存的多个线程中可能造成问题 } |
mov ax, 4c00h int 21h |
欢迎光临 编程开发论坛 (http://bbs.lihuasoft.net/) | Powered by Discuz! 6.0.0 |