Keil Logo

Register Use

There are several rules for registers used in inline assembly blocks.

  • Inline assembler instructions may not have expressions with forward references. The only exception to this are local labels.
  • Function return value may be assigned to CPU registers. Refer to Function Return Values for information about the registers used for different return types.
  • It is not possible for the CARM Compiler to verify and validate the return value of inline assembly blocks. Moreover, checks for missing return values are relaxed for functions that include inline assembly. Therefore, great care is required to properly set the appropriate registers based on the function's return type.
  • Use B and BX instructions carefully. You must ascertain whether or not the C function code (generated by the compiler) saves and restores register values (using the stack). If this is the case, you should add a common exit label to your C code and use it in the inline assembler block.
  • Registers R0-R7 are preferred for inline assembly instructions. You may use these register in your inline assembly routines without saving and restoring them.
  • By default, registers R0-R3 are used to hold function arguments. If your inline assembly code modifies them, the CARM Compiler may be forced to save parameters and/or local variables to the stack and reduce the number of register variables in the compiler-generated assembly code.
  • Registers R4-R7 (saved-by-callee) are automatically saved if your inline assembly code modifies them. There is no need to add instructions that save or restore these registers.
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.