MEXIT - Terminate Macro Expansion

Syntax
MEXIT

Synonym

None

Description

MEXIT is usually used together with conditional assembly within a macro. In that case it may happen that the macro expansion should terminate prior to termination of the macro definition. The MEXIT directive causes macro expansion to skip any remaining source lines ahead of the ENDM - End macro definition directive.

Example

The code in the following listing allows the replication of simple instructions or directives using MACRO with MEXIT.

Listing: Example assembly code using MEXIT

         XDEF  entry
storage: EQU   $00FF

save:    MACRO           ; Start macro definition

         LDX   #storage

         LDA   \1

         STA   0,x       ; Save first argument

         LDA   \2

         STA   2,x       ; Save second argument

         IFC   '\3', ''  ; Is there a third argument?

           MEXIT         ; No, exit from macro

         ENDC

         LDA   \3        ; Save third argument

           STA   4,X

         ENDM            ; End of macro definition

datSec:  SECTION

char1:  ds.b  1

char2:  ds.b  1

codSec:  SECTION

entry:

         save  char1, char2

The following listing shows the macro expansion of the previous macro.

Listing: Macro Expansion

Abs. Rel.   Loc    Obj. code  Source line
---- ----   ------ ---------  -----------

   1    1                               XDEF  entry

   2    2          0000 00FF   storage: EQU   $00FF

   3    3

   4    4                      save:    MACRO ; Start macro definition

   5    5                               LDX   #storage

   6    6                               LDA   \1

   7    7                               STA   0,x ; Save first arg

   8    8                               LDA   \2

   9    9                               STA   2,x ; Save second arg

  10   10                               IFC   '\3', ''; is there a 

  11   11                               MEXIT ; No, exit from macro.

  12   12                               ENDC

  13   13                               LDA   \3 ; Save third argument

  14   14                               STA   4,X

  15   15                               ENDM     ; End of macro defin

  16   16

  17   17                       datSec:  SECTION

  18   18    000000             char1:  ds.b  1

  19   19    000001             char2:  ds.b  1

  20   20

  21   21

  22   22

  23   23                       codSec:  SECTION

  24   24                       entry:

  25   25                                save  char1, char2

  26    5m  000000 AEFF       +          LDX   #storage

  27    6m  000002 C6 xxxx    +          LDA   char1

  28    7m  000005 E700       +          STA   0,x  ; Save first arg

  29    8m  000007 C6 xxxx    +          LDA   char2

  30    9m  00000A E702       +          STA   2,x  ; Save second

  31   10m         0000 0001  +          IFC   '', ''  ; Is there a

  33   11m                    +          MEXIT      ; no, exit macro.

  34   12m                    +          ENDC

  35   13m                    +          LDA        ; Save third argu

  36   14m                    +          STA   4,X