What and where does the content store a context switching

Thread Starter


Joined Oct 28, 2023
I'm trying to grasp the theory of context switching in embedded systems. I understand that when an interrupt is triggered, the processor must immediately execute the Interrupt Service Routine (ISR). In a example where we have a main function and a timer interrupt configured to generate a 1 millisecond interrupt, it seems that when the processor is executing the main function and an interrupt occurs, it jumps to the ISR and then returns to the main function once the ISR is done. This transition from the main function to the ISR is often referred to as context switching.

However, I'm having trouble understanding the specifics of this process. How and where does the processor store the context of the main function before jumping to the ISR, and what exactly does this store? I've read further, but I'm still struggling to grasp.


Joined Mar 31, 2012
The details depend on the processor, but the big thing is the address of the next instruction to be executed so that the processor can pick up where it left off. Then, if needed, the processor will store the minimum number of registers someplace safe -- things that it knows will get overwritten as part of any ISR call. After that, it is up to the ISR to safeguard any other values that it needs to change but that are expected to be left intact by the process that was interrupted.