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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:27:28+00:00 2026-05-26T03:27:28+00:00

C++ int main(void) { int a = 3; int b = 10; int c;

  • 0

C++

int main(void)
{
    int a = 3;
    int b = 10;
    int c;
    c = a + b;
    return 0;
}
008C1353  sub         esp,0E4h 
......
008C135C  lea         edi,[ebp+FFFFFF1Ch]  
008C1362  mov         ecx,39h  
008C1367  mov         eax,0CCCCCCCCh  
008C136C  rep stos    dword ptr es:[edi]  
     3:     int a = 3;
008C136E  mov         dword ptr [ebp-8],3  
     4:     int b = 10;
008C1375  mov         dword ptr [ebp-14h],0Ah  
     5:     int c;
     6:     c = a + b;

A couple things that I don’t understand.

(1) G++ will have stack alignment 16 bytes, and doing this in Visual Studio is 228 bytes??

(2) Doing this on Windows, does the stack grows upward or downward? I am confused. I know how the stack should look like

[Parameter n          ]
...
[Parameter 2          ]
[Parameter 1          ]
[Return Address       ]   0x002CF744
[Previous EBP         ]   0x002CF740  (current ebp)
[Local Variables      ]   

So would the lowest address be the downward?

(3) When we push the variable a to the stack, it is ebp – 8.How come it’s eight bytes?
(4) Similarly, why is int b ebp – 14 ?

Can someone please explain this to me? (-4, -8, respectively)

Using GDB, the offset makes more sense to me.

Thanks.

  • 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-26T03:27:29+00:00Added an answer on May 26, 2026 at 3:27 am

    When compiling in debug mode, the Microsoft compiler adds quite a lot of padding and other safety-checking code to your generated code. Filling the stack with 0xCC bytes is one of those checks. That may be confusing your interpretation compared to the generated gcc code.

    In release mode, these safety checks are generally turned off, but optimisation is turned on. Optimisation may make your assembly code even harder to follow.

    For best results, you might try creating a new configuration starting with release mode, and specifically turning optimisations off.

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

Sidebar

Related Questions

#include <iostream> namespace { int a=1; } int a=2,b=3; int main(void) { std::cout<<::a<<::b; return
Consider this code: int main() { int e; prn(e); return 0; } void prn(double
#include<stdio.h> void function(int); int main() { int x; printf(Enter x:); scanf(%d, &x); function(x); return
int main(void) { char four[4] = four; return 0; } When compiled as a
#include <stdio.h> int main(void){ char x [] = hello world.; printf(%s \n, &x[0]); return
see this code #include<stdio.h> int main() { void test(void) { printf(test); return; } printf(main);
So...I have the following code: int main(void) { const char *s=hello, world; cout<<&s[7]<<endl; return
The below fails to compile: typedef int arr[10]; int main(void) { return sizeof arr;
test.c int main () { void a; return 0; } I use gcc to
int foo(int c){ return c; } int main(void){ int a=5,c; c = foo(--a) +

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.