This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Fwd: QUERY : ARM inline code in Thumb file?
- From: "Alexandre Pereira Nunes" <alexandre dot nunes at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Mon, 1 Sep 2008 12:07:24 -0300
- Subject: Fwd: QUERY : ARM inline code in Thumb file?
- References: <48B58864.2060304@netscape.net> <3b6faf240809010805u2a010849hbc04111818919e3f@mail.gmail.com>
2008/8/27 Aaron P. D'Souza <adsouzp@netscape.net>
>
> hello:
>
> one small question regarding use of ARM inline assembly code in a
> C file that has been compiled for Thumb mode.
>
> is it possible to use ARM assembly code from within a C file that
> has been compiled for Thumb and Thumb interworking?
The easiest way would be to just write an assembler file with:
.global function_f
.arm
function_f:
mrs r0, cpsr
msr cpsr_c, r0
bx lr
... if you provide the correct cpu and interwork flags during the
assemble/link phases, this will get interworking veeners and thus will
be called correctly from both arm and thumb code.
If that's not an option, then you probably would need to do something like this:
void function_f(void)
{
register int x;
#ifdef __thumb__
register int y;
#endif
asm volatile (
#ifdef __thumb__
".align 2\n"
"bx pc\n"
"nop\n"
".arm\n"
#endif
"mrs %0, cpsr \n\t"
"msr cpsr_c, %0 \n\t"
#ifdef __thumb__
"add %1, pc, #1\n"
"bx %1\n"
#endif
: "=r" (x)
#ifdef __thumb__
, "=r" (y)
#endif
);
}