AVR-GCC for Linux doesn't handle well 16 bit words

Volatile variables means "do not optimize me!"

When a variable has been declared volatile the compiler does:

  1. Read the variable from the memory and save it into a register.
  2. Process the register as need it.
  3. 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.