Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3359756
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:54:41+00:00 2026-05-18T02:54:41+00:00

I have been a high-level coder, and architectures are pretty new to me, so

  • 0

I have been a high-level coder, and architectures are pretty new to me, so I decided to read the tutorial on Assembly here:

http://en.wikibooks.org/wiki/X86_Assembly/Print_Version

Far down the tutorial, instructions on how to convert the Hello World! program

#include <stdio.h>

int main(void) {
    printf("Hello, world!\n");
    return 0;
}

into equivalent assembly code was given and the following was generated:

        .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

For one of the lines,

andl    $-16, %esp

the explanation was:

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.

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 andl achieving this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:54:42+00:00Added an answer on May 18, 2026 at 2:54 am

    Assume the stack looks like this on entry to _main (the address of the stack pointer is just an example):

    |    existing     |
    |  stack content  |
    +-----------------+  <--- 0xbfff1230
    

    Push %ebp, and subtract 8 from %esp to reserve some space for local variables:

    |    existing     |
    |  stack content  |
    +-----------------+  <--- 0xbfff1230
    |      %ebp       |
    +-----------------+  <--- 0xbfff122c
    :    reserved     :
    :     space       :
    +-----------------+  <--- 0xbfff1224
    

    Now, the andl instruction zeroes the low 4 bits of %esp, which may decrease it; in this particular example, it has the effect of reserving an additional 4 bytes:

    |    existing     |
    |  stack content  |
    +-----------------+  <--- 0xbfff1230
    |      %ebp       |
    +-----------------+  <--- 0xbfff122c
    :    reserved     :
    :     space       :
    + - - - - - - - - +  <--- 0xbfff1224
    :   extra space   :
    +-----------------+  <--- 0xbfff1220
    

    The point of this is that there are some “SIMD” (Single Instruction, Multiple Data) instructions (also known in x86-land as “SSE” for “Streaming SIMD Extensions”) which can perform parallel operations on multiple words in memory, but require those multiple words to be a block starting at an address which is a multiple of 16 bytes.

    In general, the compiler can’t assume that particular offsets from %esp will result in a suitable address (because the state of %esp on entry to the function depends on the calling code). But, by deliberately aligning the stack pointer in this way, the compiler knows that adding any multiple of 16 bytes to the stack pointer will result in a 16-byte aligned address, which is safe for use with these SIMD instructions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have been playing around with MDX and need some very high-level getting-started
I have been searching high and low for a way to get my silverlight
Okay, so far, I have been taking computer science courses in my high school
I have a web application, which has been suffering high load recent days. The
There are four high level APIs to access Cassandra and I do not have
I have a simple, low-level container class that is used by a more high-level
Have been looking at the MVC storefront and see that IQueryable is returned from
Have been studying the file system related classes of Adobe AIR 1.5, but so
We have been using CruiseControl for quite a while with NUnit and NAnt. For
I have been experimenting with woopra.com A web analytics tool. Which requires a piece

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.