I wrote a simple C++ code and compiled it in VS 2013. I am trying to understand what happen after return 0.
int main(){
...
return 0;
...
}
The assembly code of return 0, translates to the xor eax, eax
011F1B19 xor eax,eax
}
011F1B1B pop ebp
011F1B1C ret
After ret, it jumps to 011F121A
011F1203 push dword ptr ds:[11F3034h]
011F1209 push dword ptr ds:[11F3030h]
011F120F push dword ptr ds:[11F302Ch]
011F1215 call main (011F1B00h)
011F121A add esp,0Ch
011F121D mov dword ptr ds:[011F3024h],eax
011F1222 cmp dword ptr ds:[11F3028h],0
011F1229 jne __tmainCRTStartup+144h (011F1261h)
#ifndef _CRT_APP
exit(mainret);
011F122B push eax
011F122C call dword ptr ds:[11F2078h]
I have two questions:
Why does the return translates to xor eax, eax?
Why does the function dereference ptr in ds segments at 011F121D and 011F1222 and 011F122C?
main
function (assuming you're not using any functions from the C runtime in your code).