C++ assembly function call pushes base pointer twice -


using visual studio, have made simple class in c++ called watertank, has member function:

double watertank::getcapacity() const{     return capacity; } 

when run code:

watertank wt = watertank(100); double capacity = wt.getcapacity(); 

the double capacity = wt.getcapacity(); generates following assembly:

push        ebp   mov         ebp, esp   mov         ecx, 0f2e320h   call        watertank::getcapacity(0f21073h)   fstp        qword ptr ds:[0f2e330h]   cmp         ebp,esp   call        _rtc_checkesp (0f250b0h)   pop         ebp   ret 

and assembly generated double watertank::getcapacity() const body is:

push        ebp   mov         ebp,esp   push        ecx   mov         dword ptr [this],0cccccccch   mov         dword ptr [this],ecx   mov         eax,dword ptr [this]   fld         qword ptr [eax]   mov         esp,ebp   pop         ebp   ret 

now, see it, when calling wt.getcapacity() function, base pointer pushed onto stack , base pointer updated current stack pointer. function can executed, , base pointer can popped off stack return state before entering function.

what don't understand why function body pushes base pointer , pops it? assume has use of ecx register, don't know used for.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -