Using Variable Names as Memory Locations

Whenever an instruction, such as a load instruction, a store instruction, or la , requires a memory location, you can use a local or global variable name. You can modify local variable names with struct member references, class member references, array subscripts, or constant displacements. For example, all the local variable references in Example of referring to variables stored in memory locations are valid.

Listing 1. Example of referring to variables stored in memory locations
asm void red(void){
  long myVar;
  long myArray[1];
  Rect myRectArray[3];
  fralloc
  lwz r3,myVar(SP)
  la  r3,myVar(SP)
  lwz r3,myRect.top
  lwz r3,myArray[2](SP)
  lwz r3,myRectArray[2].top
  lbz r3,myRectArray[2].top+1(SP)
  frfree
  blr
}

You can also use a register variable that is a pointer to a struct or class to access a member of the object, shown in Example of referring to a struct or class member.

Listing 2. Example of referring to a struct or class member
void red(void){
  Rect q;
  register Rect *p = &q;
  asm {
  lwz r3,p->top;
  }
}

You can use the @hiword and @loword directives to access the high and low four bytes of 8 byte long longs and software floating-point doubles ( Example of referring to high and low words).

Listing 3. Example of referring to high and low words
long long gTheLongLong = 5;
asm void Red(void);
asm void Red(void)
{
  fralloc
  lwz r5, gTheLongLong@hiword
  lwz r6, gTheLongLong@loword
  frfree
  blr
}