写了个简单的函数
int myfunction(int a,int b)
{
int c = a+b;
int i;
for(i=0;i<50;++i)
{
c+=i;
}
return c;
}
汇编码:
00412D10 > 55 push ebp
00412D11 8BEC mov ebp, esp
00412D13 81EC D8000000 sub esp, 0D8
00412D19 53 push ebx
00412D1A 56 push esi
00412D1B 57 push edi
00412D1C 8DBD 28FFFFFF lea edi, dword ptr [ebp-D8]
00412D22 B9 36000000 mov ecx, 36
00412D27 B8 CCCCCCCC mov eax, CCCCCCCC
00412D2C F3:AB rep stos dword ptr es:[edi]
00412D2E 8B45 08 mov eax, dword ptr [ebp+8]
00412D31 0345 0C add eax, dword ptr [ebp+C]
00412D34 8945 F8 mov dword ptr [ebp-8], eax
00412D37 C745 EC 0000000>mov dword ptr [ebp-14], 0
00412D3E EB 09 jmp short cdasm1.00412D49
00412D40 8B45 EC mov eax, dword ptr [ebp-14]
00412D43 83C0 01 add eax, 1
00412D46 8945 EC mov dword ptr [ebp-14], eax
00412D49 837D EC 32 cmp dword ptr [ebp-14], 32
00412D4D 7D 0B jge short cdasm1.00412D5A
00412D4F 8B45 F8 mov eax, dword ptr [ebp-8]
00412D52 0345 EC add eax, dword ptr [ebp-14]
00412D55 8945 F8 mov dword ptr [ebp-8], eax
00412D58 ^ EB E6 jmp short cdasm1.00412D40
00412D5A 8B45 F8 mov eax, dword ptr [ebp-8]
00412D5D 5F pop edi
00412D5E 5E pop esi
00412D5F 5B pop ebx
00412D60 8BE5 mov esp, ebp
00412D62 5D pop ebp
00412D63 C3 retn
我想知道临时变量c为什么不存储在ebp-4 而是ebp-8,变量i为啥不是ebp-8,或者ebp-C,而是ebp-14?为什么不挨着存储临时变量?
另外分配的临时变量空间为什么是D8而不是C0等其他值?这个分配的数据有啥依据?
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课