gpt4 book ai didi

c++ - 如何从 gcc 内联 arm7 程序集调用 c++ 成员函数

转载 作者:太空宇宙 更新时间:2023-11-04 16:26:12 25 4
gpt4 key购买 nike

我有以下适用于 x86 的代码,我需要将其转换为 gcc/arm7 内联汇编。

似乎替换堆栈是将堆栈指针移动到 r15 而不是 esp 的简单问题,但我不知道如何调用函数,或将实际变量放入 arm 汇编代码中。

Object *c;

unsigned long _stack = (unsigned long)c->stack + 65535;
void (Object::*_run)() = &Object::_run;

__asm
{
mov ecx, _this // store pointer to this Object
mov edx, _run // store address of _run() function
mov esp, stack // replace stack pointer with Object's internal stack
call edx // call the _run() function
}


编辑:

到目前为止,我有这个:

unsigned long _stack = (unsigned long)c->stack + 65535;
void (Object::*_run)() = &Object::_run;

asm volatile("mov %[__this], %r0\n\t"
"mov %[__run], %r5\n\t"
"mov %[__stack], %%sp\n\t"
"blx %r5\n\t"
: /* no output operands */
: [__stack] "r" (_stack),
[__this] "r" (_this),
[__run] "r" (_run)
: /* no clobbers */);

问:在 x86 asm 中,使用 thiscall 调用约定,“this”指针进入 ecx。它去哪儿了?

编辑:

答:For C++, an implicit this parameter is passed as an extra argument that immediately precedes the first user argument. Other rules for marshalling C++ arguments are described in CPPABI.

编辑:

我正在尝试做的事情的完整实现在这里: http://pastebin.com/6mrUC7td

它在 visual studio 中完美运行,但我无法在 XCode/iOS 中正常运行

最佳答案

arm abi指定寄存器 r0r3 用于参数传递。 this 指针始终位于第一个寄存器中,即 r0

关于c++ - 如何从 gcc 内联 arm7 程序集调用 c++ 成员函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11812314/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com