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

  • Home
  • SEARCH
  • 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 6639571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:34:08+00:00 2026-05-25T23:34:08+00:00

(gdb) disas /m main Dump of assembler code for function main(): 2 { 0x080483f4

  • 0
(gdb) disas /m main
Dump of assembler code for function main():
2   {
   0x080483f4 <+0>: push   %ebp
   0x080483f5 <+1>: mov    %esp,%ebp
   0x080483f7 <+3>: sub    $0x10,%esp

3       int a = 1;
   0x080483fa <+6>: movl   $0x1,-0x4(%ebp)

4           int b = 10;
   0x08048401 <+13>:    movl   $0xa,-0x8(%ebp)

5           int c;
6           c = a + b;
   0x08048408 <+20>:    mov    -0x8(%ebp),%eax
   0x0804840b <+23>:    mov    -0x4(%ebp),%edx
   0x0804840e <+26>:    lea    (%edx,%eax,1),%eax
   0x08048411 <+29>:    mov    %eax,-0xc(%ebp)

7           return 0;
   0x08048414 <+32>:    mov    $0x0,%eax

8   }
   0x08048419 <+37>:    leave  

Notce the 3rd assembler instruction, it allocated 16 bytes instead of the expected 12 bytes. Why is that? I thought the 3rd line is allocating automatic variables…

Even if I removed the assignment, the allocation is still 16 bytes.

Thanks.


Edit

// no header. nothing
int main()
{
        int a = 1;
        int b = 10;
        int c;
        c = a + b;
        return 0;
}

g++ -g -o demo demo.cpp


Follow up…
I read a couple more threads on stack alignment (sorry, I am now studying computer arch and organization class…so I am not familiar with this at all)

Stack Allocation Padding and Alignment

I am supposed it’s the compiler’s setting. So default, the minimum is 16-byte.

If we have

int a = 1;
int b = 10;
int c = 10;
int d = 10;
// --
int e = 10;

Up to int d, we would have exactly 16-bytes, and the allocation is still 0x10. But when we give another delectation, int e = 10, esp is now allocated 32 bytes (0x20).

This shows me that esp, the stack pointer, is only used for automatic variables.


Follow-up 2

Call stack and Stack frame

Each stack frame

Storage space for all the automatic variables for the newly called function.

The line number of the calling function to return to when the called function returns.

The arguments, or parameters, of the called function.

But after we allocated int a through int d, it already took us 16 bytes. Main has no function parameters, so that’s zero. But the line to return, where did this information go?

  • 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-25T23:34:09+00:00Added an answer on May 25, 2026 at 11:34 pm

    I although I haven’t seen the source code for main() yet, I believe this is due to stack alignment.

    Under your settings, the stack probably needs to be aligned to 8 bytes. Therefore esp is being incremented by 16 bytes rather than 12 bytes. (even though 12 bytes is enough to hold all the variables)

    On other systems (with SSE or AVX), the stack will need to be aligned to 16 or 32 bytes.

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

Sidebar

Related Questions

(gdb) disas foo Dump of assembler code for function foo: 0x00000000004004a8 <foo+0>: push %rbp
(gdb) disas htons Dump of assembler code for function ntohs: 0x00000037aa4e9470 <ntohs+0>: ror $0x8,%di
Dump of assembler code for function foo@plt: 0x0000000000400528 <foo@plt+0>: jmpq *0x2004d2(%rip) # 0x600a00 <_GLOBAL_OFFSET_TABLE_+40>
Debugging with gdb, any c++ code that uses STL/boost is still a nightmare. Anyone
I'm working with a binary file that I disas'd in gdb. Right now I'm
I am using gdb to examine a program. In assembly, the code is doing:
What gdb frontends can I use with vim for debugging C and C++ code?
What do gdb users here think about its capabilities in regards to debugging code
I'm using gdb to debug some c++ code. At the moment the code I'm
0x00000000004004b6 <main+30>: callq 0x400398 <printf@plt> Anyone knows? UPDATE Why two disas printf give me

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.