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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:59:37+00:00 2026-05-12T09:59:37+00:00

I write empty programs to annoy the hell out of stackoverflow coders, NOT. I

  • 0

I write empty programs to annoy the hell out of stackoverflow coders, NOT. I am just exploring the gnu toolchain.

Now the following might be too deep for me, but to continuie the empty program saga I have started to examine the output of the C compiler, the stuff GNU as consumes.

gcc version 4.4.0 (TDM-1 mingw32)

test.c:

int main()
{
    return 0;
}

gcc -S test.c

    .file   "test.c"
    .def    ___main;    .scl    2;  .type   32; .endef
    .text
.globl _main
    .def    _main;  .scl    2;  .type   32; .endef
_main:
    pushl   %ebp
    movl    %esp, %ebp
    andl    $-16, %esp
    call    ___main
    movl    $0, %eax
    leave
    ret 

Can you explain what happens here? Here is my effort to understand it. I have used the as manual and my minimal x86 ASM knowledge:

  • .file "test.c" is the directive for the logical filename.
  • .def: according to the docs “Begin defining debugging information for a symbol name”. What is a symbol (a function name/variable?) and what kind of debugging information?
  • .scl: docs say “Storage class may flag whether a symbol is static or external”. Is this the same static and external I know from C? And what is that ‘2’?
  • .type: stores the parameter “as the type attribute of a symbol table entry”, I have no clue.
  • .endef: no problem.
  • .text: Now this is problematic, it seems to be something called section and I have read that its the place for code, but the docs didn’t tell me too much.
  • .globl “makes the symbol visible to ld.”, the manual is quite clear on this.
  • _main: This might be the starting address (?) for my main function
  • pushl_: A long (32bit) push, which places EBP on the stack
  • movl: 32-bit move. Pseudo-C: EBP = ESP;
  • andl: Logical AND. Pseudo-C: ESP = -16 & ESP, I don’t really see whats the point of this.
  • call: Pushes the IP to the stack (so the called procedure can find its way back) and continues where __main is. (what is __main?)
  • movl: this zero must be the constant I return at the end of my code. The MOV places this zero into EAX.
  • leave: restores stack after an ENTER instruction (?). Why?
  • ret: goes back to the instruction address that is saved on the stack

Thank you for your help!

  • 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-12T09:59:37+00:00Added an answer on May 12, 2026 at 9:59 am

    .file “test.c”

    Commands starting with . are directives to the assembler. This just says this is “file.c”, that information can be exported to the debugging information of the exe.

    .def ___main; .scl 2;
    .type 32; .endef

    .def directives defines a debugging symbol. scl 2 means storage class 2(external storage class) .type 32 says this sumbol is a function. These numbers will be defined by the pe-coff exe-format

    ___main is a function called that takes care of bootstrapping that gcc needs(it’ll do things like run c++ static initializers and other housekeeping needed).

    .text
    

    Begins a text section – code lives here.

    .globl _main

    defines the _main symbol as global, which will make it visible to the linker and to other modules that’s linked in.

    .def        _main;  .scl    2;      .type   32;     .endef
    

    Same thing as _main , creates debugging symbols stating that _main is a function. This can be used by debuggers.

    _main:

    Starts a new label(It’ll end up an address). the .globl directive above makes this address visible to other entities.

    pushl       %ebp
    

    Saves the old frame pointer(ebp register) on the stack (so it can be put back in place when this function ends)

    movl        %esp, %ebp
    

    Moves the stack pointer to the ebp register. ebp is often called the frame pointer, it points at the top of the stack values within the current “frame”(function usually), (referring to variables on the stack via ebp can help debuggers)

    andl $-16, %esp

    Ands the stack with fffffff0 which effectivly aligns it on a 16 byte boundary. Access to aligned values on the stack are much faster than if they were unaligned. All these preceding instructions are pretty much a standard function prologue.

    call        ___main
    

    Calls the ___main function which will do initializing stuff that gcc needs. Call will push the current instruction pointer on the stack and jump to the address of ___main

    movl        $0, %eax
    

    move 0 to the eax register,(the 0 in return 0;) the eax register is used to hold function return values for the stdcall calling convention.

    leave

    The leave instruction is pretty much shorthand for

    movl     ebp,esp
    popl     ebp
    

    i.e. it “undos” the stuff done at the start of the function – restoring the frame pointer and stack to its former state.

    ret

    Returns to whoever called this function. It’ll pop the instruction pointer from the stack (which a corresponding call instruction will have placed there) and jump there.

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

Sidebar

Ask A Question

Stats

  • Questions 181k
  • Answers 181k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I guess you have to apply some additional CSS so… May 12, 2026 at 4:14 pm
  • Editorial Team
    Editorial Team added an answer Here is an example, not necessarily working code: - (void)sendProviderDeviceToken:(NSString… May 12, 2026 at 4:14 pm
  • Editorial Team
    Editorial Team added an answer var myEl = $("#dad").children(":input"); May 12, 2026 at 4:14 pm

Related Questions

I've got the following two programs, one acting as a reader and the other
Supposing I have a File f that represents a directory, then f.delete() will only
I have a utility (grep) that gives me a list of filenames and a
I'm writing this small program to extract any number of email address from a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.