Referring to Variables in Memory

For instructions that take a memory operand (such as the lwz instruction), follow these rules when using a C-language variable as an operand:

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.

Listing 1. Using C Variables with 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: