This is the mail archive of the
mailing list for the binutils project.
Re: arm thumb2 ldr.w syntax?
On 15/09/11 05:06, Jeffrey Walton wrote:
> On Wed, Sep 14, 2011 at 5:28 PM, Roland McGrath <firstname.lastname@example.org> wrote:
>> The disassembler shows me this for a Thumb2 instruction of interest:
>> 28: f8dc c000 ldr.w ip, [ip]
>> But I cannot figure out how to make the assembler emit that.
> I've run across similar when trying to generate Thumb instructions on
> an ARM. In my case, I could not get ADDS generated (the instruction
> was being rejected as invalid). Instead of 'ADDS, r1, r1, r0', I
> needed to emit the instruction manually:
> "ldr r0, %[xa] ;" // R0 = a
> "ldr r1, %[xb] ;" // R1 = b
> ".short 0x1809 ;" // 'adds r1, r1, r0'
This is because for historical reasons GCC generates legacy syntax for
Thumb1 assembly code, but unified syntax for Thumb2 assembly code.
Roland's case looks like a case of trying to generate an assembly file
directly and failing to put
at the start.
The second case looks like GCC inline assembly, where you are generating
Thumb-1 code. The legacy equivalent of
adds r1, r1, r0
add r1, r1, r0 // Flag setting implicit in legacy code.
Don't try to put .syntax unified into inline assembly code, though.
You'll just end up confusing the compiler in all likelihood.
Finally, don't ever use .short or .word for instructions, this will
cause them to be marked as data in the object file (which would be
disastrous in big-endian mode). Instead use .inst, .inst.n or .inst.w
as the context demands.