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 8028399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:07:36+00:00 2026-06-05T00:07:36+00:00

I have seen an assembly code which subtracts from the stack pointer before calling

  • 0

I have seen an assembly code which subtracts from the stack pointer before calling a function without any particular reason. The space subtracted is left empty and not used:

sub    esp, 8    ; stack align
push   dword y
push   dword [x]
call   foo
add    esp, 16
mov    [x], eax

The writer of the code added the comment ‘stack align’, but I don’t know what is meant by ‘stack align’ nor how does the command sub esp, 8 help achieving it.

Any ideas?

  • 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-06-05T00:07:38+00:00Added an answer on June 5, 2026 at 12:07 am

    If your stack pointer is aligned to a cache line when a function is entered, execution of the functions is likely to place less stress on the cache.

    So, a compiler system can be organized to insist that functions are entered with the SP aligned on a cache line, and the compiler, knowing how much stack has been used at each call site, how much it takes to re-align the SP before it makes the call.

    That would explain your example. I haven’t seen many compilers actually do this, since the stack itself tends to grow/shrink by modest distances and overall doesn’t put much demand on the cache by virtue of reusing that local storage again and again.

    Another use is allocating space for the callee to work in, or to return a result bigger than what fits in a register. A compiler wouldn’t write a comment like that, so some person likely did this. Maybe he knew what he was doing; maybe he didn’t. If the called function doesn’t need this space, then its just a wasted instruction.

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

Sidebar

Related Questions

I have seen a assembly program written from a book about assemble: assume cs:code
I have seen code for summation of an array using threads. In this code
Disclaimer : I have seen the exact questions, but have not seen any answers
I've observed a lot of stack-introspective code in applications, which often implicitly rely on
I'm writing a compiler project which will produce assembly code as the target language.
I am writing an assembly function to be called from C that will call
Have seen some similar questions: What is the difference between a JavaBean and a
I have seen that in some cases we use following syntax format in c#,
I have seen that there are two different ways to access methods within a
I have seen that there are so wonderful ways in Xcode to design your

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.