944,147 Members | Top Members by Rank

Ad:
Nov 6th, 2009
0

C++ internals

Expand Post »
I'm trying to advance my understanding of how computers and compilers work.

Given the C++ program bellow with exceptions and runtime typing turned off and no optimizing that removes main or makes it into a non-standard function.
  1. int main() {return0;}

Produced an disassembly with the following code for main:
asm Syntax (Toggle Plain Text)
  1. pushl %ebp ; pushes the stack frame
  2. xorl %eax, %eax ; sets the eax register to zero
  3. movl %esp, %ebp ; empties the stack frame
  4. leave
  5. ret ; return with 0 in eax

1. What will the assembly that calls the main function look like?
2. What will be on the start before this code is run?
3. What will EBP (the stack frame pointer) be at the start? Garbage values?
4. What is in the accumulator at the start? Garbage values again?
5. What does the leave function do? I've read around for this but I can't find anything that makes much sense.
6. To what address will ret jump the instruction pointer to?
7. What does the assembly look like for the code that is executed the main function exits?
8. Another thing that is being getting at me is: why does C++ CDECL calling convention pass argument right to left? It seems counter intuitive to me as it rewards doing right to left as the order of evaluation of the parameters which is also counter intuitive to me.

Thanks in advance, any help would be much appreciated
Similar Threads
Reputation Points: 17
Solved Threads: 0
Light Poster
ganbree is offline Offline
28 posts
since Apr 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Computer Science Forum Timeline: SuggEsTionS plZ..!!
Next Thread in Computer Science Forum Timeline: Final Year Project help!!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC