1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

Alchemy AU1550 board: establish endianness

Discussion in 'Embedded' started by Roman Mashak, Sep 20, 2004.

  1. Roman Mashak

    Roman Mashak Guest

    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:
     
    Roman Mashak, Sep 20, 2004
    #1
    1. Advertisements

  2. Roman Mashak

    Fred Viles Guest

    one generic way (assuming sizeof(int)>sizeof(char)):

    int i=1;
    if (*(char *)&i)
    /* little endian */;
     
    Fred Viles, Sep 21, 2004
    #2
    1. Advertisements

  3. 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
     
    Michael N. Moran, Sep 22, 2004
    #3
  4. Followup to: <8m34d.186242$%>
    By author:
    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
     
    H. Peter Anvin, Sep 23, 2004
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.