cancel
Showing results for 
Search instead for 
Did you mean: 

Reversing endianess

T J
Lead
Posted on June 03, 2018 at 03:07

4.4.4 REV, REVH, and REVSH

REV reverses the byte order in a data word,

For example, if R0 is 0x12345678, in executing the following:

REV R1, R0

R1 will become 0x78563412,

The Definitive Guide to the ARM� Cortex-M3 by Joseph Yiu

in a C file

Would call this assembler instruction in a function ?

or define it as a macro ?

or inline assembler ?

#endianness
4 REPLIES 4
Posted on June 03, 2018 at 03:24

STM32Cube_FW_L4_V1.11.0\Drivers\CMSIS\Include\cmsis_armcc.h

use

foo = __REVSH(foo);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 03, 2018 at 04:00

is that for 32bit data ?

is this ok ?

// inline ASM

   uint32_t  r0 = IncomingData;

   uint32_t  r1;

    __asm

    {

        rev r1, r0

    }

   RevData = r1;

Posted on June 03, 2018 at 13:47

/**

  \brief   Reverse byte order (32 bit)

  \details Reverses the byte order in integer value.

  \param [in]    value  Value to reverse

  \return               Reversed value

 */

♯ define __REV                             __rev

/**

  \brief   Reverse byte order (16 bit)

  \details Reverses the byte order in two unsigned short values.

  \param [in]    value  Value to reverse

  \return               Reversed value

 */

♯ ifndef __NO_EMBEDDED_ASM

__attribute__((section('.rev16_text'))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)

{

  rev16 r0, r0

  bx lr

}

♯ endif

/**

  \brief   Reverse byte order in signed short value

  \details Reverses the byte order in a signed short value with sign extension to integer.

  \param [in]    value  Value to reverse

  \return               Reversed value

 */

♯ ifndef __NO_EMBEDDED_ASM

__attribute__((section('.revsh_text'))) __STATIC_INLINE __ASM int32_t __REVSH(int32_t value)

{

  revsh r0, r0

  bx lr

}

♯ endif
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 03, 2018 at 15:12

my blank project compiles except for this section:

when I enable this code:

&sharpifndef __NO_EMBEDDED_ASM

__attribute__((section('.revsh_text'))) __STATIC_INLINE __ASM int32_t __REVSH(int32_t value)

{

  revsh r0, r0

  bx lr

}

&sharpendif

I get:

Error        expected identifier or '(' before '__asm'    TH18    C:\Users\nickm\Documents\VS2018\TH18_Cube\Drivers\CMSIS\Include\cmsis_gcc.h    36    

cmsis_gcc.h:

34 /* CMSIS compiler specific defines */

35 &sharpifndef   __ASM

36 &sharpdefine __ASM                     __asm

37 &sharpendif