Alchemy AU1550 board: establish endianness

Sep 20, 2004 3 Replies

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: snipped-for-privacy@tusur.ru


"Roman Mashak" wrote in news:cimifa$2cik$ snipped-for-privacy@mpeks.tomsk.su:

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
formatting link

"... 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: By author: snipped-for-privacy@mnmoran.org In newsgroup: comp.arch.embedded

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

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required