When to use # pragma interrupt handler directive

Question: Is it necessary to use the #pragma interrupt handler directive for all C functions called from the Interrupt.asm file?



The #pragma interrupt handler directive needs to be used only when the Preserve and Restore CPU context is not being done before and after calling the C function from the INT.asm file. For example, if the sequence of calling the C function from the concerned INT.asm file is as below:


   lcall _My_C_Function


Then the function My_C_Function should not be declared with a #pragma interrupt handler directive. This is because, the #pragma interrupt handler directive adds an additional Preserve and Restore, as well a return from interrupt at the end of the My_C_Function, which  causes program counter corruption and the code gets into an unknown loop.

If using the #pragma interrupt handler directive , the call in the INT.asm has to be just:

Ljmp _My_C_Function

Note again that it should not be a lcall, but a ljmp while using this directive.