The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: russian on December 31, 2004, 09:49:46 PM

Title: labels in macros
Post by: russian on December 31, 2004, 09:49:46 PM
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??
Title: Re: labels in macros
Post by: Kestrel on December 31, 2004, 10:08:45 PM
Local Labels
http://www2.ics.hawaii.edu/~pagerg/312/notes/15Macros/Index.html
Title: Re: labels in macros
Post by: MichaelW on December 31, 2004, 10:24:53 PM
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".
Title: Re: labels in macros
Post by: russian on January 01, 2005, 07:33:34 PM
thanks alot!