title: What does it mean to align the stack?
body: <p>I have been a high-level coder, and architectures are pretty new to me, so I decided to read the tutorial on Assembly here: </p>
  
  <p><a href="http://en.wikibooks.org/wiki/X86_Assembly/Print_Version" rel="noreferrer">http://en.wikibooks.org/wiki/X86_Assembly/Print_Version</a></p>
  
  <p>Far down the tutorial, instructions on how to convert the Hello World! program </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void) {
      printf("Hello, world!\n");
      return 0;
  }
  </code></pre>
  
  <p>into equivalent assembly code was given and the following was generated:</p>
  
  <pre><code>        .text
  LC0:
          .ascii "Hello, world!\12\0"
  .globl _main
  _main:
          pushl   %ebp
          movl    %esp, %ebp
          subl    $8, %esp
          andl    $-16, %esp
          movl    $0, %eax
          movl    %eax, -4(%ebp)
          movl    -4(%ebp), %eax
          call    __alloca
          call    ___main
          movl    $LC0, (%esp)
          call    _printf
          movl    $0, %eax
          leave
          ret
  </code></pre>
  
  <p>For one of the lines,</p>
  
  <pre><code>andl    $-16, %esp
  </code></pre>
  
  <p>the explanation was:</p>
  
  <blockquote>
    <p>This code "and"s ESP with 0xFFFFFFF0,
    aligning the stack with the next
    lowest 16-byte boundary. An
    examination of Mingw's source code
    reveals that this may be for SIMD
    instructions appearing in the "_main"
    routine, which operate only on aligned
    addresses. Since our routine doesn't
    contain SIMD instructions, this line
    is unnecessary.</p>
  </blockquote>
  
  <p>I do not understand this point. Can someone give me an explanation of what it means to align the stack with the next 16-byte boundary and why it is required? And how is the <code>andl</code> achieving this?</p>