fastcall调用约定详解(VC与Delphi)

fastcall调用约定

1.函数的前几个参数通过寄存器传递,其他参数通过堆栈.
2.被调用函数清理堆栈
3.函数名修改规则同stdcall


VC中的fastcall.

Add(1,2,3,4,5);
00417B83  push        5   
00417B85  push        4   
00417B87  push        3   
00417B89  mov         edx,2
00417B8E  mov         ecx,1
00417B93  call        Add (411749h)


int _fastcall Add(int n1,int n2,int n3,int n4,int n5)
{
00417B10  push        ebp 
00417B11  mov         ebp,esp
00417B13  sub         esp,0D8h
00417B19  push        ebx 
00417B1A  push        esi 
00417B1B  push        edi 
00417B1C  push        ecx 
00417B1D  lea         edi,[ebp-0D8h]
00417B23  mov         ecx,36h
00417B28  mov         eax,0CCCCCCCCh
00417B2D  rep stos    dword ptr es:[edi]
00417B2F  pop         ecx 
00417B30  mov         dword ptr [ebp-14h],edx
00417B33  mov         dword ptr [ebp-8],ecx
 return n1+n2+n3+n4+n5;
00417B36  mov         eax,dword ptr [n1]
00417B39  add         eax,dword ptr [n2]
00417B3C  add         eax,dword ptr [n3]
00417B3F  add         eax,dword ptr [n4]
00417B42  add         eax,dword ptr [n5]
}
00417B45  pop         edi 
00417B46  pop         esi 
00417B47  pop         ebx 
00417B48  mov         esp,ebp
00417B4A  pop         ebp 
00417B4B  ret         0Ch 

delphi中的fastcall.

Add(1,2,3,4,5);
00451F91   6A04                   push    $04
00451F93   6A05                   push    $05
00451F95   B903000000             mov     ecx, $00000003
00451F9A   BA02000000             mov     edx, $00000002
00451F9F   B801000000             mov     eax, $00000001

|
00451FA4   E8C7FFFFFF             call    00451F70

 

function Add(n1,n2,n3,n4,n5:Integer):Integer;
demoform.pas.35: begin
00451F70 55                   push ebp
00451F71 8BEC             mov ebp,esp
demoform.pas.36: Result:=n1+n2+n3+n4+n5;
00451F73 03D0             add edx,eax
00451F75 03CA             add ecx,edx
00451F77 034D0C        add ecx,[ebp+$0c]
00451F7A 034D08         add ecx,[ebp+$08]
00451F7D 8BC1             mov eax,ecx
demoform.pas.37: end;
00451F7F 5D                  pop ebp
00451F80 C20800        ret $0008

你可能感兴趣的:(fastcall调用约定详解(VC与Delphi))