Hello, Pedro,

Thursday, April 3, 2003, 10:19:28 PM you wrote:

PZN> On Thu, Mar 27, 2003 at 11:10:04AM -0500, D.Pageau wrote:
>> do
>> {
>>       IFG1 &= ~OFIFG;                       // Clear OSCFault flag
>>       for (i = 0xFF; i > 0; i--);           // Time for flag to set
>> }
>> while ((IFG1 & OFIFG) == OFIFG);      // OSCFault flag still set? 

PZN> Hi Pageau,

PZN>   The optimizer will detect this as "useless" loop and remove it.

PZN>   Instead of:
PZN>     for (i = 0xFF; i > 0; i--);
PZN>   try:
PZN>     for (i = 0xFF; i > 0; i--) __asm__ __volatile__("; loop");

PZN>   See also:
PZN>     http://mspgcc.sourceforge.net/doc_appendixE.html

By  the  way,  I  have  discovered  that  this  is true only for "-O1"
optimisation. When I use such delay function:

#define DELAY(X) ({unsigned int _i = (X); \
                   do __asm__ __volatile__ ("; loop"); \
                   while(--_i);})

and  if  "-O2"  option used, compiler all the same
remove  the  loop completely. :( If I try to use:

#define DELAY(X) ({unsigned int _i = (X); \
                   do __asm__ __volatile__ ("nop"); \
                   while(--_i);})

instead,  the  compiler  generates  so much  "nop"
instructions how much is indicated by the counter value.

Regards,
Victor.


Reply via email to