Re: Issue byte codes for ARMv7's movw and movt?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 21/05/2019 00:39, Jeffrey Walton wrote:
> Hi Everyone,
> 
> I'm having trouble crafting the byte codes for the following from C/C++:
> 
>     asm volatile("movw %0,%1 \n"
>         "movt %0,%1 \n"
>         : "=r"(a) : "i"(0x1234));
> 
> When I tested and disassembled it produced:
> 
>     00000000 <_Z4testv>:
>        0:   f241 2334       movw    r3, #4660       ; 0x1234
>        4:   f2c1 2334       movt    r3, #4660       ; 0x1234
>        8:   4770            bx      lr
> 
> Then, moving back to C/C++:
> 
>         int a;
>         asm volatile (
> #if __BIG_ENDIAN__
>             ".byte 0xf2, 0x41, 0x23, 0x34  \n\t"   // movw r3, 0x1234
>             ".byte 0xf2, 0xc1, 0x23, 0x34  \n\t"   // movt r3, 0x1234
>             "mov %0, r3                    \n\t"   // mov [a], r3
> #else
>             ".byte 0x41, 0xf2, 0x34, 0x23  \n\t"   // movw r3, 0x1234
>             ".byte 0xc1, 0xf2, 0x34, 0x23  \n\t"   // movt r3, 0x1234
>             "mov %0, r3                    \n\t"   // mov [a], r3
> #endif
>             : "=r" (a) : : "r3");
> 
>         result = (a == 0x12341234);
> 
> However, when I step the code under GDB, it disassembles to strcc or teqcs.
> 
> I seem to recall there's a special way of doing this with ARM such
> that two code paths are not needed, but I don't recall them. I thought
> it used .word or .instruction, but I can't find a reference at the
> moment.
> 
> How do I issue the byte codes for movw and movt?

Use the .inst directive.  If you don't, the assembler will mark the area
as data and bad things might happen during linking, especially on
big-endian devices.

You shouldn't need big and little endian variants if you do it right,
unless the constants to load are themselves endian dependent.

> 
> Thanks in advance.
> 

R.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux