Which registers should be pushed in a naked ISR
Posted: 10 February 2008, 11:40 AM
If you don't use a naked ISR, then the compiler automatically pushes and pops all of the required 15 registers (r0, r1, SREG, r18-r27, r30, and r31).
Presumably you would write a naked ISR if you wanted to make the ISR faster. The problem comes in when you mix a naked ISRs with ZBasic code and knowing which registers to push. For example:Through careful research it would appear that PutPin requires R22 and R24 and also uses r16 and r25. The question is how can this be determined easily.
Perhaps it should be a compiler warning/error to use ZBasic functions inside a native ISR - it is too dangerous.
Presumably you would write a naked ISR if you wanted to make the ISR faster. The problem comes in when you mix a naked ISRs with ZBasic code and knowing which registers to push. For example:
Code: Select all
ISR Timer1_CompB() Attribute(Naked)
#asm
; push registers here
#endasm
Call PutPin(D.7, 0) ' which registers are touched by this call
#asm
; pop registers here
reti ; always needed
#endasm
End ISR
Perhaps it should be a compiler warning/error to use ZBasic functions inside a native ISR - it is too dangerous.