We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi guys,
First of all, I'm using a LM3S6950 Arm Cortex M3 microcontroller with Keil MDK 3.70. I'm programming in C, Thumb Mode.
For converting low endianess to big endianess I want to use the rev and rev16 instruction.
32 Bit swaps can be done with the build in __rev() inline C function (http://www.keil.com/support/man/docs/armccref/armccref_cjaeegce.htm)
How can I do this with the 16 bit instruction since inline assembler isn't supported in thumb mode?
Thanks for your replies br Robert
Mike:
I would bracket a, as in
b = (((a) & 0x00ff) << 8) | (((a) & 0xff00) >> 8);
just in case (a) is an expression.
also, I am not sure why you need to to the & operation before shifting, assuming a is 16bit or shorter.
Parentheses around "a" is only needed if you make a #define of the expression.
Remember that the ARM is a 32-bit processor. Even if variable a is 16-bit large, the compiler will upgrade your expression to a 32-bit values, so if b is 32-bit and you try to reverse 0x8765, you will not get 0x6587 but 0x876587 if you don't do the bit-and.
And if a happens to be signed, life will be extra fun. With the & operations, you would still get the correct result, but without them, you would get 0xffffff87 because the upgrade from 16-bit to 32-bit will be with sign-extend.
...just in case (a) is an expression.
I realize that. What I did was copy&paste from this presentation (page 4): www.newark.com/.../LMTTCM3.pdf