Skip to main content

IAR Embedded Workbench for RL78 5.20

Expressions, operands, and operators

In this section:

Expressions consist of expression operands and operators.

The assembler accepts a wide range of expressions, including both arithmetic and logical operations. All operators use 64-bit two’s complement integers. Range checking is performed if a value is used for generating code.

Expressions are evaluated from left to right, unless this order is overridden by the priority of operators. See also Assembler operators.

These operands are valid in an expression:

  • Constants for data or addresses, excluding floating-point constants

  • Symbols—symbolic names—which can represent either data or addresses, where the latter also is referred to as labels

  • The program location counter (PLC), $ (dollar).

The operands are described in greater details on the following pages.

Note

You cannot have two symbols in one expression, or any other complex expression, unless the expression can be resolved at assembly time. If they are not resolved, the assembler generates an error.

Integer constants

The assembler uses 64-bit two’s complement internal arithmetic, so integers have a (signed) range from -263 to 263-1.

Constants are written as a sequence of digits with an optional preceding - (minus) sign in front to indicate a negative number.

Commas and decimal points are not permitted.

The following types of number representation are supported:

Integer type

Example

Binary

1010b, b'1010

Octal

1234q, q'1234

Decimal

1234, -1, d'1234

Hexadecimal

0FFFFh, 0xFFFF, h'FFFF

Table 114. Integer constant formats 


Note

Both the prefix and the suffix can be written with either uppercase or lowercase letters.

ASCII character constants

ASCII constants can consist of any number of characters enclosed in single or double quotes. Only printable characters and spaces can be used in ASCII strings. If the quote character itself will be accessed, two consecutive quotes must be used:

Format

Value

'ABCD'

ABCD (four characters)

"ABCD"

ABCD'\0' (five characters the last ASCII null)

'A''B'

A'B

'A'''

A'

'''' (4 quotes)

'

'' (2 quotes)

Empty string (no value)

"" (2 double quotes)

'\0' (an ASCII null character)

\'

', for quote within a string, as in 'I\'d love to'

\\

\, for \ within a string

\"

", for double quote within a string

Table 115. ASCII character constant formats 


Floating-point constants

The IAR Assembler accepts floating-point values as constants and converts them into IEEE single-precision (32-bit) or double-precision (64-bit) floating-point format, or fractional format.

Floating-point numbers can be written in the format:

[+|-][digits].[digits][{E|e}[+|-]digits]

This table shows valid examples:

Format

Value

10.23

1.023 x 101

1.23456E-24

1.23456 x 10-24

1.0E3

1.0 x 103

Table 116. Floating-point constants 


Spaces and tabs are not allowed in floating-point constants.

Note

Floating-point constants do not give meaningful results when used in expressions.

True and false

In expressions, a zero value is considered false, and a non-zero value is considered true.

Conditional expressions return the value 0 for false and 1 for true.

Symbols

User-defined symbols can be up to 255 characters long, and all characters are significant. Depending on what kind of operation a symbol is followed by, the symbol is either a data symbol or an address symbol where the latter is referred to as a label. A symbol before an instruction is a label and a symbol before, for example the EQU directive, is a data symbol. A symbol can be:

  • absolute—its value is known by the assembler

  • relocatable—its value is resolved at link time.

Symbols must begin with a letter, a–z or A–Z, ? (question mark), or _ (underscore). Symbols can include the digits 0–9 and $ (dollar).

Symbols may contain any printable characters if they are quoted with ` (backquote), for example:

`strange#label`

Case is insignificant for built-in symbols like instructions, registers, operators, and directives. For user-defined symbols, case is by default significant but can be turned on and off using the Case sensitive user symbols (‑‑case_insensitive) assembler option. For more information, see ‑‑case_insensitive.

Use the symbol control directives to control how symbols are shared between modules. For example, use the PUBLIC directive to make one or more symbols available to other modules. The EXTERN directive is used for importing an untyped external symbol.

Labels

Symbols used for memory locations are referred to as labels.

Program location counter (PLC)

The assembler keeps track of the start address of the current instruction. This is called the program location counter.

To refer to the program location counter in your assembler source code, use the $ (dollar) character. For example:

         BR     $        ; Loop forever

Absolute and relocatable expressions

Depending on what operands an expression consists of, the expression is either absolute or relocatable. Absolute expressions are those expressions that only contain absolute symbols or relocatable symbols that cancel each other out.

Expressions that include symbols in relocatable sections cannot be resolved at assembly time, because they depend on the location of sections. These are referred to as relocatable expressions.

Such expressions are evaluated and resolved at link time, by the linker. They can only be built up out of a maximum of one symbol reference and an offset after the assembler has reduced it.

For example, a program could define absolute and relocatable expressions as follows:

            name    simpleExpressions
            section MYCONST:CONST(2)
first       dc32    5                ; A relocatable label.
second      equ     10 + 5           ; An absolute expression.

            dc32    first            ; Examples of some legal
            dc32    first + 1        ; relocatable expressions.
            dc32    first + second
            end

Note

At assembly time, there is no range check. The range check occurs at link time and, if the values are too large, there is a linker error.