[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] efficiency of assigning bits
From: |
David Brown |
Subject: |
Re: [avr-gcc-list] efficiency of assigning bits |
Date: |
Mon, 14 Mar 2005 13:07:36 +0100 |
>
> >
> > Hello,
> > To turn two bits off, the method I would adopt is
> >
> > PORTD &= 0B11101101;
> >
> > This is the fastest method.
>
> What does that work out to in assembly? A cbi/sbi assembly instruction is
2 clock cycles. I still don't understand why these instructions would be
taken out of winavr, they obviously are useful for them to have been
included as opcodes in the AVR! :)
>
> Is it possible to do inline assembly with cbi/sbi?
> Something like this:
>
> asm("sbi,x,y)"
>
> --gives an error though
>
> cheers,
> Jamie
>
It's tempting to reply with RTFM, but I'll elaborate a little (although you
should still read the documentation and FAQ).
Nobody has taken "instructions out of winavr". A few macros were removed
from the standard headers - these macros were non-standard, confusingly
named, useful only in the distant past when avr-gcc had limited
optomisation, and had been marked as pending removable for a long time
(several years, IIRC). Instead of incorrectly pretending that the C
compiler is an assembler, or that it needs assembler to access hardware, use
standard C bit manipulation operators:
PORTD &= ~PD1; PORTD &= ~PD4;
or
PORTD &= ~(PD1 | PD4);
The first method will be faster, since it compiles to two cbi instructions,
but it does not turn the bits off simultaneously. The second method gives
you simultaneous switch-off, but takes slightly longer.
If you want to know what assembly is generated, use the gcc flags to
generate a listing file (such as -Wa,-ahlsd=listing.txt ). If you want to
use in-line assembly (which is very seldom necessary, and certainly not
appropriate here), there is plenty of documentation in the avr-libc manual.
David
>
> >
> > The cbi and sbi instructions are removed in the latest
> > version of winavr and can not be used. Moreover the
> > two instructions take more time and more space
> > compared to the above example.
> >
> > Nayani
> >
> >
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > Make Yahoo! your home page
> > http://www.yahoo.com/r/hs
> >
>
>
>
> _______________________________________________
> AVR-GCC-list mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
>
- Re: [avr-gcc-list] efficiency of assigning bits, (continued)
- Re: [avr-gcc-list] efficiency of assigning bits, Parthasaradhi Nayani, 2005/03/13
- Re: [avr-gcc-list] efficiency of assigning bits, Jamie Morken, 2005/03/14
- Re: [avr-gcc-list] efficiency of assigning bits, E. Weddington, 2005/03/14
- Re: [avr-gcc-list] efficiency of assigning bits, E. Weddington, 2005/03/14
- Re: [avr-gcc-list] efficiency of assigning bits, E. Weddington, 2005/03/14
- Re: [avr-gcc-list] efficiency of assigning bits, Jamie Morken, 2005/03/17