The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: vid on July 10, 2007, 03:05:51 PM

Title: local labels not in procs, or leaf procs
Post by: vid on July 10, 2007, 03:05:51 PM
hi, i need to write set of procedures.

These procedures won't use EBP as stack frame pointer, but instead as normal register. They will take arguments only in registers, and won't have any local variables. But I need to have couple of local labels with same name in every procedure.

Is it possible to do this with PROC directive, so that it doesn't generate prologue/epilogue which changes EBP? Or is there some way to declare local label outside procedure?

thanks
Title: Re: local labels not in procs, or leaf procs
Post by: Tedd on July 10, 2007, 04:08:02 PM
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

fun1 proc
  label1:
    nop
  label2:
    ret
fun1 endp

fun2 proc
  label1:
    nop
  label2:
    ret
fun2 endp

OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef


The first set of OPTIONs turn off the stack-frame, and the last ones turn it back on - any procs in between will not have a stack-frame generated.
Title: Re: local labels not in procs, or leaf procs
Post by: vid on July 10, 2007, 04:17:55 PM
thanks, i will give it a try
Title: Re: local labels not in procs, or leaf procs
Post by: Ian_B on July 18, 2007, 08:31:00 PM
Quote from: vid on July 10, 2007, 03:05:51 PMBut I need to have couple of local labels with same name in every procedure.

This isn't affected by the Prologue/Epilogue options Tedd has explained. By default, there's no problem having duplicate labels in different procs, each procedure is "encapsulated".

However, if for some reason you want to be able to jump into a proc from elsewhere (perhaps to have a single error-handling "tail" common to a group of file-handling procedures, which is something I do a lot, although it's probably bad programming practise) then you need to enable this deliberately with Option Noscoped. That will prevent you from having duplicate labels anywhere in your program though, but as I said it is NOT enabled by default.
Title: Re: local labels not in procs, or leaf procs
Post by: MichaelW on July 18, 2007, 09:13:00 PM
To be clear, OPTION NOSCOPED affects all labels that follow the directive, up to the next OPTION SCOPED directive, if present. Any single label can be made accessible from outside a procedure by defining it with a double colon, as in "labelname::", but the name cannot then be duplicated anywhere in the source.
Title: Re: local labels not in procs, or leaf procs
Post by: Ian_B on July 20, 2007, 04:40:15 AM
Thanks for the clarification, Michael. That's all extra neat, especially the double-colon trick.  :thumbu