This section describes the lexical features of the assembler syntax.
Uppercase and lowercase letters are distinct everywhere except in the names of special symbols. Special symbol names have no case distinction.
A comment is preceded by an exclamation mark character (!); the exclamation mark character and all following characters up to the end of the line are ignored. C language-style comments (``/*…*/'') are also permitted and can span multiple lines.
A label is either a symbol or a single decimal digit n (0...99). A label is immediately followed by a colon ( : ).
Numeric labels may be defined repeatedly in an assembly file; symbolic labels may be defined only once.
A numeric label n is referenced after its definition (backward reference) as nb, and before its definition (forward reference) as nf.
Decimal, hexadecimal, and octal numeric constants are recognized and are written as in the C language. However, integer suffixes (such as L) are not recognized.
For floating-point pseudo-operations, floating-point constants are written with 0r or 0R (where r or R means REAL) followed by a string acceptable to atof(); that is, an optional sign followed by a non-empty string of digits with optional decimal point and optional exponent.
The special names 0rnan and 0rinf represent the special floating-point values Not-A-Number (NaN) and INFinity. Negative Not-A-Number and Negative INFinity are specified as 0r-nan and 0r-inf.
A string is a sequence of characters quoted with either double-quote mark (") or single-quote mark (') characters. The sequence must not include a newline character. When used in an expression, the numeric value of a string is the numeric value of the ASCII representation of its first character.
The suggested style is to use single quote mark characters for the ASCII value of a single character, and double quote mark characters for quoted-string operands such as used by pseudo-ops. An example of assembly code in the suggested style is:
add %g1,'a'-'A',%g1 ! g1 + ('a' - 'A') --> g1
The following escape codes, derived from ANSI C, are recognized in strings.
Alert
Backspace
Form feed
Newline (line feed)
Carriage return
Horizontal tab
Vertical tab
Octal value nnn
Hexadecimal value nn...
The syntax for a symbol name is:
{ letter | _ | $ | . } { letter | _ | $ | . | digit }*
In the preceding syntax:
Uppercase and lowercase letters are distinct; the underscore ( _ ), dollar sign ($), and dot ( . ) are treated as alphabetic characters.
Symbol names that begin with a dot ( . ) are assumed to be local symbols. To simplify debugging, avoid using this type of symbol name in hand-coded assembly language routines.
The symbol dot ( . ) is predefined and always refers to the address of the beginning of the current assembly language statement.
External variable names beginning with the underscore character are reserved by the ANSI C Standard. Do not begin these names with the underscore; otherwise, the program will not conform to ANSI C and unpredictable behavior may result.
Special symbol names begin with a percentage sign (%) to avoid conflict with user symbols. Figure 1, Table 1, Special Symbol Names lists these special symbol names.
|
There is no case distinction in special symbols. For example, %PSR is equivalent to %psr.
The suggested style is to use lowercase letters.
The lack of case distinction allows for the use of non-recursive preprocessor substitutions, for example:
#define psr %PSR
The special symbols %hi and %lo are true unary operators which can be used in any expression and, as other unary operators, have higher precedence than binary operations. For example:
%hi a+b = (%hi a)+b %lo a+b = (%lo a)+b
To avoid ambiguity, enclose operands of the %hi or %lo operators in parentheses. For example:
%hi(a) + b
Attributes, in the form #attribute, can be used to modify certain pseudo-operations and instructions. Pseudo-ops .global, .section, .register, and .type accept specific attributes that correspond to linker attribute flags, as shown in Figure 10, Table 10, Pseudo-op Linker Attributes.
Several instructions, such as membar and prefetch, also accept attributes. See the instruction descriptions in Oracle SPARC Architecture 2011 for details on the attributes a given instruction supports.
The operators described in Figure 2, Table 2, Operators Recognized in Constant Expressions are recognized in constant expressions.
|
Since these operators have the same precedence as in the C language, put expressions in parentheses to avoid ambiguity.
To avoid confusion with register names or with the %hi, %lo, %r_disp32/64, or %r_plt32/64 operators, the modulo operator % must not be immediately followed by a letter or digit. The modulo operator is typically followed by a space or left parenthesis character.
The following SPARC V9 64-bit operators and expressions in Figure 3, Table 3, SPARC V9 64-bit Operators and Expressions ease the task of converting from V8/V8plus assembly code to V9 assembly code.
For example:
sethi %hh (address), %l1 or %l1, %hm (address), %l1
sethi %lm (address), %12 or %12, %lo (address), %12
sllx %l1, 32, %l1 or %l1, %12, %l1
The SPARC V9 high 32-bit operators and expressions are identified in Figure 4, Table 4, SPARC V9 32-Bit Operators and Expressions.
|
For example:
%sethi %hix (address), %l1 or %l1, %lox (address), %l1
The SPARC V9 low 44-bit operators and expressions are identified in Figure 5, Table 5, SPARC V9 Low 44-Bit Operators and Expressions.
|
For example:
%sethi %h44 (address), %l1 or %l1, %m44 (address), %l1 sllx %l1, 12, %l1 or %l1, % l44 (address), %l1