## ALP Programming Guide and Reference

[prev][next][parent][TOC]

### Macro Expansion

To expand the macro, the macro Name (defined in the Name field of the MACRO definition statement) is coded as you would any other assembler directive, followed by the list of arguments (if any) that you want to pass to the macro.

Syntax

    Name   [ Argument   [ ,   Argument   . . . ] ]

Remarks

The Name field must be the name of a macro defined previously with a MACRO directive.

Each Argument field denotes a text value that you want to pass to the macro . The relative positions of the elements are important, because each Argument is associated in left-to-right fashion with the corresponding Parameter as defined in the Parameter-List during the macro definition.

The number of Argument entries given when the macro is invoked need not be the same as the number of Parameter entries. If you pass extra Arguments to the macro, they are ignored; if too few are supplied, empty text values are associated with the remaining Parameters. You may also associate an empty text value with a Parameter by passing an explicitly empty text literal <> as an Argument.

Commas are normally used to separate arguments, although blanks or tabs are also considered to be argument separators. For this reason, any argument that must contain an argument separator character (commas, blanks, or tabs) should be enclosed in angle brackets <>. For example:

    PUSHVEC     MACRO   PARM1 , PARM2
               MOV     AX , PARM1
               PUSH    AX
               MOV     AX , PARM2
               PUSH    AX
               ENDM
               .
               .
               .
               PUSHVEC   DS , < OFFSET   VARNAME >
    ; PUSH   DWORD   VECTOR   OF   VARNAME   ONTO   STACK

You can also use angle brackets to produce variable lengths of results. For example:

    STRING     MACRO     NUMBERS
              DB        NUMBERS
              ENDM
                  .
                  .
                  .
              STRING   < 1 , 2 , 3 , 4 >
              ; PRODUCE   4   BYTES   OF   INTEGER   NUMBERS

Remarks

Each time a macro is invoked (expanded) by specifying its name, the preprocessor emits the statements contained in the body of the macro and passes them to the assembler for processing. During the expansion process, any replacement parameters encountered in the macro body (as named in the Parameter-List of the macro definition) are replaced with the corresponding Argument (if any) passed through the argument-list at the time the macro was invoked.

Example

    GEN     MACRO     XX , YY , ZZ
           MOV     AX , XX
           ADD     AX , YY
           MOV     ZZ , AX
           ENDM

When the call is made, for example:

    GEN     ED , KISER , SUM

The assembler produces the following code:

    MOV     AX , ED
    ADD     AX , KISER
    MOV     SUM , AX