Bob Paddock ha scritto:
you see that the last rjmp is jumping to the point where shift
is reinitialized with '1' (r18/r19).
Moving 'uint16_t shift = 1;' out of the for(;;){} and into
the top of main(){} makes the code work ok.
Is it my understanding, or the compiler that is broken here?
Nothing is broken.
If you declare shift inside the for block, every time block is executed
shift is recreated.
As James said, with optimizations turned on, the code
if (0 == shift)
...
is optimized away, while if you add volatile you deny the compiler the
assumption that the variable will not be modified, forcing to generate
the code that use it. However, even with volatile keyword, the code
cannot work as you intend because every time the loop ends shift die and
borns again on loop start, initialized with 1.
--
_|/ Francesco Sacchi - Develer S.r.l., R&D dept.
|\ http://www.develer.com/
_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list