Generating Unique Labels in HLI Assembler Macros

Invoking the same m acro twice in the same function causes the ANSI C preprocessor to generate the same label twice (once in each macro expansion). Use the special string concatenation operator of the ANSI-C preprocessor ( ##) to generate unique labels. Refer the following listing.

Listing: Using the ANSI C Preprocessor String Concatenation Operator
/* The following macro copies the string pointed to by 'src'
   into the string pointed to by 'dest'.

   'src' and 'dest' must be valid arrays of characters.

   'inst' is the instance number of the macro call. This

   parameter must be different for each invocation of the

   macro to allow the generation of unique labels. */

#pragma NO_STRING_CONSTR 

#define copyMacro2(src, dest, inst) { \

  __asm           LOAD   @src,Reg0;  /* load src addr */ \

  __asm           LOAD   @dest,Reg1; /* load dst addr */ \

  __asm           CLR    Reg2;        /* clear index reg */ \

  __asm lp##inst: LOADB  (Reg2, Reg0); /* load byte reg indir */  \

  __asm           STOREB (Reg2, Reg1); /* store byte reg indir */ \

  __asm           ADD    #1,Reg2; /* increment index register */   \

  __asm           TST    Reg2;     /* test if not zero */           \

  __asm           BNE    lp##inst; }

Invoking the copyMacro2 macro in the source code:

  copyMacro2(source2, destination2, 1);

  copyMacro2(source2, destination3, 2);

During expansion of the first macro, the preprocessor generates an lp1 label. During expansion of the second macro the preprocessor creates an lp2 label.