Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>.file "test.c"</p> </blockquote> <p>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.</p> <blockquote> <p>.def ___main; .scl 2; .type 32; .endef</p> </blockquote> <p>.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</p> <p>___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).</p> <blockquote> <pre><code>.text </code></pre> </blockquote> <p>Begins a text section - code lives here.</p> <blockquote> <p>.globl _main</p> </blockquote> <p>defines the _main symbol as global, which will make it visible to the linker and to other modules that's linked in.</p> <blockquote> <pre><code>.def _main; .scl 2; .type 32; .endef </code></pre> </blockquote> <p>Same thing as _main , creates debugging symbols stating that _main is a function. This can be used by debuggers.</p> <blockquote> <p>_main:</p> </blockquote> <p>Starts a new label(It'll end up an address). the .globl directive above makes this address visible to other entities.</p> <blockquote> <pre><code>pushl %ebp </code></pre> </blockquote> <p>Saves the old frame pointer(ebp register) on the stack (so it can be put back in place when this function ends)</p> <blockquote> <pre><code>movl %esp, %ebp </code></pre> </blockquote> <p>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)</p> <blockquote> <p>andl $-16, %esp</p> </blockquote> <p>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.</p> <pre><code>call ___main </code></pre> <p>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</p> <blockquote> <pre><code>movl $0, %eax </code></pre> </blockquote> <p>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.</p> <blockquote> <p>leave</p> </blockquote> <p>The leave instruction is pretty much shorthand for </p> <blockquote> <pre><code>movl ebp,esp popl ebp </code></pre> </blockquote> <p>i.e. it "undos" the stuff done at the start of the function - restoring the frame pointer and stack to its former state.</p> <blockquote> <p>ret</p> </blockquote> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload