15.11 Context Saving During Interrupts

During interrupts, the return PC address is saved on the stack. Additionally, the WREG, STATUS and BSR registers are saved on the fast return stack. If a fast return from interrupt is not used the user may need to save the WREG, STATUS and BSR registers on entry to the Interrupt Service Routine. Depending on the user’s application, other registers may also need to be saved. Saving Status, WREG and BSR Registers in RAM saves and restores the WREG, STATUS and BSR registers during an Interrupt Service Routine.

Saving Status, WREG and BSR Registers in RAM


        MOVWF   W_TEMP                 ; W_TEMP is in virtual bank
        MOVFF   STATUS, STATUS_TEMP    ; STATUS_TEMP located anywhere
        MOVFF   BSR, BSR_TEMP          ; BSR_TEMP located anywhere
;
; USER ISR CODE
;
        MOVFF   BSR_TEMP, BSR          ; Restore BSR
        MOVF    W_TEMP, W              ; Restore WREG
        MOVFF   STATUS_TEMP, STATUS    ; Restore STATUS