For instructions that take a memory operand (such as the lwz instruction), follow these rules when using a C-language variable as an operand:
Be declared/assigned with the register.
instrName regName , 0(globalVarName )
or
instrName regName , 0(parameterName )
Using C Variables with Instructions that Take a Memory Operand shows inline assembly language statements that correctly use C-language variables as operands in instructions that take a memory operand.
int my_global asm("r14")= 25; /* global variable */
int my_loc = 1; /* my_loc is on memory, not in a register */
asm void red(register int *my_param)
{
lwz r4, 0(my_global) /* line 9 */
lwz r4, 0(my_param) /* line 10 */
lwz r4, my_loc /* line 11 */
lwz r4, my_loc(SP)
blr
}
In Using C Variables with Instructions that Take a Memory Operand:
The CodeWarrior inline assembler automatically adds the contents of the SP register to local variable my_loc .
Note that statements 11 and 12 are equivalent.
As mentioned above, the inline assembler automatically adds the SP register to local variable my_loc , so explicitly including (SP) is redundant.