With "Naked", the compiler omits ALL of the standard context save and restore that it would have inserted on an ISR. How much context that is is dependent on exactly what code your ISR contains. If the ISR is a "leaf" function (doesn't call any other functions), the context saved includes R0, R1, the status register, and whatever registers the code actually uses.
ISR(PCINT1_vect) {
2d2: 1f 92 push r1
2d4: 0f 92 push r0
2d6: 0f b6 in r0, 0x3f ; Status register
2d8: 0f 92 push r0
2da: 11 24 eor r1, r1 ;r1 must be a "known zero" for C code.
This has actually been improved in more recent versions of the compiler (not currently used by Arduino), so that if you don't use R0, R1, or instructions that change the SR, they won't be saved.
Of course, there is matching "restore" code at the end of the ISR.
if the ISR calls additional code, it also has to save whatever registers are defined as "caller modifiable" by the C api. Thisi is ... a lot, but is somewhat mitigated by the use of link time optimization...
IMPLEMENT_ISR(INT1_vect, EXTERNAL_INT_1)
186: 1f 92 push r1
188: 0f 92 push r0
18a: 0f b6 in r0, 0x3f ; status register
18c: 0f 92 push r0
18e: 11 24 eor r1, r1 ; known zero
190: 2f 93 push r18 ; registers that C code does not have to preserve.
192: 3f 93 push r19 ; :
194: 4f 93 push r20
196: 5f 93 push r21
198: 6f 93 push r22
19a: 7f 93 push r23
19c: 8f 93 push r24
19e: 9f 93 push r25
1a0: af 93 push r26
1a2: bf 93 push r27
1a4: ef 93 push r30
1a6: ff 93 push r31
:
Also is there a difference in trigger-to-start time between interrupts defined like:
attachInterrupt(digitalPinToInterrupt(pin), ISR_func, mode)
Yes. if you use a bare ISR, it's address is a compile-time constant, so it gets inserted directly into the AVR vector table. attachInterrupt
allows the vector to be changed at runtime, so it has an additional level of indirection (load the ISR address from a RAM location, and then do an icall
), IN ADDITION to invoking that "have to save a lot because I don't know what the C code called will do" described above.
;;; All that other context save from above
1a6: ff 93 push r31
1a8: e0 91 02 01 lds r30, 0x0102 ; Load provided function address
1ac: f0 91 03 01 lds r31, 0x0103 ; (which is two bytes)
1b0: 09 95 icall ; indirect call
1b2: ff 91 pop r31 ; start restoring state.
;; more restore state
I believe "naked" also omits the "iret" instruction at the end of the ISR...
Usually, a "naked" ISR will consist entirely of inline asm statements.