本文仅对 keil armcc 编译器有效,对于其他编译器未验证,不清楚。
代码:
#define __ASM __asm /*!< asm keyword for ARM Compiler */
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
#define __STATIC_INLINE static __inline
/** \brief Set Priority Mask
This function assigns the given value to the Priority Mask Register.
\param [in] priMask Priority Mask
*/
__STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
{
register uint32_t __regPriMask __ASM("primask");
__regPriMask = (priMask);
}
参见armcc.chm文件9.155 Named register variables一节。
9.155 Named register variables
The compiler enables you to access registers of an ARM architecture-based processor or coprocessor using named register variables.
Syntaxregister type var-name __asm(reg);
Where:
type
- is the type of the named register variable.
- Any type of the same size as the register being named can be used in the declaration of a named register variable. The type can be a structure, but bitfield layout is sensitive to endianness.
var-name
- is the name of the named register variable.
reg
- is a character string denoting the name of a register on an ARM architecture-based processor, or for coprocessor registers, a string syntax that identifies the coprocessor and corresponds with how you intend to use the variable.
- Registers available for use with named register variables on ARM architecture-based processors are shown in the following table.
其大致意思是:可以用register type var-name __asm(reg)
这样的定义,来声明一个命名寄存器的变量,像使用变量一样操作他们;
type 是声明变量的类型;需要与寄存器大小一致,且注意大小端;
var-name 是声明变量的名称;
r