|
|
|
Re: Using ARM inline assembly, how can I ask gcc to put a variable into a designated register? | |
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
|
LiMing wrote:
> Dear all,
>
> Using ARM inline assembly, how can I ask gcc to put a variable into a designated register?
> For example: on X86 architechure,
>
> int foo(int x, int y)
> {
> int z = x + y;
>
> printf("foo: x = %d y= %d\n ", x, y);
> return z;
> }
>
> void call_foo(void)
> {
> int result;
> int arg1 =1, arg2=2;
>
> asm("foo" : "=r"(result) : "a"(arg1),"d"(arg2));
> printf("call_foo result = %d\n",result);
> }
>
> In function call_foo, gcc will put arg1 into eax and arg2 into edx.
> On ARM architechure, How can I ask arm gcc to put arg1 into r0 and arg2 into r1?
That would not work on x86. You would need to replace "foo" with "call
foo". And "result" must be set to a register.
On arm a working call_foo code would be:
void call_foo(void)
{
register int arg1 asm("r0");
register int arg2 asm("r1");
register int result asm("r0");
asm("bl foo" : "=r"(result) : "r"(arg1),"r"(arg2));
printf("call_foo result = %d\n",result);
}
--
Gilles.
_______________________________________________
linux-arm mailing list
linux-arm@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/linux-arm
[Linux ARM] [Linux ARM MSM] [Linux ARM Kernel] [Fedora ARM] [IETF Annouce] [Security] [Bugtraq] [Linux] [Linux OMAP] [Linux MIPS] [ECOS] [Asterisk Internet PBX] [Linux API]
![]() |
![]() |