Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't have all answers but I can explain what I know.</p> <p><code>ebp</code> is used by the function to store the initial state of <code>esp</code> during its flow, a reference to where are the arguments passed to the function and where are its own local variables. The first thing a function does is to save the status of the given <code>ebp</code> doing <code>pushl %ebp</code>, it is vital to the function that make the call, and than replaces it by its own current stack position <code>esp</code> doing <code>movl %esp, %ebp</code>. Zeroing the last 4 bits of <code>ebp</code> at this point is GCC specific, I don't know why this compiler does that. It would work without doing it. Now finally we go into business, <code>call ___main</code>, who is __main? I don't know either... maybe more GCC specific procedures, and finally the only thing your main() does, set return value as 0 with <code>movl $0, %eax</code> and <code>leave</code> which is the same as doing <code>movl %ebp, %esp; popl %ebp</code> to restore <code>ebp</code> state, then <code>ret</code> to finish. <code>ret</code> pops <code>eip</code> and continue thread flow from that point, wherever it is (as its the main(), this ret probably leads to some kernel procedure which handles the end of the program).</p> <p>Most of it is all about managing the stack. I wrote a detailed tutorial about how stack is used some time ago, it would be useful to explain why all those things are made. But its in portuguese...</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