This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Interrupt Register Bank Usage

I created a timer 0 interrupt handler:

void Timer_0_Interrupt(void) interrupt INTERRUPT_TIMER_0 using 1
{ ...
}

I noticed that the compiler created instructions with absolute register access. Please confirm that I must also specify either "#pragma REGISTERBANK(1)" or "#pragma NOAREGS". Otherwise the code will use register bank 0 for the absolute register instructions.

  • Please confirm that I must also specify either "#pragma REGISTERBANK(1)" or "#pragma NOAREGS". Otherwise the code will use register bank 0 for the absolute register instructions.

    You do not, "using 1" makes the routine (ISR or other) use register bank 1 throughout.

    Erik

  • As Erik points out, the 'Using 1" tells the compiler to switch register bank from 0 to register bank 1 on entering the ISR routine. The compiler creates a prolog to store some information on a 'stack' not in the registers. On exiting the ISR, the code pops the PC address from the stack and switches back to register bank 0.

    Bank 0 is the default register bank. Most of the time register bank 0 is used to pass args to called sub-routines. Regs 7 and 6 for the first arg (int) and then regs 5 and 4 for the second arg (int) and then regs 3 and 2 for the third args. Any other args are passed via absolute memory addresses. Regs 1 and 0 are not used for passing args. Of course, args cannot be passed into an ISR and any values in reg bank 0 would remain until the bank becomes active once again.

    Never, never, never write Using 0! You give the compiler/linker permission to write over Register Bank 0 without saving any of the registers.

    It's in the book!

    Bradford