- UID
- 66114
注册时间2010-4-1
阅读权限30
最后登录1970-1-1
龙战于野
TA的每日心情 | 慵懒 2019-3-12 17:25 |
---|
签到天数: 3 天 [LV.2]偶尔看看I
|
楼主 |
发表于 2010-5-17 21:05:24
|
显示全部楼层
汇编代码
在VC中,按F10进入DEBUG模式。右键弹出菜单,选择“Go To Disassembly”,则显示C源程序的相应汇编代码。注意:这里的汇编代码是DEBUG模式的,与RELEASE模式的汇编代码会有所不同,但我们将要研究的问题。下面的代码完全摘自VC中,未作任何修改。由此可见,子函数存储区(低址)和主函数存储区(高址)之间还有一些空白区。函数中调用的其他库函数存储在更高的地址,具体情况在实践在查看。
……(前面省略)
1: #include <stdio.h>
2: #include <string.h>
3:
4: void func1(int input1, int input2)
5: {
00401020 push ebp
00401021 mov ebp,esp
00401023 sub esp,4Ch
00401026 push ebx
00401027 push esi
00401028 push edi
00401029 lea edi,[ebp-4Ch]
0040102C mov ecx,13h
00401031 mov eax,0CCCCCCCCh
00401036 rep stos dword ptr [edi]
6: int j;
7: char c;
8: short k;
9:
10: j = 0;
00401038 mov dword ptr [ebp-4],0
11: c = 'a';
0040103F mov byte ptr [ebp-8],61h
12: k = 1;
00401043 mov word ptr [ebp-0Ch],offset func1+27h (00401047)
13:
14: printf("sum=%d\n", input1+input2);
00401049 mov eax,dword ptr [ebp+8]
0040104C add eax,dword ptr [ebp+0Ch]
0040104F push eax
00401050 push offset string "sum=%d\n" (0042001c)
00401055 call printf (00401130)
0040105A add esp,8
15:
16: return;
17: }
0040105D pop edi
0040105E pop esi
0040105F pop ebx
00401060 add esp,4Ch
00401063 cmp ebp,esp
00401065 call __chkesp (004011b0)
0040106A mov esp,ebp
0040106C pop ebp
0040106D ret
18:
19: int main()
20: {
00401080 push ebp
00401081 mov ebp,esp
00401083 sub esp,50h
00401086 push ebx
00401087 push esi
00401088 push edi
00401089 lea edi,[ebp-50h]
0040108C mov ecx,14h
00401091 mov eax,0CCCCCCCCh
00401096 rep stos dword ptr [edi]
21: char output[8] = "abcdef";
00401098 mov eax,[string "abcdef" (00420f84)]
0040109D mov dword ptr [ebp-8],eax
004010A0 mov cx,word ptr [string "abcdef"+4 (00420f88)]
004010A7 mov word ptr [ebp-4],cx
004010AB mov dl,byte ptr [string "abcdef"+6 (00420f8a)]
004010B1 mov byte ptr [ebp-2],dl
004010B4 xor eax,eax
004010B6 mov byte ptr [ebp-1],al
22: int i, j;
23:
24: i=2;
004010B9 mov dword ptr [ebp-0Ch],2
25: j=3;
004010C0 mov dword ptr [ebp-10h],3
26: func1(i,j);
004010C7 mov ecx,dword ptr [ebp-10h]
004010CA push ecx
004010CB mov edx,dword ptr [ebp-0Ch]
004010CE push edx
004010CF call @ILT+0(_func1) (00401005)
004010D4 add esp,8
27:
28: printf("%s\r\n", output);
004010D7 lea eax,[ebp-8]
004010DA push eax
004010DB push offset string "%s\r\n" (00420024)
004010E0 call printf (00401130)
004010E5 add esp,8
29:
30: return 0;
004010E8 xor eax,eax
31: }
004010EA pop edi
004010EB pop esi
004010EC pop ebx
004010ED add esp,50h
004010F0 cmp ebp,esp
004010F2 call __chkesp (004011b0)
004010F7 mov esp,ebp
004010F9 pop ebp
004010FA ret
……(后面省略)
[ 本帖最后由 whypro 于 2010-5-17 21:15 编辑 ] |
评分
-
查看全部评分
|