Re: QUERY : ARM mode inline instructions in C Thumb mode file?




"adsouzp" <adsouzp@xxxxxxxxx> wrote in message news:APqdnc54RY_X4ijVnZ2dnUVZ_rHinZ2d@xxxxxxxxxxxxxxx
Nick Clifton said:

There are two problems with the above code:

1. You do not switch back to thumb mode at the end of the ARM code
fragment. Gcc passes the contents of the asm() directory on to the
assembler - it does not try to parse it and discover that you are
sneakily switching into ARM mode...

2. You have the .arm directive without a nearby label to hang it on.
The .arm (and .thumb) directives need a label because the changes
between instruction sets is encoded into attributes of the labels, thus
allowing the linker and disassembler to know when instruction sets have
changed.

ie. please try this:

void function_f( void )
{
asm volatile
(
".align \n"
"__f_into_arm:\n\t"
".arm \n\t"
"mrs r0, cpsr \n\t"
"msr cpsr_c, r0 \n\t"
"pop { r0 } \n"
"__f_from_arm:\n\t"
".thumb"
);
}

i tried the above code but it still did not work! here is the code
generated.

00008194 <function_f>:
8194: b580 push {r7, lr}
8196: af02 add r7, sp, #8

00008198 <__f_into_arm>:
8198: 0000 lsls r0, r0, #0
819a: e10f b.n 83bc <wrap+0x10>
819c: f000 e121 blx 4083e0 <_stack+0x3883e0>
81a0: 0001 lsls r1, r0, #0
81a2: e8bd 46bd ldmia.w sp!, {r0, r2, r3, r4, r5, r7, r9, sl, lr}

000081a4 <__f_from_arm>:
81a4: b08246bd strlth r4, [r2], sp
81a8: bc01bc80 stclt 12, cr11, [r1], {128}
81ac: 00004700 andeq r4, r0, r0, lsl #14

That's because you need to first use .arm and then define the label.
The label uses the current instruction set, and doesn't look at whatever
comes afterwards. The disassembly is what I'd expect it to be.

Wilco


.



Relevant Pages

  • Re: interesting article on quantum cryptography
    ... label the sorry arm and execute it in respect of its election. ...
    (sci.crypt)
  • Re: The thumb state of MC9328MXL
    ... > The hardware group designed a development board of MC9328MXL for our ... > the thumb mode only and the thumb mode is 16 bit. ... > reasons that might be ARM state. ... ARM processes always start in ARM state. ...
    (comp.arch.embedded)
  • Re: Advice neede: Atmel or Philips ARM
    ... It would allow to grow with 82 % if you run in Thumb mode. ... According to Steve Furber "ARM system on chip architecture" who is one ... Philips 128-bit wide bus. ... So there is about a 22% difference on Dhrystone. ...
    (comp.arch.embedded)
  • Re: ADS1.2 inline assembly :Branching by writing PC is not supported
    ... I create a project as arm executable image in default settings. ... I think maybe ADS1.2 compiler doesn't support this kinds of syntax. ... You should read the ADS manual/docs. ... The inline asm in ADS is not quite pure asm, ...
    (comp.arch.embedded)
  • Re: fast arm9 cipher?
    ... RC5 might do better, it is a nice standard to use though and probably ... I don't benchmark RC4 on ARM platforms (mostly ... fast ARM asm code for some cipher, since I have no experience writing ARM ...
    (sci.crypt)