assemblyarmimmediate-operand

How to know that a certain number can be represented as 32 bit immediate in ARM?


Given a number x, how can we tell that it can be represented as 32-bit immediate. Does any kind of formula exists? If yes, is that formula exhaustive, i.e., covers all the possible cases? ARM decomposes the rightmost 12 bits in the instruction set as 4 bit rotate-bit and 8 bit value bit.


Solution

  • I would look into open source compilers and how they do it...

    https://github.com/gcc-mirror/gcc/blob/cbca62831cb7c1c7c20d67fcf929f156b09923bf/gcc/config/arm/arm.c#L4387

    /* Return TRUE if int I is a valid immediate ARM constant.  */
    int
    const_ok_for_arm (HOST_WIDE_INT i)
    {
    ...