Search code examples
assemblycompiler-constructionarmcpu-registers

Restrict a routine to use a limited set of registers


Using compiler option, is it possible to restrict a routine from using certain set of registers?

For example: Restrict a routine to use only R0-R8;

Purpose: If some compiler option available, then I could ensure certain routines (like Interrupt Service Routines) to use only limited register set, and thus do limited Context Save & Restore.


Solution

  • When this was last discussed, the consensus was that it is not possible on a function-by-function basis.

    There are ways to restrict register use throughout an entire compilation, so if you put your interrupt routines in a separate compilation unit, you can use the gcc switch -ffixed-reg. I believe it would be used like -ffixed-R0 if you wanted the compiler to not generate code using R0.