Syntax

Syntax

Assembler Instruction Coding

Assembler instructions are coded using the structure described below. Comments can be omitted.

 [Operands] [Comments]

Example:
add     r0, r1, r2  // r0 = r1 + r2
mul     r3, c0, v0  // r3 = c0 + v0

Assembler instructions are coded using ASCII characters according to the rules described below.
Operation
For operation, specify an assembler instruction to execute. You cannot code multiple operations on the same line.


Operands
Operand name [operand]
Specifies the operand names, such as registers and values, used in the operation. Enter at least one space or tab after the operation and before the operand name. If you are coding multiple operands, separate them with commas. You can also enter one or more spaces or tabs between operands.


Comment
Anything coded after a set of double slashes (" // ") is treated as comments. Any coding enclosed between "/*" and "*/" is also treated as comments.


Masking Output Components

When outputting calculation results to registers that have multiple components, you can specify which components to output.
Only the values for the specified components will be updated. If nothing has been specified, all components will be updated.
Specify components this order: x, y, z, w. (You cannot specify them in other orders, such as "wzyx".)

Examples:

add     r0.x,  r1, r2   // The x component is updated. The yzw components are not updated.
mov     r0.yz, r1       // The yz components are updated. The xw components are not updated.
dp3     r0,    r1, r2   // All components (xyzw) are updated.

Swizzling (Rearranging Input Components)

If you are using a register that has multiple components as an input operand, you can rearrange (swizzle) the components used for computations.
If this is not specified, the components will be used in this order: x, y, z, w.

If fewer than four components are specified, the component specified last will be repeated.

Example:

add     r0, r1.xzyy, r2     // r0.x = r1.x + r2.x
                            // r0.y = r1.z + r2.y
                            // r0.z = r1.y + r2.z
                            // r0.w = r1.y + r2.w
mov     r0, r1.ywz          // r0.x = r1.y
                            // r0.y = r1.w
                            // r0.z = r1.z
                            // r0.w = r1.z ; The last specified component (z) is repeated
add     r0, r1.zw, r2.xy    // r0.x = r1.z + r2.x
                            // r0.y = r1.w + r2.y
                            // r0.z = r1.w + r2.y
                            // r0.w = r1.w + r2.y

Note that if input components are swizzled, the parsing of masking for the output components will differ if fewer than four components have been specified.
The x, y, z, and w components specified for masking of output components will be applied respectively to the 1st, 2nd, 3rd, and 4th input components after swizzling has been performed.

Example:
mov     r0.x, r1.xy         // r0.x = r1.x ; (r1.xyyy)
mov     r0.y, r1.xy         // r0.y = r1.y ; (r1.xyyy)
mov     r0.z, r1.xy         // r0.z = r1.y ; (r1.xyyy)
mov     r0.w, r1.xy         // r0.w = r1.y ; (r1.xyyy)
add     r0.zw, r1.yx, r2.wz // r0.z = r1.x + r2.z;(r1.yxxx + r2.wzzz)
                            // r0.w = r1.x + r2.z;(r1.yxxx + r2.wzzz)
In the above examples, the red-colored input components are used for the output components.

Adding the Negative Sign ( - ) to Input Components

You can attach the negative sign ( - ) to input operands.

Example:

add     r0,  r1, -r2    // r0 = r1 – r2
mul     r0, –r1,  r2    // r0 = (–r1) * r2

Offsetting the Input Operand Register Index

You can offset input operand register numbers by enclosing them in square brackets ("[ ]").
A sum of multiple integers can be enclosed in brackets. If the offset integer sum exceeds the number of registers, an error will occur when assembling.

You can offset floating-point constant registers only, or address registers as well as loop-counter registers.
For address registers, you need to specify either the x component or the y component.
Behavior is undefined if the total combined index offset of the address registers and loop counter registers is outside the range of [0, 95].

Example:

c2              // Index is 2
v[5 + 2]        // Index is 5 + 2
r8[1 + 2 + 4]   //  Index is 8 + 1 + 2 + 4
c[3 + a0.x]     // Index is 3 + a0.x
c4[11 + aL]     // Index is 4 + 11 + aL

Labels

Labels can specify jumps to call instructions and jpb instructions.

Labels take the form of names comprising a combination of ASCII alphanumeric characters and underscores ("_") followed by a colon.
You cannot use reserved words (like the register names r0, c0) nor names that represent numbers (either decimal or hexadecimal, such as 123 or 0xf).
Lines that contain code labels cannot contain anything other than comments.

Example:

function0:
    mov r0, r1
    ...
    ret

main:
    ...
    call    function0

The main Label

The vertex shader invariably starts from a main label.
Shaders that do not have the main label are referenced as subroutines.
When the assembler file for the vertex shader is being assembled and linked, you must link a main object that contains at least one main label. An endmain label must also be set in this main object.

Set the endmain label immediately after the final executed instruction. (The final executed instruction is the instruction that gets written to the output register last.)

Label Name Conflicts

You cannot use the same label name more than once in an object file. Also, if you link multiple object files, you cannot use the same label name in multiple object files for subroutines.
Main objects do not reference each other, so it is all right to use the same label name in multiple main objects.

Reserved Words

The following strings are defined as reserved words by the assembler. Do not use these reserved words for such things as label names and symbol names.


・Register names

v0-v15, r0-r15, c0-c95, a0, b0-b15, i0-i3, aL, o0-o15

・Assembler instructions
def, defb, defi,
add, dp3, dp4, dph, dst, exp, flr, litp, log, mad, max, min, mov, mova, mul, nop, rcp, rsq, sge, slt,
sub, abs, crs, frc, lrp, m3x2, m3x3, m3x4, m4x3, m4x4, nrm, pow, sgn, sincos,
call, callc, callb, jpb, jpc, ret, ifb, ifc, else, endif, loop, endloop, breakc, cmp, end

・Pre-processor
include, define, undef, ifdef, ifndef, if, defined, else, elif, endif, error, pragma, bind_symbol, output_map

Revision History

2011/12/20
Initial version.

CONFIDENTIAL