Alchemy AU1550 board: establish endianness

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

Reply to
Roman Mashak
Loading thread data ...

"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 */;

Reply to
Fred Viles

BOO. Beware of optimizer. :-)

--
Michael N. Moran           (h) 770 516 7918
5009 Old Field Ct.         (c) 678 521 5460
 Click to see the full signature
Reply to
Michael N. Moran

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

Reply to
H. Peter Anvin

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.