I've got a function as follows:
int foo()
{
asm("swi 1");
}
The underlying handler for swi 1, plac开发者_高级运维es the return value correctly into r0, I want foo() to correctly return this value. ARM-ELF-GCC warns about control reaching the end of a non-void function for the above.
ARM-ELF-GCC still warns with the following:
int foo()
{
asm("swi 1");
return;
}
I've instead resorted to the following:
int foo()
{
int ret_val;
asm("swi 1");
asm("mov %[v], r0" : [v]"=r"(ret_val) :: "r0", "r3" )
return ret_val;
}
Is there a more elegant way of getting GCC to return the value in r0 without resorting to the above?
Thanks.
Try this (works on gcc):
int foo()
{
register int ret_val __asm__("r0");
__asm__ __volatile__ ("swi 1" : "=r"(ret_val));
return ret_val;
}
if you are going to use assembler...then...use assembler.
.globl foo
foo:
swi i
mov pc,lr
精彩评论