Explanation of the disassembly of the simplest program (x86)-Collection of common programming errors
The instructions sets up the stack frame upon the runtime loader entering the int _main()
function,
PUSH EBP MOV EBP, ESP
Stack frame is set up and to access the parameters if any were supplied would be offset from EBP
+ the size of the parameter (WORD, BYTE, LONG, etc).
Usually the EAX
register is the normal register to return an exit status from the runtime environment to the operating system loader,
MOV EAX, 0 LEAVE
in other words, to say the program has exited successfully returning a 0 to the Operating system.
Where a return is used, the stack frame is restored upon runtime execution prior to handing control back to the Operating system.
POP EBP
The general consensus is, if an error has occurred, the value would be non-zero, and can be used both from batch files (harking back to the old DOS days) and unix scripts where it checks if the program ran successfully or not and proceed onwards depending on the nature of the batch file or script.