4.8.4 Context Switching

The compiler will automatically link code into your project which saves the current status when an interrupt occurs, and restores this status when the interrupt returns.

All call-used registers will be saved in interrupt code generated by the compiler. This is the context save or context switch code.

Any objects saved by software are automatically restored by software before the interrupt function returns. The order of restoration is the reverse of that used when context is saved.