Page 151 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 151

128                    Chapter 5 Advanced Assemblers, Linkers, and Downloaders


                                Table 5.5. Macro Arguments












        Every time the programmer uses this macro, he or she writes

                  label     name     parameter,parameter,...,parameter
        where name is the name of the macro, which is placed in the operation field, to which
        an optional size . B, .W,or .L may be appended. The designation label at the
        beginning of the line is treated just like a label in front of a conventional assembly line.
            The parameters can be inserted into the body of the macro using the two-character
        symbols in Table 5.5. As an example, the macro
                              MOVE:    MACRO
                                       LDD       \1
                                       STD       \2
                                       ENDM
        will move the two bytes at parameter location \1 to parameter location \2, like the MOW
        instruction, but the macro is faster and shorter where the second parameter is a page-zero
        address. When used in the program, say as
                                       MOVE      Z+3,M                       (1)
        the two bytes at locations Z + 3, Z + 4 will be moved to locations M, M + 1. In this
        example, all the usual rules for choosing between direct and page-zero addressing would
        apply. Additionally, if the actual parameters involve an index mode of addressing that
        uses a comma, the actual parameters must be enclosed within parentheses as in MOVE
         ( 3, X) , Y for the sequence
                                       LDD       3, X
                                       STD       Y

        As implied in the example above, when a macro is used, the actual parameters are
        inserted in a one-to-one correspondence with the order in (1).
             If "goto" labels are to be used within macros, then, because the macro may be used
        more than once during the program, assembler-generated labels must be used. The
        symbol character pair "\@" means an underbar followed by the macro invocation number,
        which is initially zero and is incremented each time a macro is called. When the first
        macro is expanded \@ generates the label _00000, when the second macro is expanded,
        \@ generates _00001, and so on. Throughout the first macro, \@ generates _00000 even
        though this macro may call another macro expansion, whenever it is used, before or after
        other macros are called and expanded. This generated symbol can be concatenated to other
   146   147   148   149   150   151   152   153   154   155   156