I'm looking for the most efficient way (in terms of code size first, but speed is also an issue) of doing a little-endian to big-endian convertion on a DWORD. The commonly-used C macro: #define SWAP32(x) (((x) & 0xff) << 24 | ((x) & 0xff00) << 8 | ((x) & 0xff0000) >> 8 | ((x) >> 24) & 0xff) produces terrible code on the 8051. I'm looking for either a macro or a function that would perform the equivalent swap using the minimum number of instructions. The macro/function is called in lots of places in my code and code size has become an issue. Thanks! Ran Shalgi
How about
ByteSwap.h: extern U32 ByteSwapU32 (U32 val); -- ByteSwap.a51: PUBLIC _ByteSwapU32 _ByteSwapU32: MOV A, R7 XCH A, R4 MOV R7, A MOV A, R6 XCH A, R5 MOV R6, A RET