[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Problems with avr-gcc vers 3.0

From: Peter N Lewis
Subject: Re: [avr-gcc-list] Problems with avr-gcc vers 3.0
Date: Tue, 7 Aug 2001 09:53:08 +0800

Is there something I must know?

This delay routine does *nothing* as far as the rest of the program is concerned, so it would be a perfectly legitimate compilation of it to translate it in to:

void delay(void)

counter is not externally visible, so its value on completion is irrelevant.

If you want to do a delay routine, you should do it in assembler code, since otherwise there is no reasonable guarantee of what result you'll get on any given compiler. Even if you label the counter variable "volatile" and the compiler actually has to count through them all in order, the amount of time it will take is pretty much random depending on the compiler version, optimizing flags, etc.

Better yet would be to use a timer of course, although that is not always possible.

I have to admit, it is an odd optimization!

 102:../Common/Util.c **** void delay(void)
 103:../Common/Util.c **** {
 104:../Common/Util.c ****   int counter;
 105:../Common/Util.c ****
 106:../Common/Util.c ****   for(counter = 0; counter < 5000; counter++)
 347 0104 87E8                  ldi r24,lo8(4999)
 348 0106 93E1                  ldi r25,hi8(4999)
 349                    .L35:
 350 0108 8157                  subi r24,lo8(-(-625))
 351 010a 9240                  sbci r25,hi8(-(-625))
 352 010c EAF7                  brpl .L35
 355 010e 0895                  ret
 107:../Common/Util.c ****     ;
 108:../Common/Util.c **** }

Thanks in advance.

Maurizio Ferraris                mailto:address@hidden
Via Borgonuovo 27                mailto:address@hidden
10040 GIVOLETTO TO ITALY         http://www.studioferraris.it

avr-gcc-list mailing list

<http://www.interarchy.com/>  <ftp://ftp.interarchy.com/interarchy.hqx>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]