Hi,

I was looking into the assembly code of a add function that I have written.
The function takes two integers as input and outputs an integer, which is
the sum of the two inputs. I am declaring 3 local varibles in the function,
2 to hold input and one for the output . The disassembly code shown for the
same in visual studio 6 is as follows.
-----------------------------------------------------------------------------
25: int add(int a, int b){
00401610   push        ebp
00401611   mov         ebp,esp
00401613   sub         esp,44h   *// allocating / reserving 68 bytes ?
*00401616   push        ebx
00401617   push        esi
00401618   push        edi
00401619   lea         edi,[ebp-44h]
0040161C   mov         ecx,11h
00401621   mov         eax,0CCCCCCCCh
00401626   rep stos    dword ptr [edi]
26:
27:   int c;
28:
29:   c= a+b;
00401628   mov         eax,dword ptr [ebp+8]
0040162B   add         eax,dword ptr [ebp+0Ch]
0040162E   mov         dword ptr [ebp-4],eax
30:   return c;
00401631   mov         eax,dword ptr [ebp-4]
31:
32:
33:   }
00401634   pop         edi
00401635   pop         esi
00401636   pop         ebx
00401637   mov         esp,ebp
00401639   pop         ebp
0040163A   ret
-----------------------------------------------------------------------------
 1) My question is why did the compiler allocated 68 bytes while I have only
3 integer variables in my function = 3*4 = 12 bytes?
2) Though it allocates the 68 bytes instead of 12, it never refers to any
thing other than those 12 bytes?

Thanks in advance,
Sai.


[Non-text portions of this message have been removed]

Reply via email to