[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Assembler Language Reference

Constants

The assembler language provides four kinds of constants:

When the assembler encounters an arithmetic or character constant being used as an instruction's operand, the value of that constant is assembled into the instruction. When the assembler encounters a symbol being used as a constant, the value of the symbol is assembled into the instruction.

Arithmetic Constants

The assembler language provides four kinds of arithmetic constants:

In 32-bit mode, the largest signed positive integer number that can be represented is the decimal value (2**31) - 1. The largest negative value is -(2**31). In 64-bit mode, the largest signed positive integer number that can be represented is (2**63)-1. The largest negative value is -(2**63). Regardless of the base (for example, decimal, hexadecimal, or octal), the assembler regards integers as 32-bit constants.

The interpretation of a constant is dependent upon the assembly mode. In 32-bit mode, the AIX assembler behaves in the same manner as earlier AIX versions: the assembler regards integers as 32-bit constants. In 64-bit mode, all constants are interpreted as 64-bit values. This may lead to results that differ from expectations. For example, in 32-bit mode, the hexadecimal value 0xFFFFFFFF is equivalent to the decimal value of "-1". In 64-bit mode, however, the decimal equivalent is 4294967295. To obtain the value "-1" the hexadecimal constant 0xFFFF_FFFF_FFFF_FFFF (or the octal equivalent), or the decimal value -1, should be used.

In both 32-bit and 64-bit mode, the result of integer expressions may be truncated if the size of the target storage area is too small to contain an expression result. (In this context, truncation refers to the removal of the excess most-significant bits.)

To improve readability of large constants, especially 64-bit values, the assembler will accept constants containing the underscore ("_") character. The underscore may appear anywhere within the number except the first numeric position. For example, consider the following table:

Constant Value Valid/Invalid?
1_800_500 Valid
0xFFFFFFFF_00000000 Valid
0b111010_00100_00101_00000000001000_00 Valid (this is the "ld 4,8(5)" instruction)
0x_FFFF Invalid

The third example shows a binary representation of an instruction where the underscore characters are used to delineate the various fields within the instruction. The last example contains a hexadecimal prefix, but the character immediately following is not a valid digit; the constant is therefore invalid.

Arithmetic Evaluation

In 32-bit mode, arithmetic evaluation takes place using 32-bit math. For the .llong pseudo-op, which is used to specify a 64-bit quantity, any evaluation required to initialize the value of the storage area uses 32-bit arithmetic.

For 64-bit mode, arithmetic evaluation uses 64-bit math. No sign extension occurs, even if a number might be considered negative in a 32-bit context. Negative numbers must be specified using decimal format, or (for example, in hexadecimal format) by using a full complement of hexadecimal digits (16 of them).

Decimal Constants

Base 10 is the default base for arithmetic constants. If you want to specify a decimal number, type the number in the appropriate place:

ai 5,4,10
# Add the decimal value 10 to the contents
# of GPR 4 and put the result in GPR 5.

Do not prefix decimal numbers with a 0. A leading zero indicates that the number is octal.

Octal Constants

To specify that a number is octal, prefix the number with a 0:

ai 5,4,0377
# Add the octal value 0377 to the contents
# of GPR 4 and put the result in GPR 5.

Hexadecimal Constants

To specify a hexadecimal number, prefix the number with 0X or 0x. You can use either uppercase or lowercase for the hexadecimal numerals A through F.

ai 5,4,0xF
# Add the hexadecimal value 0xF to the
# contents of GPR 4 and put the result
# in GPR 5.

Binary Constants

To specify a binary number, prefix the number with 0B or Ob.

ori 3,6,0b0010_0001
# OR (the decimal value) 33 with the
# contents of GPR 6 and put the result
# in GPR 3.

Floating-Point Constants

A floating-point constant has the following components in the specified order:

Integer Part Must be one or more digits.
Decimal Point . (period). Optional if no fractional part follows.
Fraction Part Must be one or more digits. The fraction part is optional.
Exponent Part Optional. Consists of an e or E, possibly followed by a + or -, followed by one or more digits.

For assembler input, you can omit the fraction part. For example, the following are valid floating-point constants:

Floating-point constants are allowed only where fcon expressions are found.

There is no bounds checking for the operand.

Note:In AIX 4.3 and later, the assembler uses the strtold subroutine to perform the conversion to floating point. Check current documentation for restrictions and return values.

Character Constants

To specify an ASCII character constant, prefix the constant with a ' (single quotation mark). Character constants can appear anywhere an arithmetic constant is allowed, but you can only specify one character constant at a time. For example 'A represents the ASCII code for the character A.

Character constants are convenient when you want to use the code for a particular character as a constant, for example:

cal 3,'X(0)
# Loads GPR 3 with the ASCII code for
# the character X (that is, 0x58).
# After the cal instruction executes, GPR 3 will
# contain binary
# 0x0000 0000 0000 0000 0000 0000 0101 1000.

Symbolic Constants

A symbol can be used as a constant by giving the symbol a value. The value can then be referred to by the symbol name, instead of by using the value itself.

Using a symbol as a constant is convenient if a value occurs frequently in a program. Define the symbolic constant once by giving the value a name. To change its value, simply change the definition (not every reference to it) in the program. The changed file must be reassembled before the new symbol constant is valid.

A symbolic constant can be defined by using it as a label or by using it in a .set statement.

String Constants

String constants differ from other types of constants in that they can be used only as operands to certain pseudo-ops, such as the .rename, .byte, or .string pseudo-ops.

The syntax of string constants consists of any number of characters enclosed in "" (double quotation marks):

"any number of characters"

To use a " in a string constant, use double quotation marks twice. For example:

"a double quote character is specified like this "" "

Related Information

Character Set

Reserved Words

Line Format

Statements

Symbols

Operators

Expressions

The atof subroutine.

.comm Pseudo-op, .csect Pseudo-op, .double Pseudo-op, .dsect Pseudo-op, .float Pseudo-op, .lcomm Pseudo-op, .tc Pseudo-op, .toc Pseudo-op, .tocof Pseudo-op.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]