There's no quick easy answer to that. It depends on a number of factors... the data types involved, 8/16/32 bit target, etc.
In general, multiplication and division will probably involve one of the system libraries, so you should use 'save(0)' to protect the internal system variables (those named SB_xxxxx). For the PIC18 (which I think you're using), save(0) will also save the FSR0, FSR1, and PROD registers for you.
An expression like
- Code: Select all
RoundedDiv = (ValueNum + ( ValueDivisor / 2)) / ValueDivisor
will almost always generate some intermediate temp variables, but you normally shouldn't have to worry too much about those if the code is
directly inline in the isr. If it's in a sub or event that you call from the isr that's a different story. If you call a routine then you should add the sub's name to the save() list.
If you want to avoid the use of any intermediate values, then you have to help the compiler along and break up the expression so that there's nothing on the right-hand side that would have to be saved...
- Code: Select all
RoundedDiv = ValueDivisor / 2
RoundedDiv = RoundedDiv + ValueNum
RoundedDiv = RoundedDiv/ValueDivisor
Sometimes that can end up producing smaller code as well, but it's a lot of bother and makes it much harder to see what the intent is.
So, the general rule is something like this:
- if you don't want to bother looking at the asm, use 'save(0)'
- if you call ANY routines from the isr, add them to the 'save()' list
That should be safe. It might be overkill, but it should work. If you want to reduce the overhead then you need to do a little digging.
PS - I assumed you meant an interrupt handler, and not a PIC24 exception handler. Two different things.