This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Efficient translate from 0x12345678 to 0x87654321

Dear all,
I met a problem due to big-endian of 8051. The phenomenon is as follows:

32-bit value A[4] is in XDATA space
Ex. offset 0 = 0x12; offset 1 = 0x34; offset 2 = 0x56; offset 3 = 0x78

I used the following to get this value:
*((UINT32 *) 0);

For 8051 we got "0x12345678" because of big-endian...

Is there any "efficient"(favor size) method to transform it to 0x87654321 ?

I tried to use: A[0]+A[1]<<8+A[2]<<16+A[3]<<24 but the "machine code" gets bigger...

Thanks !

Parents
  • "Compiler-generated code for this kind of thing may well not be inefficient at all..."

    The keyword there is surely may. Due to compiler versions, optimization levels etc, it cannot be guaranteed.

    Whereas, a little (and simple) piece of assembler would have fixed and predictable results.

    Heck, for this function, it would be a case of passing parameters in registers, shuffling around a bit and returning the result in registers.

    I sometimes think that the art of assembler is just fading away :(

Reply
  • "Compiler-generated code for this kind of thing may well not be inefficient at all..."

    The keyword there is surely may. Due to compiler versions, optimization levels etc, it cannot be guaranteed.

    Whereas, a little (and simple) piece of assembler would have fixed and predictable results.

    Heck, for this function, it would be a case of passing parameters in registers, shuffling around a bit and returning the result in registers.

    I sometimes think that the art of assembler is just fading away :(

Children
No data