- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试从 C++ 调用我的 asm 函数并发送两个参数,根据维基百科关于 fastcall 调用约定,这两个参数应该保存在 ecx 和 edx 中。
但这不起作用。我错过了什么吗?
汇编 x86
.model flat
.code
_TestFunction proc
mov eax, ecx
add eax, edx
ret
_TestFunction endp
end
C++代码
#include <iostream>
extern "C" int TestFunction(int a, int b);
int main()
{
std::cout << "Function returns:" << TestFunction(200,100) << std::endl;
std::cin.get();
return 0;
}
函数返回 1,这是寄存器:
ECX = 00000000 EDX = 00000001
构建日志:
1>------ Rebuild All started: Project: Tutorial, Configuration: DebugWin32 ------ 1>
Assembling asm.asm... 1>Main.cpp 1>Tutorial.vcxproj -> C:\Users\nilo\documents\visual studio2012\Projects\Tutorial\Debug\Tutorial.exe========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
最佳答案
如果你真的想要__fastcall calling convention在 Win32 中,您的代码需要做一些小改动:
在程序集文件中,更改
_TestFunction proc
...
_TestFunction endp
到
@TestFunction@8 proc
...
@TestFunction@8 endp
在C++文件中,更改
extern "C" int TestFunction(int a, int b);
到
extern "C" int __fastcall TestFunction(int a, int b);
关于c++ - 组装发送参数-fastcall,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31011491/
我目前正在自己学习 x64 汇编,并且在从 C++ 调用汇编过程时无法理解堆栈会发生什么。 从我目前从 MSDN 了解到的和 Intel , 前 4 个整数/浮点参数存储在 rcx/xmm0、rd
我正在尝试从 C++ 调用我的 asm 函数并发送两个参数,根据维基百科关于 fastcall 调用约定,这两个参数应该保存在 ecx 和 edx 中。 但这不起作用。我错过了什么吗? 汇编 x86
例如,假设我有一个函数可以为您交换 32 位值中的字节: uint32_t byte_swap(uint32_t in); 好吧,将 32 位值压入堆栈并再次将其弹出似乎很愚蠢,特别是如果我们要经常调
您有使用调用约定 fastcall 的实际用例吗? 谢谢。 最佳答案 __fastcall 尝试在 CPU 寄存器而不是堆栈中传递函数参数(如果可能),这样速度更快。 这是一个 MSDN 文章的链接,
好的,所以我可以调用函数作为fastcall CC,方法是用__attribute__((fastcall))声明它。如何将函数本身定义为 fastcall? 例如,我有来电代码: // caller
考虑到: Microsoft Specific The __fastcall calling convention specifies that arguments to functions are
所以我有一个程序集需要在 Windows 上使用 fastcall 调用约定调用一个函数,但 gcc 不(afaict)支持它。 GCC 确实提供了 regparm 属性,但它期望前 3 个参数在 e
我有一个以极高频率调用的 CRC 计算函数。我已经声明为 inline 我尝试将其设为 __attribute((hot))__ 但我不确定这是否能买到任何东西。我正在考虑将其设为 fastcall。
我见过fastcall在许多函数之前附加符号。为什么使用它? 最佳答案 函数前的符号称为“调用约定”。它指定编译器如何(在低级别)将输入参数传递给函数并在执行后检索其结果。 有许多不同的调用约定,最流
这2个约定在x86编译模式下一起使用? 对于 64 位编译,没有 cdecl + fastcall 对吗?只是 AMD 64 ABI 调用约定?如果是这样,如何在 64 位模式下在 stdcall 和
我进退两难,对于 VM 的循环来说,什么是性能更好的选择: 选项 1 - 强制内联指令函数,使用计算的 goto 切换到该标签上指令的调用(有效的内联代码)...或... 选项 2 - 使用函数指针查
我是一名优秀的程序员,十分优秀!