Expressions

Assignment Statements

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.

For example:

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.

For example:

.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.

Scalar Expression Operators

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.
Operator Type Description
~
unary
BITWISE NOT operator
-
unary
Negation
-
binary
Subtraction
+
binary
Addition
*
binary
Multiplication
/
binary
Division
%
binary
Modulus
&
binary
BITWISE AND operator
^
binary
BITWISE EXCLUSIVE OR operator
|
binary
BITWISE OR operator
=,==
binary
Equality (0 or 1)
!=
binary
Inequality (0 or 1)
>,>=,<,<=
binary
Signed compares (0 or 1); greater than, greater than or equal, less than, less than or equal
UGT, UGE, ULT, ULE
binary
Unsigned compares (0 or 1); greater than, greater than or equal, less than, less than or equal
<<,>>
binary
Shift left and shift right
USHR
binary
Unsigned shift right (shift 0 into high bit)
ROTR, ROTL
binary
Rotate right and rotate left

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 [ ].

Expression Types

The primary expression types are:

manifest

If the value of an identifier or expression is computed by the Macro Assembler when encountered, it is a manifest value.

absolute

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.

quoted string

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".

relocatable

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.

undefined

If an identifier is unassigned, its value cannot be determined until link time. This is an undefined external.

Type Combinations

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.

Examples:

4 # constant
4 * (5 + 6) # constant
label # relocatable

Previous

Next



Copyright © 1999, Green Hills Software. All rights reserved.