This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Memory Allocation On Stack
On Sun, Jul 22, 2007 at 12:32:36AM +0530, Pankaj Kohli wrote:
> What about this one ? Three PUSHes + sub 0x10,%esp. That makes 28 bytes.
> Stack is not aligned on 16-byte boundary in this case.
There is no reason to 16-byte align the stack in this case.
> (gdb) list 8
> 3 int main(int argc, char **argv) {
> 4 int a, b, c;
> 5
> 6 a = 1;
> 7 b = 2;
> 8 c = a + b;
> 9
> 10 return 0;
> 11 }
Compare your example with this significantly modified one:
extern void g (void);
int main (int argc, char **argv) {
int a, b, c;
a = 1;
b = 2;
c = a + b;
g ();
return 0;
}
main:
leal 4(%esp), %ecx # 36 *lea_1 [length = 4]
andl $-16, %esp # 37 *andsi_1/1 [length = 3]
pushl -4(%ecx) # 38 *pushsi2 [length = 3]
pushl %ebp # 39 *pushsi2 [length = 1]
movl %esp, %ebp # 40 *movsi_1/1 [length = 2]
pushl %ecx # 41 *pushsi2 [length = 1]
subl $20, %esp # 42 pro_epilogue_adjust_stack_1/1 [length = 3]
movl $1, -16(%ebp) # 8 *movsi_1/2 [length = 7]
movl $2, -12(%ebp) # 10 *movsi_1/2 [length = 7]
movl -12(%ebp), %edx # 12 *movsi_1/1 [length = 3]
movl -16(%ebp), %eax # 13 *movsi_1/1 [length = 3]
addl %edx, %eax # 14 *addsi_1/1 [length = 2]
movl %eax, -8(%ebp) # 15 *movsi_1/2 [length = 3]
call g # 17 *call_0 [length = 5]
movl $0, %eax # 19 *movsi_1/1 [length = 5]
addl $20, %esp # 45 pro_epilogue_adjust_stack_1/1 [length = 3]
popl %ecx # 46 popsi1 [length = 1]
popl %ebp # 47 popsi1 [length = 1]
leal -4(%ecx), %esp # 48 *addsi_1/3 [length = 3]
ret # 49 return_internal [length = 1]
> (gdb) disassemble main
It is probably a lot easier to compile with -S -dp.
--
Rask Ingemann Lambertsen