avr-gcc-list
[Top][All Lists]
Advanced

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

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


From: Lai Kang Tin
Subject: Re: [avr-gcc-list] Problems with avr-gcc vers 3.0
Date: Wed, 8 Aug 2001 09:59:32 +0800 (HKT)

If you compile the code using gcc i386,
you will get a correct codes generated.

.globl delay
        .type    delay,@function
delay:
        pushl %ebp
        movl %esp,%ebp
        movl $4999,%ecx
        .p2align 4,,7
.L5:
        decl %ecx
        jns .L5
        leave
        ret
.Lfe1:
        .size    delay,.Lfe1-delay




On Tue, 7 Aug 2001, Peter N Lewis wrote:

> >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!
>     Peter.
> 
> >  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.
> >Mau.
> >
> >_____________________________________________________________
> >Maurizio Ferraris                mailto:address@hidden
> >Via Borgonuovo 27                mailto:address@hidden
> >10040 GIVOLETTO TO ITALY         http://www.studioferraris.it
> >
> >
> >_______________________________________________
> >avr-gcc-list mailing list
> >address@hidden
> >http://avr.jpk.co.nz/mailman/listinfo/avr-gcc-list
> 
> 
> -- 
> <http://www.interarchy.com/>  <ftp://ftp.interarchy.com/interarchy.hqx>
> 
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://avr.jpk.co.nz/mailman/listinfo/avr-gcc-list
> 

K.T.LAI
address@hidden





reply via email to

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