I have the following piece of code that works on x86, and I need to convert it to gcc/arm7 inline assembly.
It seems replacing the stack would be a simple matter of moving the stack pointer into r15 instead of esp, but I can't figure out how I would call the function, or get the actual variables into the arm assembly code.
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
}
edit:
so far, I have this:
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 */);
Q: in x86 asm, using thiscall calling convention, the "this" pointer goes in ecx. Where does it go in arm?
edit:
EDIT:
the full implementation of what I am trying to do is here: http://pastebin.com/6mrUC7td
it works perfectly in visual studio, but I can't get it to work right in XCode/iOS