@LiveForIt
Quote:
LiveForIt wrote:
asm(
" lwz 3,0(%1) \t\n"
" li 4,0 \t\n"
" stwbrx 3,4,%0"
:: "r" (&output), "r" (&input) );
r0 can never be used as an address, it will always be 0 when used in such a way.
To ensure that a register is taken that works as a memory address, use the "b" constraint. Also, for memory references themselves (as in the lwz), you can use use "m".
Finaly, stwbrx is defined as
stwbrx rs, ra, rb
and the effective address is (ra|0)+(rb), so the code can be compressed llike this (since r0 is automatically used as constant 0, no need to load an additional register with it):
asm(
" lwz 3,%1\t\n"
" stwbrx 3,0,%0"
:: "b" (&output), "m" (input) : "3" );
Note that this also adds r3 to the globbered registers, meaning that their value is undefined after the asm statement (otherwise, the compiler might assume that r3 wasn't change, which it was).
You might want to check if this works better for you.