Ok, this is probably what's happening.
You've got just enough variables that 1 or 2 are getting pushed into BANK1.
In particular _portb_masked.
_portb_masked is used in the interrupt handler, but the Bank isn't being changed. So it ends up overwriting memory in BANK0.
Where it's located makes it overwrite PBP's system registers at R1.
If you comment out the DEBUG_STACK variable like you mentioned, the _portb_masked variable moves and then overwrites PBP's R0 system var.
As the placement of the variable moves, so does the apparent problem that it causes, which corresponds with your symptoms.
If you were to remove two more variables, _portb_masked would no longer be in BANK1, and it would probably run correctly.
Unless you are handling the Banking, any variables you use at the ASM level should be declared in BANK0.
Code:
encoder_history VAR BYTE BANK0:encoder_history = 0 'Store the current and last state of channelA/B of the encoder
portb_masked VAR BYTE BANK0:portb_masked = 0 'Masked port B to have only the encoder channels
interrupt_debug VAR BYTE BANK0: interrupt_debug = 0
HTH,
Bookmarks