[Top][All Lists]

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

Re: [avr-gcc-list] gcc binary

From: Yura Galayda
Subject: Re: [avr-gcc-list] gcc binary
Date: Fri, 05 Mar 2004 19:42:19 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113 MultiZilla/

Yura Galayda wrote:

      Or try can another version code:

#define BIN__N(x) (x) | x>>3 | x>>6 | x>>9
#define BIN__B(x) (x) & 0xf | (x)>>12 & 0xf0

#define BIN8(v) (BIN__B(BIN__N(0x##v)))

      Why not use macros, for example:

#define BIN8(x) BIN___(0##x)

#define BIN___(x)                                        \
       (                                                \
       ((x / 01ul) % 010)*(2>>1) +                      \
       ((x / 010ul) % 010)*(2<<0) +                     \
       ((x / 0100ul) % 010)*(2<<1) +                    \
       ((x / 01000ul) % 010)*(2<<2) +                   \
       ((x / 010000ul) % 010)*(2<<3) +                  \
       ((x / 0100000ul) % 010)*(2<<4) +                 \
       ((x / 01000000ul) % 010)*(2<<5) +                \
       ((x / 010000000ul) % 010)*(2<<6)                 \

#define BIN16(x1,x2) \

#define BIN24(x1,x2,x3) \

#define BIN32(x1,x2,x3,x4) \

char  i1 = BIN8  (00101010);
short i2 = BIN16(10110110,11101110);
long  i3 = BIN24(10110111,00010111,01000110);
long i4 = BIN32(11101101,01101000,01010010,10111100);
Erik Christiansen wrote:

On Wed, Mar 03, 2004 at 08:20:57PM +0100, Joerg Wunsch wrote:
It seems to be quite common among µC C compilers.  Unlike the PORTB.0
notation where I don't see how this would ever fit at all into legal C
syntax, I can imagine that 0b is a perferctly legal vendor extension
for a compiler.

It's also perfectly legal for avr-as (OK, that's binutils, but gcc is
nothing without it):

ldi    r16,0b10111111

Overcoming the compiler deficiency seems attractive. Portability is a
bit of a worry, though. I wonder if the 'C' world could be educated, in

Just curious, I've once made a patch for GCC that implements it.  This
was merely intented to be a proof of concept.  Does anyone
incidentally know whether this feature might have already been
proposed (and perhaps put down) to the GCC folks?  If not, do people
feel I should submit that patch?

In case anyone is interested:


Interested enough to take a copy for future reference. (When this
first project is delivered, I'll take a look at the compiler. :)

Thanks Jörg.


avr-gcc-list mailing list

Yuri Galayda at EIC Vector R&D Department       address@hidden
Fax or VoiceMail                                +1 206 202 4455
PGP public key available

avr-gcc-list mailing list


reply via email to

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