How to set PC (Program Counter) register to another function (for scheduler) I am trying to implement a scheduler for Arduino Mega 2560. I think I lack understanding of how to set the PC register to another instruction.
Here is my simple approach so far:

void dummy(){
    digitalWrite(LED_BUILTIN, HIGH);
 }


in a naked ISR method:

SP = (uint16_t)(&amp;dummy)
__asm volatile(
"reti     \n\t"
)


However it is not working. How should the PC register be set to a certain function or to where it was in a previous process for a scheduler approach?
This:
SP = (uint16_t)(&amp;dummy)

is changing the stack pointer. Not what you want. You want to instead
push the destination address to the stack. However, rather than
simulating a function return, it should be simpler to perform an
indirect jump:
asm volatile(&quot;ijmp&quot; :: &quot;z&quot;(dummy));

Don't forget that your naked ISR has to save all the call-used
registers, as well as SREG, r0 and r1, in its custom prologue. And
restore them in its epilogue. Check the AVR calling
conventions.