This section describes the basic building blocks of an assembly language program—these are characters, symbols, labels, and constants.
Characters
Identifiers
Labels
Constants
Assembly Location Counter
The following characters are used in assembly language programs:
Alphanumeric characters—A through Z, a through z, and 0 through 9
Other printable ASCII characters (such as #, $, :, ., +, -, *, /, !, and |)
Nonprinting ASCII characters (such as space, tab, return, and newline)
Some of these characters have special meanings, which are described in “Expression Syntax” and in “Assembly Language Statements.”
An identifier (also known as a symbol) can be used for several purposes:
As the label for an assembler statement (see “Labels”)
As a location tag for data
As the symbolic name of a constant
Each identifier consists of a sequence of alphanumeric characters (which may include other printable ASCII characters such as ., _, and $). The first character must not be numeric. Identifiers may be of any length, and all characters are significant. The case of letters is significant—for example, the identifier var is different from the identifier Var.
It is also possible to define an identifier by enclosing multiple identifiers within a pair of double quotation marks. For example:
"Object +new:": |
.long "Object +new:" |
A label is written as an identifier immediately followed by a colon (:). The label represents the current value of the current location counter; it can be used in assembler instructions as an operand.
Local numeric labels allow compilers and programmers to use names temporarily. A numeric label consists of a digit (between 0 and 9) followed by a colon. These 10 local symbol names can be reused any number of times throughout the program. As with alphanumeric labels, a numeric label assigns the current value of the location counter to the symbol.
Although multiple numeric labels with the same digit may be used within the same program, only the next definition and the most recent previous definition of a label can be referenced:
To refer to the most recent previous definition of a local numeric label, write digitb, (using the same digit as when you defined the label).
To refer to the next definition of a numeric label, write digitf.
The scope of a label is the distance over which it is visible to (and referenceable by) other parts of the program. Normally, a label that tags a location or data is visible only within the current assembly unit.
The .globl directive (described in “.globl”) may be used to make a label external. In this case, the symbol is visible to other assembly units at link time.
Four types of constants are available: Numeric, character, string, and floating point. All constants are interpreted as absolute quantities when they appear in an expression.
A numeric constant is a token that starts with a digit. Numeric constants can be decimal, hexadecimal, or octal. The following restrictions apply:
Decimal constants contain only digits between 0 and 9, and normally aren’t longer than 32 bits—having a value between -2,147,483,648 and 2,147,483,647 (values that don’t fit in 32 bits are bignums, which are legal but which should fit within the designated format). Decimal constants cannot contain leading zeros or commas.
Hexadecimal constants start with 0x (or 0X), followed by between one and eight decimal or hexadecimal digits (0 through 9, a through f, and A through F). Values that don’t fit in 32 bits are bignums.
Octal constants start with 0, followed by from one to eleven octal digits (0 through 7). Values that don’t fit in 32 bits are bignums.
A single-character constant consists of a single quotation mark (') followed by any ASCII character. The constant’s value is the code for the given character.
A string constant is a sequence of zero or more ASCII characters surrounded by quotation marks (for example, "a string").
The general lexical form of a floating-point number is:
0flt_char[{+–}]dec...[.][dec...][exp_char[{+–}][dec...]] |
where:
Item | Description |
|---|---|
flt_char | A required type specification character (see the following table). |
[{+-}] | The optional occurrence of either |
dec... | A required sequence of one or more decimal digits. |
[.] | A single optional period. |
[dec...] | An optional sequence of one or more decimal digits. |
[exp_char] | An optional exponent delimiter character (see the following table). |
The type specification character, flt_char, specifies the type and representation of the constructed number; the set of legal type specification characters with the processor architecture, as shown here:
Architecture | flt_char | exp_char |
|---|---|---|
ppc | {dDfF} | {eE} |
i386 | {fFdDxX} | {eE} |
When floating-point constants are used as arguments to the .single and .double directives, the type specification character isn’t actually used in determining the type of the number. For convenience, r or R can be used consistently to specify all types of floating-point numbers.
Collectively, all floating-point numbers, together with quad and octal scalars, are called bignums. When as requires a bignum, a 32-bit scalar quantity may also be used.
Floating-point constants are internally represented as flonums in a machine-independent, precision-independent floating-point format (for accurate cross-assembly).
A single period (.), usually referred to as “dot,” is used to represent the current location counter. There is no way to explicitly reference any other location counters besides the current location counter.
Even if it occurs in the operand field of a statement, dot refers to the address of the first byte of that statement; the value of dot isn’t updated until the next machine instruction or assembler directive.
Last updated: 2006-07-24