C++ internals

Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
Reply

Join Date: Apr 2007
Posts: 28
Reputation: ganbree is an unknown quantity at this point 
Solved Threads: 0
ganbree ganbree is offline Offline
Light Poster

C++ internals

 
0
  #1
33 Days Ago
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:
  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
Thanks in advance; in advance taken (thankfully).
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the Computer Science Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC