#pragma saved_regs register,register,register, ..

Since version 0.7.3, the SAVE_REGS and RESTORE_REGS macro are suppressed. These macros were used to save and restore the data modified by an Interrupt Service Routine on to the stack. However, this kind of context saving had two disadvantages:

  1. Data was saved in the stack frame of the function, so the available space on the stack was reduced,
  2. because data was saved after the local variables, these variables were not properly managed by the compiler. It was indeed a very bad feature, because the code of ISRs was obliged to use only global variables.
With the new pragma, registers are saved before the stack frame, so the two previous defaults disappear.

The following saved_regs pragma is provided in the <interrupt.h> header:

#pragma saved_regs _r0,_r0+1,_r1,_r1+1,_r2,_r2+1,_r3,_r3+1,PRODL,PRODH

You can redefine this pragma just before an ISR routine if you are not happy with the standard registers list. Note that doing such a redefinition does not expand the previous list of registers, but creates a new list. It means that you can easily turn off all the registers savings with:

#pragma saved_regs

Also remember that the registers used by the floating point routines are not saved if you use the standard registers list, so if an ISR performs floating point maths, you will have to use this pragma4.

The register specification can be any expression or address that refers to a valid location in memory because data is pushed with a movff instruction, that can access any page. However, never use this pragma to save any interrupt control registers (INTCONx or PIRx) because, as stated in the documentation, they cannot be manipulated with the movff instruction.



Footnotes

... pragma4
However, it is generally not a good idea to perform complex calculations in an interrupt service routine.
Alain Gibaud 2015-07-09