News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

labels in macros

Started by russian, December 31, 2004, 09:49:46 PM

Previous topic - Next topic

russian

if you are to execute a certain macro many times the labels inside of it must obviously be different or it MASM will give a label redifinition error. Is there a way, aside from @@/@b/@f, to make labels inside of macros that will not be duplicated if you run the macro many times??


MichaelW

You declare the labels as LOCAL. See Defining Local Symbols in Macros here:

http://webster.cs.ucr.edu/Page_TechDocs/MASMDoc/ProgrammersGuide/Chap_09.htm

As a demonstration, if you attempt to compile this:

    .486                       ; create 32 bit code
    .model flat, stdcall       ; 32 bit memory model
    option casemap :none       ; case sensitive

    locals MACRO
        LOCAL lbl
      lbl:
      .err <lbl>
    ENDM

    .data
    .code
start:

    locals
    locals
    locals
    locals

end start


You will get this output:

Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: C:\masm32\My\MACRO\LOCALS.asm
C:\masm32\My\MACRO\LOCALS.asm(15) : error A2052: forced error : ??0000
locals(3): Macro Called From
  C:\masm32\My\MACRO\LOCALS.asm(15): Main Line Code
C:\masm32\My\MACRO\LOCALS.asm(16) : error A2052: forced error : ??0001
locals(3): Macro Called From
  C:\masm32\My\MACRO\LOCALS.asm(16): Main Line Code
C:\masm32\My\MACRO\LOCALS.asm(17) : error A2052: forced error : ??0002
locals(3): Macro Called From
  C:\masm32\My\MACRO\LOCALS.asm(17): Main Line Code
C:\masm32\My\MACRO\LOCALS.asm(18) : error A2052: forced error : ??0003
locals(3): Macro Called From
  C:\masm32\My\MACRO\LOCALS.asm(18): Main Line Code
_
Assembly Error
Press any key to continue . . .

Note the generated labels that start with "??0000".
eschew obfuscation

russian