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


5.14.3 Defining Symbols

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

name    def     value

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

There are two possible scopes of a symbol: global and local. Global symbols are those defined not within macros. If the ‘def’ directive within a macro is used for symbol name, which has been defined as a global one, then that global symbol will be redefined to a new value.

Local symbols are those defined within macros. Macro arguments are also got implicitly defined as local symbols. Local symbols are not visible outside of macros where they were defined. If the ‘def’ directive within a macro is used for symbol name, which has been defined as a local one, then that local symbol will be redefined to a new value.

If the name of a symbol occurs as a token in the text in the scope of that symbol, then that token will be replaced with a symbol value. If the symbol value has to be concatenated with adjacent tokens, then prepend and/or append characters ‘##’ to the symbol name token.

For example, 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

will be preprocessed to text

        choice
        case    a01_00, l01_00
        case    a01_01, l01_01
        end     choice

        jmp     l01_02

When a symbol value is a verbatim text, to convert the symbol value to a string literal, prepend the character ‘#’ to the symbol name token. For example, source text

id       def     5

s##id:   stt     #id

will be preprocessed to text

s5:   stt     "5"

Names of symbols may occur in a value to which a symbol is defined or redefined. After expanding those symbols, the value of the symbol must reduce either to verbatim text, which does not contain commas, or to a string literal.

The assembler preprocessor supports predefined symbol ‘__UNIQUE__’, which is expanded to verbatim text in the form of the next element from the sequence of natural numbers. That symbol can be used to generate unique location labels in macros.


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