Using Immediate Operands

For an immediate operand, you can use an integer or enum constant, sizeof expression, and any constant expression using any of the C dyadic and monadic arithmetic operators.

These expressions follow the same precedence and associativity rules as normal C expressions. The inline assembler carries out all arithmetic with 32-bit signed integers.

An immediate operand can also be a reference to a member of a struct or class type. You can use any struct or class name from a typedef statement, followed by any number of member references. This evaluates to the offset of the member from the start of the struct. For example:

  lwz   r4,Rect.top(r3) 
  addi  r6,r6,Rect.left
   

As a side note, la rD,d(rA) is the same as addi rD,rA,d .

You also can use the top or bottom half-word of an immediate word value as an immediate operand by using one of the @ modifiers ( Example of referring to immediate operands).

Listing 1. Example of referring to immediate operands
long gTheLong;
asm void red(void)
{
  fralloc
  lis r6, gTheLong@ha
  addi r6, r6, gTheLong@h
  lis r7, gTheLong@h
  ori r7, br7, gTheLong@l
  frfree
  blr
}

The access patterns are:

  lis x,var@ha 
  la  x,var@l(x)
   

or

  lis x,var@h 
  ori x,x,var@l
   

In this example, la is the simplified form of addi to load an address. The instruction las is similar to la but shifted. Refer to the Freescale Power Architecture manuals for more information.

Using @ha is preferred since you can write:

  lis x,var@ha 
  lwz v,var@l(x)
   

You cannot do this with @h because it requires that you use the ori instruction.