0
0
Embedded Cprogramming~10 mins

Interrupt vector table in Embedded C - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Interrupt vector table
CPU Reset
Fetch Interrupt Vector
Jump to ISR Address
Execute ISR
Return to Main Program
When an interrupt occurs, the CPU looks up the interrupt vector table to find the address of the correct Interrupt Service Routine (ISR) and jumps there to handle the interrupt.
Execution Sample
Embedded C
void ISR_Timer(void) {
    // Timer interrupt code
}

void (* const interrupt_vector_table[])(void) = {
    ISR_Timer
};
Defines an interrupt vector table with one entry pointing to the Timer ISR function.
Execution Table
StepEventActionVector Table LookupISR CalledResult
1CPU ResetFetch reset vectorAddress of Reset ISRReset ISRStart main program
2Timer InterruptFetch timer vectorAddress of ISR_TimerISR_TimerExecute timer ISR code
3ISR_Timer completesReturn from ISRN/AMain program resumesContinue normal execution
4No more interruptsIdleN/AN/AProgram runs main loop
💡 No interrupts pending, CPU runs main program continuously
Variable Tracker
VariableStartAfter InterruptAfter ISRFinal
Program Counter (PC)Reset vector addressISR_Timer addressReturn address after ISRMain program address
Interrupt Flag0 (no interrupt)1 (interrupt triggered)0 (interrupt handled)0 (idle)
Key Moments - 3 Insights
Why does the CPU jump to a specific address when an interrupt occurs?
Because the CPU uses the interrupt vector table to find the address of the ISR to handle that interrupt, as shown in execution_table step 2.
What happens to the program counter during an interrupt?
The program counter saves the current address and loads the ISR address from the vector table, as tracked in variable_tracker under Program Counter.
How does the CPU know when to return to the main program?
After the ISR finishes, the CPU uses the saved return address to resume the main program, shown in execution_table step 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what ISR is called at step 2?
AReset ISR
BMain program
CISR_Timer
DNo ISR
💡 Hint
Check the 'ISR Called' column at step 2 in execution_table
According to variable_tracker, what happens to the Interrupt Flag after the ISR completes?
AIt stays 1
BIt resets to 0
CIt becomes 2
DIt is undefined
💡 Hint
Look at the Interrupt Flag values after ISR in variable_tracker
If a new interrupt occurs, how would the execution_table change?
AA new step with fetching vector and calling ISR would be added
BThe CPU would ignore the interrupt
CThe program counter would not change
DThe main program would stop permanently
💡 Hint
Refer to the flow in execution_table steps 2 and 3 for interrupt handling
Concept Snapshot
Interrupt vector table holds addresses of ISRs.
CPU uses it to jump to correct ISR on interrupt.
Program counter changes to ISR address.
After ISR, CPU returns to main program.
Each interrupt type has a vector entry.
Full Transcript
An interrupt vector table is a list of addresses where the CPU can find the code to handle different interrupts. When the CPU resets, it starts at the reset vector. When an interrupt happens, the CPU looks up the vector table to find the ISR address and jumps there. The program counter changes to this ISR address. After the ISR runs, the CPU returns to where it left off in the main program. The interrupt flag signals when an interrupt is active and resets after handling. This process ensures the CPU responds quickly and correctly to hardware events.