Skip to main content
T J
Senior III
June 3, 2018
Question

Reversing endianess

  • June 3, 2018
  • 1 reply
  • 5086 views
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
    This topic has been closed for replies.

    1 reply

    Tesla DeLorean
    Guru
    June 3, 2018
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    T J
    T JAuthor
    Senior III
    June 3, 2018
    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;

    Tesla DeLorean
    Guru
    June 3, 2018
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..