【发布时间】:2013-12-10 17:35:03
【问题描述】:
我有如下所示的 C++ 文件和 .asm 文件。我正在尝试添加我在求和函数中传递的所有参数
summation(int a ,int b ,int c ,int d, int e,int f)
c++ 文件如下所示:
#include <iostream>
#include <conio.h>
#include<stdlib.h>
using namespace std;
extern "C" int summation(int a ,int b ,int c ,int d, int e,int f);
int main(){
cout << "Summation : "<<summation(1,2,7,1,8,10)<<endl;
return 0;
}
asm 文件看起来像这样:
.code
summation proc
sub rsp,30h
mov eax,ecx
add eax,edx
add eax,r8d
add eax,r9d
add eax,dword ptr [rsp+20h]
add eax,dword ptr [rsp+28h]
add rsp,30h
ret
summation endp
end
有了这些代码,结果总是 22(应该是 29)。我的代码有什么问题?
【问题讨论】:
-
你正在使用 fastcall,它不会处理超过 4 个。其余的为你压入堆栈。
-
那么我该如何处理它们(那些被压入堆栈的)? @ScarletAmaranth
-
为什么不让 64 位 C 编译器告诉你答案?