Robert Dominicus-Schleutermann wrote:
static inline uint16_t endian16(uint16_t v)
{
asm("swpb %0" : "+g" (v));
return v;
}
The other case: you call a function with the
parameter "value" which gets copied for the
lifetime of the function endian16 and discarded
after finishing that funciton. So the modified
parameter "value" gets discarded with the return
to the caller and the old "value" is visible again.
I agree - the compiler removes unnessecary code here, but the reason is
the incomplete asm() instruction. The asm() instruction has 3 parts: the
instruction itself (here "swpb %0"), the destination of the operand
(here "+g" (v)) and the source(s). The sources have been omitted here.
asm("<instruction>" : <destination> : <sources>);
Therefore the compiler can't see a source and removes the statements.
Have a look at my definition of the macro for this problem in the other
mail. I have defined an additional assembler variable [opsrc] only for
this reason.
Ralf