The compiler doesn't know that the ISR that changes the value of a
is ever run, and so has optimized the entire loop out due to its evaluation of the loop condition. You must declare a
as volatile
in order to tell the compiler that its value must be checked each time.
volatile int a = 0;