Next: , Previous: , Up: Using the Assembler Preprocessor   [Contents][Index]


5.13.3 Defining Symbols

To define or redefine a symbol, use the ‘def’ directive:

name    def     value

This statement defines or redefines a symbol name to a value. A symbol name must start at the beginning of a line. A symbol value must not contain commas outside of string literals.

There are two possible scopes of a symbol: global and local. Defining a symbol outside of macros makes the symbol global. If a symbol is global one, a ‘def’ directive used for this symbol inside a macro redefines the global symbol to a new value.

Defining a symbol inside a macro makes the symbol local. Macro arguments are also local symbols. Local symbols are not visible outside of macros containing their definitions. If a symbol is local one, a ‘def’ directive used for this symbol inside a macro (containing the definition of this symbol) redefines the local symbol to a new value.

The assembler preprocessor replaces with a symbol value every occurrence of a symbol name as a token in the scope of this symbol (after its definition or redefinition). To concatenate the symbol value with adjacent tokens, prepend and/or append the characters ‘##’ to the symbol name token.

For example, the source text

st      def     01

        choice
        case    a##st##_00, l##st##_00
        case    a##st##_01, l##st##_01
        end     choice

        jmp     l##st##_02

preprocesses to the text

        choice
        case    a01_00, l01_00
        case    a01_01, l01_01
        end     choice

        jmp     l01_02

If a symbol value is not a (quoted) string literal, prepend the character ‘#’ to the symbol name token to convert the symbol value to a string literal. For example, the source text

id       def     5

s##id:   stt     #id

preprocesses to the text

s5:   stt     "5"

The value of a defined or redefined symbol can contain symbol names. After expanding those symbol names, the value of this symbol must reduce to either a string literal or other text without string literals, spaces, and commas.

The assembler preprocessor supports the predefined symbol ‘__UNIQUE__’ expanded to the next number from the sequence of natural numbers. You can use that symbol to generate unique location labels in macros.


Next: , Previous: , Up: Using the Assembler Preprocessor   [Contents][Index]