我有 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)。我的代码有什么问题?
最佳答案
你不需要为你的栈帧保留空间,除非你正在做 calling convention。 ,快速调用只允许 4 个参数,尝试使用 RSP 直接使用堆栈,
summation proc
mov eax,ecx
add eax,edx
add eax,ebx
add eax,r8d
add eax,r9d
add eax,[rsp+50o]
add eax,[rsp+60o]
ret
summation endp
我使用的是八进制,如果你愿意,你可以使用十进制
关于c++ - 在 Assembly 中添加四个以上的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20501369/