【发布时间】:2012-08-04 22:04:20
【问题描述】:
我有以下在 x86 上工作的代码,我需要将其转换为 gcc/arm7 内联汇编。
似乎替换堆栈只是将堆栈指针移动到r15 而不是esp 的简单问题,但我不知道如何调用该函数,或将实际变量放入手臂汇编代码。
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。 它在哪里?
编辑:
编辑:
我正在尝试做的事情的完整实现在这里: http://pastebin.com/6mrUC7td
它在 Visual Studio 中完美运行,但我无法让它在 XCode/iOS 中正常运行
【问题讨论】: