我使用Visual C++ 2010和MASM作爲我的x64彙編程序。
這是我的C++代碼:__cdecl,__stdcall和__fastcall都被稱爲完全相同的方式?
// include directive
#include "stdafx.h"
// functions
extern "C" int Asm();
extern "C" int (convention) sum(int x, int y) { return x + y; }
// main function
int main()
{
// print asm
printf("Asm returned %d.\n", Asm());
// get char, return
_getch();
return EXIT_SUCCESS;
}
我的彙編代碼:
; external functions
extern sum : proc
; code segment
.code
Asm proc
; create shadow space
sub rsp, 20o
; setup parameters
mov ecx, 10
mov edx, 15
; call
call sum
; clean-up shadow space
add rsp, 20o
; return
ret
Asm endp
end
的原因,我這樣做是這樣我就可以學習不同的調用約定。 我會讓sum的調用約定stdcall,並修改asm代碼,所以它會調用sum的「stdcall」方式。一旦我得到了這個工作,我會做出,比如fastcall,然後用「快速調用」的方式來調用它。
但現在看看我的彙編代碼。當我使用該代碼時,無論sum是stdcall,fastcall還是cdecl,它都會編譯,執行正常,並打印25作爲我的總和。
我的問題:爲什麼__cdecl,__stdcall和__fastcall都被稱爲完全相同的方式?
「在Windows上下文中編譯x64體系結構時(無論使用Microsoft還是非Microsoft工具),只有一個調用約定 - 此處描述的調用約定,以便stdcall,thiscall,cdecl,fastcall等等,現在都是一樣的。「 http://en.wikipedia.org/wiki/X86_calling_conventions – 2013-02-24 01:52:36
好吧...我只是要切換到x86,並嘗試使用不同的調用約定進行編譯,並查看結果是什麼,只是爲了檢查它是什麼這樣做。當可能的工作,我會接受你的答案:) – Aaron 2013-02-24 01:56:35
真棒,改變到x86工作。非常感謝! – Aaron 2013-02-24 02:03:06