您的位置:首页 > 编程语言 > C语言/C++

C++反汇编二(if...else语句)

2012-02-11 00:39 363 查看
17:   void Grammar_if_else()
18:   {
00401450   push        ebp
00401451   mov         ebp,esp
00401453   sub         esp,44h
00401456   push        ebx
00401457   push        esi
00401458   push        edi
00401459   lea         edi,[ebp-44h]
0040145C   mov         ecx,11h
00401461   mov         eax,0CCCCCCCCh
00401466   rep stos    dword ptr [edi]								// 初始化
19:       int x=5;
00401468   mov         dword ptr [ebp-4],5							// 局部变量ebp-4赋值
20:       if (x==5)
0040146F   cmp         dword ptr [ebp-4],5							// 局部变量与5比较
00401473   jne         Grammar_if_else+45h (00401495)				//  不相等则跳向00401495(即else开始处),相等则继续向下执行
21:       {
22:           cout<<"相等"<<endl;
00401475   push        offset @ILT+40(std::endl) (0040102d)			// 0040148E处的operator<<的参数2 std::endl入栈
0040147A   push        offset string "\xcf\xe0\xb5\xc8" (0043201c)	// 00401484处的operator<<的参数2 "相等"入栈		// 与下面2条语句组合为调用operator<<
0040147F   push        offset std::cout (00439528)					// 00401484处的operator<<的参数1 std::cout入栈
00401484   call        @ILT+165(std::operator<<) (004010aa)			// 调用operator<<
00401489   add         esp,8										// 平衡堆栈,由于是不定长参数,所以由调用者平衡堆栈
0040148C   mov         ecx,eax										// 返回值cout作为0040148E处的operator<<的参数1,寄存器ecx传递参数1
0040148E   call        @ILT+120(std::basic_ostream<char,std::char_traits<char> >::operator<<) (0040107d)
23:       }
24:       else
00401493   jmp         Grammar_if_else+63h (004014b3)				// 如果执行了if前半句,则跳过else直接到else结尾,保证2者只有一个执行.
25:       {
26:           cout<<"不相等"<<endl;
00401495   push        offset @ILT+40(std::endl) (0040102d)
0040149A   push        offset string "\xb2\xbb\xcf\xe0\xb5\xc8" (00432024)
0040149F   push        offset std::cout (00439528)
004014A4   call        @ILT+165(std::operator<<) (004010aa)
004014A9   add         esp,8
004014AC   mov         ecx,eax
004014AE   call        @ILT+120(std::basic_ostream<char,std::char_traits<char> >::operator<<) (0040107d)
27:       }
28:   }
004014B3   pop         edi
004014B4   pop         esi
004014B5   pop         ebx
004014B6   add         esp,44h
004014B9   cmp         ebp,esp
004014BB   call        __chkesp (00409100)
004014C0   mov         esp,ebp
004014C2   pop         ebp
004014C3   ret

由此可知,IF...ELSE语句与IF语句一样,也与高级语言的跳转指令正好相反.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  汇编 c++ basic string c 语言