Keil Logo

Register Use

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

  • Inline assembler instructions may not have expressions with forward references. The only exception to this are local labels and registerbanks (defined with the using keyword).
  • Function return value may be assigned to CPU registers. Refer to Return Values for information about the registers used for different return types.
  • It is not possible for the C166 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 RET instructions carefully. You must ascertain whether or not the C function code (generated by the compiler) executes PUSH/POP instructions or makes user stack adjustments. If this is the case, you should add a common exit label to your C code and use it in the inline assembler block.
  • You must save and restore the R0 register (which contains the user stack pointer) if your inline assembly code modifies it. For example:
    __asm  {
        PUSH  R0               ; save R0
        .
        .
        .
        POP   R0               ; restore R0
    }
    
  • Registers R1-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 R8-R15 are used to hold function arguments. If your inline assembly code modifies them, the C166 Compiler may be forced to save parameters and/or local variables to the user stack and reduce the number of register variables in the compiler-generated assembly code.
  • You must save and restore R13, R14, and R15 (which contain saved-by-callee registers) if your inline assembly code modifies them.
  • You must save and restore the DPP0-DPP3 Registers (which contain the Data Page Pointers) if your inline assembly code modifies them. For example:
    __asm  {
        PUSH  DPP2               ; save DPP2
        .
        .
        .
        POP   DPP2               ; restore DPP2
    }
    
  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.