Volatile variables means "do not optimize me!"
When a variable has been declared volatile the compiler does:
- Read the variable from the memory and save it into a register.
- Process the register as need it.
- Save the result into memory.
I did it this way to help me figure the error out. You might want to generate both assembly outputs (volatile and no volatile) to see the difference.