Many thanks to Darrel Taylor ! I'll have to try this immediately.


His techniques probably make most of what I'm about to write obsolete - but last night I promised that I would post what I learned about assembly-language interrupts and PBP from Tim Box, Charles Leo (of MELABS) and my own testing. The information presented is believed to be accurate, but I cannot guarantee this without complete testing - something I will do within the next few days. If I find any mistakes, I'll post an update.

1)
Some of the newer 18F parts have a new instruction -

RETFIE FAST

This instruction AUTOMATICALLY saves and restores the W,STATUS and BSR registers. Unless you mess around with pointers (such as FSR0x), this is all you need to do use. No extra instructions for saving and restoring context are needed. Just put it in place of the ordinary 'retfie' instruction. Check your datasheet to make sure if your part offers this. The 18F8720 and '8722 have this instruction.

2)
If your part does NOT have the "fast interrupt" enhancement, you should *normally* only need to save and restore W,STATUS and BSR.

3)
ALL of the variables declared by PBP but used in the assembly routine should be declared as 'bankA'.

4)
Variables declared by PBP are given an underscore "_" before the name when used in assembly. For example: 'MyVar var BYTE bankA' in PBP becomes '_MyVar' in assembly. To allow the same name in both PBP AND assembly, you need to define the variable as 'system' . For example 'MyVar BYTE bankA
system' has the name 'MyVar' in assembly (The assembler variable doesn't require an underscore as long as the variable is declared as 'system'.)

5)
Don't declare BIT variables in PBP to later be used in an assembly routine.
Use BYTE or WORD variables only. If you just need a bit to act as a flag, declare a PBP variable such as 'FLAGVAR' and set/reset one of the bits.

6)
Since your are only using the Access Bank (bankA) in your assembly-language routine, you don't need to use GOTOs. Use the BRA (branch) instruction instead.

7)
If you have two interrupt levels (high and low priority), you can use the PBP defines -
DEFINE INTHAND (label of high-priority interrupt handler) and
DEFINE INTLHAND (label of low-priority interrupt handler)

Save and restore context the same way as described above. RETFIE FAST works on the low-priority interrupt, too.