Search code examples
assemblygcccortex-m

Need explanation of ARM Cortex-M3 assembly instruction in CMSIS to __set_PRIMASK


Below is a code snippet from the ARM CMSIS library that is used to set the value of the PRIMASK register.

/**
 * @brief  Set the Priority Mask value
 *
 * @param  priMask  PriMask
 *
 * Set the priority mask bit in the priority mask register
 */
static __INLINE void __set_PRIMASK(uint32_t priMask)
{
   register uint32_t __regPriMask         __ASM("primask");
   __regPriMask = (priMask);
}

The part that I don't understand is the inline assembly instruction

__ASM("primask");

I haven't read anything about addressing registers by name in this way. How can you have inline assembly without an op-code first? Is this assigning __regPriMask to this register location? Can anyone point to a reference document?


Solution

  • register uint32_t __regPriMask __ASM("primask");
    

    ...is the declaration of a local register variable called __regPriMask that is stored in the primask register.

    In other words, assigning to that register variable will set the value of the register primask.