assembly - Disecting x86 stack frame set up Visual C++ (Visual Studio 2010) -


On this very simple function, there are just some query questions that connect two numbers together. Here is the aortic distribution (with the question code are marked ???)

here is a function

  int add (int x, int y) {int additionAnswer = 0 ; AdditionAnswer = x + y; Return extra job; }   

There is disassembly (DEBUG BUILD) with my aesthetics and questions

  int add (int x, int y) {push ebp; Base Pointer Move Ebap, ASP; Move the base pointer to start the stack frame for this function sub ESP, 0CCh; ??? It preserves the place on the heap for the local; Variable .204bytes looks extremely !!! ebx / push ??? Why is it the preservation of EBX, SEI and EDI ESI? This function does not explicitly use it! Push ed lia ed, [ebp-0chh]; ??? Why is it loading the top address of the stack in the EDE? Mov ecx, 33h; ??? What is that ex, 0 ccccccc; ??? What are the reps that are dword ptr es: [edi]; ??? What is that mov dword ptr [additionAnswer], 0; Int Additional Answers = 0 mov eax, dword ptr [x]; eax = x add eax, dword ptr [y]; eax = eax + y mov dword ptr [additionAnswer] ex; Answer = EXMem EX, Dividend PTR [Extra Ender]; Except for returning to EX pop EDI; Despite the reinstatement of EDI, I did not use it !!!! Pop asi; Even after restoring SE, I did not use it !!!! Pop ebx; ebx restored though i did not use it !!!! Mov esp, ebp; Clean the stack frame and replace the 4 bytes of its original size with EBP; Revert the base point to the original value; And at the same time it will add 4 to restore it; Pointing back to my pre-frame value, and stack write   

, I dug a bit more in Win32, obviously it should be protected: edi, esi, ebp and ebx I can use the source / destination index registers (sei / edi) by calling function, but the calling function does not preserve EBX instead of my function Unnecessary ass work Of course, the caller knows what he needs to maintain and what is not it! After all, why do not you keep EBX safe and say ECX, then why is it the responsibility of my work to keep these registers (or even in any register!) Safe?

One last thing I do not see any of these registration codes when constructing in release mode (without optimization) ...... it is just a debug concept ????

To answer your question

Why calling function Do not protect yourself; Unnecessary donkeys are working for their work; Surely the caller knows what is needed to preserve it and what is not it!

Because, in calling conferences it is clear that a function can assume that the function that calls the function will not modify edi, esi, ebp, and ebx. Many times a collar cares for values ​​in other registers (EX, XX and ADX), but they know that they can be modified, so they should be saved by collars if it cares.

Sometimes the collar is easy to preserve things and sometimes it is easy to do for Cali. Calling conventions need to be understood by many different compilers (allowing those compilers to work together) for different languages, so a mixture of standard calling conference will save you collars and save Kaili. And any compiler can create , which type of register itself (indirect) option to use for different types of methods,

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -