Forums

Alchemy AU1550 board: establish endianness

Started by Roman Mashak September 20, 2004
Hello, All!

Could you please explain me the process of establishing the endianness on
Alchemy board? This board has the DIP switches for establish endian mode,
and I'd like to understand how to determine the endianness from software.

On-board CPU is MIPS32.

With best regards, Roman Mashak.  E-mail: mrv@tusur.ru


"Roman Mashak" <mrv@tusur.ru> wrote in
news:cimifa$2cik$1@mpeks.tomsk.su: 

>... > I'd like to understand how to > determine the endianness from software.
one generic way (assuming sizeof(int)>sizeof(char)): int i=1; if (*(char *)&i) /* little endian */;
Fred Viles wrote:
> "Roman Mashak" <mrv@tusur.ru> wrote in >>I'd like to understand how to >>determine the endianness from software. > > > one generic way (assuming sizeof(int)>sizeof(char)): > > int i=1; > if (*(char *)&i) > /* little endian */;
BOO. Beware of optimizer. :-) -- Michael N. Moran (h) 770 516 7918 5009 Old Field Ct. (c) 678 521 5460 Kennesaw, GA, USA 30144 http://mnmoran.org "... abstractions save us time working, but they don't save us time learning." Joel Spolsky, The Law of Leaky Abstractions The Beatles were wrong: 1 & 1 & 1 is 1
Followup to:  <8m34d.186242$%n4.110639@bignews6.bellsouth.net>
By author:    mike@mnmoran.org
In newsgroup: comp.arch.embedded
> > Fred Viles wrote: > > "Roman Mashak" <mrv@tusur.ru> wrote in > >>I'd like to understand how to > >>determine the endianness from software. > > > > > > one generic way (assuming sizeof(int)>sizeof(char)): > > > > int i=1; > > if (*(char *)&i) > > /* little endian */; > > BOO. > Beware of optimizer. :-) >
If the optimizer optimizes that out, then the optimizer is broken. However, try: static volatile uint16_t i = 0x0102; volatile uint8_t *p = (volatile uint8_t *)&i; switch ( *p ) { case 1: /* bigendian */ break; case 2: /* littleendian */ break; default: /* wtf */ break; } If the optimizer optimizes *THAT* out then napalm your compiler vendor. -hpa