[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] AVR assembly for fast bit bang
From: |
Peter Fuhrmann |
Subject: |
Re: [avr-gcc-list] AVR assembly for fast bit bang |
Date: |
Wed, 9 Nov 2005 16:31:44 +0100 |
User-agent: |
KMail/1.7.2 |
> void write_data (Word towrite, Byte nbits)
> {
> Byte n;
>
> for(n = 0; n < nbits; n++)
> {
>
> CLK_HIGH;
> if( towrite & (0x0001 << n))
> {
> SDIO_HIGH;
> }
> else
> {
> SDIO_LOW;
> }
> CLK_LOW;
>
> }
> }
This will give very slow code, because a left shift by a variable will allways
take lots of cycles. Even with optimisation on this will give slow code. This
should work better:
void write_data (Word towrite, Byte nbits)
{
Byte n;
for(n = 0; n < nbits; n++)
{
CLK_HIGH;
if( towrite & 0x001)
{
SDIO_HIGH;
}
else
{
SDIO_LOW;
}
CLK_LOW;
towrite >>= 1;
}
}
Now always one shift is done with each cycle of the loop.
You should look at the dissassembler listing when you get this sort of
problem. Then you can see, what the compiler does, and optimize your C code,
so the compiler can generate better assembly for you.
I also suggest, you allways turn optimization on! This works very well with
gcc, I always use -Os, and haven't had any broken code problems so far.
Regards,
Peter
- [avr-gcc-list] AVR assembly for fast bit bang, Mike S., 2005/11/08
- Re: [avr-gcc-list] AVR assembly for fast bit bang, Hugo González Monteverde, 2005/11/08
- Re: [avr-gcc-list] AVR assembly for fast bit bang, Daniel O'Connor, 2005/11/08
- Re: [avr-gcc-list] AVR assembly for fast bit bang, David Kelly, 2005/11/08
- Re: [avr-gcc-list] AVR assembly for fast bit bang, Mike S., 2005/11/09
- Re: [avr-gcc-list] AVR assembly for fast bit bang, Daniel O'Connor, 2005/11/09
- Re: [avr-gcc-list] AVR assembly for fast bit bang,
Peter Fuhrmann <=
- Re: [avr-gcc-list] AVR assembly for fast bit bang, Jesper Hansen, 2005/11/09
- Re: [avr-gcc-list] AVR assembly for fast bit bang, Nils Springob, 2005/11/09
- Re: [avr-gcc-list] AVR assembly for fast bit bang, David Brown, 2005/11/10
- Re: [avr-gcc-list] AVR assembly for fast bit bang, Mike S., 2005/11/16
- Re: [avr-gcc-list] AVR assembly for fast bit bang, Dave Hansen, 2005/11/09