I have observed that when generating assembly code from simple C programs using GCC, the stack is initialized as follows:

pushl   %ebp
movl    %esp,  %ebp
andl    $-16,  %esp

my question concerns the last instruction where -16 is anded with the stack pointer. Am I correct in assuming that this is for proper memory alignment for 32 bit data? If so, then why not -4?

I have also observed that in a simple program I have written that compares data in memory, byte by byte, removing the said instruction significantly slows down the process. If this has to do with memory alignment, then I don't understand why it would have an affect since I am accessing bytes in memory individually anyway.

Thank you,


7 Years
Discussion Span
Last Post by Tight_Coder_Ex

Would have to see the C code but most likely the -16 is allocating 16 bytes on the stack for local variables, such as four 4-byte integers.

Edited by Ancient Dragon: n/a


did you notice that is "and", not "add"? It is zeroing out the four least significant bits in the stack pointer.

Edited by Allasso: n/a


It is different, and yes probably has something to do with alignment, but without seeing code in its entirety and more importantly the switches your passing to GCC it's hard to say why this is happening.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.