two mains

David Nadlinger see at klickverbot.at
Sun Jan 27 06:09:18 PST 2013


On Saturday, 26 January 2013 at 20:57:54 UTC, Tyro[17] wrote:
> On 1/26/13 3:42 PM, Tyro[17] wrote:
>> The second is the use of leave in [2]. If I understand 
>> correctly, leave
>> is the exact same as:
>>
>>         mov    RBP,RSP
>>         pop    RBP
>>
>> So why do we need to mov RBP, RSP in [2] but not in [1]? I'm 
>> thinking
>> this is because RBP contains the address of args but not sure.
>
> Still not clear on this choice.

Both functions could be replaced with

---
_Dmain:
   xor EAX, EAX
   ret
---

as they don't need to store anything on the stack at all.

What you are seeing is just an odd result of the way the compiler 
generates the code internally, especially if you are compiling 
without optimizations on.

For further information on what EBP/RBP is needed for, try 
searching for discussions about the (mis)use of GCC's 
omit-frame-pointer option, such as: 
http://stackoverflow.com/questions/579262/what-is-the-purpose-of-the-frame-pointer

David


More information about the Digitalmars-d-learn mailing list