On Sun, Nov 08, 2015 at 05:01:34PM -0500, Ian Chapman wrote:
> Hi all,
>       I'm having difficulty understanding this situation.
> flag = 1;
> while ( 0 != flag )
> {
> code;
> }
>   generates strange assembly code till I commented out
> // flag = 1;
> it looked to me like the optimizer realized that from then on the code 
> would be planted in a " $  jmp  $; " situation.  I intended flag to be 
> cleared after an ADC interrupt.  ie set flag and wait for it to be cleared.
> Test code snippet and Makefile follow.

The compiler is allowed to assume that flag won't spontaneously change,
because you haven't told it otherwise. Either declare flag as volatile
(probably the simplest), or insert a memory barrier before checking its
value.

Cheers,
Daniel

-- 
Daniel Beer <dlb...@gmail.com> http://dlbeer.co.nz/
PGP: BA6E 0B26 1F89 246C E3F3  C910 1E58 C43A 160A 553B

------------------------------------------------------------------------------
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to