This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Memory Allocation On Stack


Pankaj Kohli writes:
 > Yeah, that was me who asked it on kerneltrap :)
 > If it is trying to align ESP on a 16-byte boundary, that seems fine
 > for a single integer variable or anything less than 16 bytes, but why
 > is it allocating 116 bytes for 100 byte buffer ? That doesn't fit on a
 > 16-byte boundary.

Where's the mystery?

 > Dump of assembler code for function main:
 > 0x080483a4 : lea 0x4(%esp),%ecx
 > 0x080483a8 : and $0xfffffff0,%esp

sp = sp & -16 // sp is 16-aligned

 > 0x080483ab : pushl 0xfffffffc(%ecx)

sp -= 4  // sp is 4-aligned

 > 0x080483ae : push %ebp

sp -= 4  // sp is 8-aligned

 > 0x080483af : mov %esp,%ebp
 > 0x080483b1 : push %ecx

sp -= 4  // sp is 4-aligned

 > 0x080483b2 : sub $0x74,%esp

sp -= 116 // sp is 16-aligned

Andrew.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]