An expression is assigned to a symbol by an assignment statement in one of the following general forms:
symbol =[:] expr
symbol .equ expr
.set symbol, expr
The expression specifies any addressing mode, which is generated when the symbol becomes an instruction operand. An assignment by = defines a local constant, and an assignment by =: additionally specifies that the symbol is global.
a = 1 # a local constant
xyz =: 123 # a global constant
Both .equ and .set work similarly to =, with the difference that .equ only allows you to assign an expression to a symbol once while .set allows you to reassign to the same symbol multiple times.
.set 7 stack # set stack to be 7 (legal)
.set 8 stack # reset stack to be 8 (legal)
chair .equ 9 # set chair to be 9 (legal)
sofa .equ 8 # set sofa to be 8 (legal)
chair .equ 5 # try to set chair to be 5 (illegal)
An expression is either absolute or relocatable. See "Expression Types" for more information about absolute or relocatable expressions.
A number of operators are available to form expressions. The operators are listed below. The type unary indicates that the function is recognized when the operator has only a right operand; binary indicates that the operator has two operands, one to the left of the operator and one to the right.
The following table lists the operators in decreasing order of precedence.The binary operators are associative from left to right
Operators |
---|
~ and - (unary) |
*, /, %, <<, >>, USHR, ROTR, and ROTL |
+ and - (binary) |
=, .equ, ==, !=, <, >, <=., >=, ULT, UGT, ULE, and UGE |
& |
| and ^ |
Expressions are grouped with matching square brackets [ ].
The primary expression types are:
If the value of an identifier or expression is computed by the Macro Assembler when encountered, it is a manifest value.
If the value of an identifier or expression is computed by the Macro Assembler during assembly, it is absolute. Essentially, any absolute value is a manifest value with the exception of an absolute value derived from the difference between two relocatable values in the same section.
A C-style character string delimited by double quotes is used in conjunction with a number of Macro Assembler directives. All string "escape" sequences defined in the C language, such as \n for newline, are allowed. These sequences are described in "Character Escape Sequences".
A relocatable expression or identifier assigns a value relative to the beginning of a particular section. These values are not determined at assembly time. All label identifiers are relocatable values.
If an identifier is unassigned, its value cannot be determined until link time. This is an undefined external.
The constant types are combined with all operators, except where a relocatable type was made immediate or absolute. Constant types and relocatable types are combined only by the following:
+ If one operand is constant, the result is the type of the other operand.
- If the second operand is constant, the result is the type of the other. If both operands are selected from the same one of the types text, data, or bss relocatable, then the result is a constant which is the difference of the addresses.
4 # constant
4 * (5 + 6) # constant
label # relocatable