This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I've used the intrinsic __swap_bytes(x) to do big to little endian data conversion.
I came to the conclusion that __swap_bytes(x) only works correctly when x is word aligned.
This intrinsic is essential the assembler command "swpb x", the generated code is shown below:
9898: 2e 4d mov @r13, r14 ; 989a: 8e 10 swpb r14 ; 989c: 8d 4e 00 00 mov r14, 0(r13) ;
The problem stems from the fact that 'mov @r13, r14' seems to only be able to do word transfers, at least that's what happens when this command is executed by the CPU.
GCC (msp430-14r1-167) does not seem to be able to take this into account and work around this alignment problem.
George Mock, could you possibly comment on that?
friedl said:I came to the conclusion that __swap_bytes(x) only works correctly when x is word aligned.
Yes. The __swap_bytes built-in expects and returns an unsigned short. The unsigned short type requires an alignment of 2-bytes (16-bits). I cannot think of a way to pass an unaligned address to __swap_bytes without violating the C standard. The TI compiler handles all of this the same way.
Thanks and regards,
-George