The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: TNick on February 13, 2007, 10:33:12 AM

Title: Label offset
Post by: TNick on February 13, 2007, 10:33:12 AM
Hello, all!

I think this is the right place for this problem...

I want to store in .DATA section an offset to a label within a function like this:

.DATA
  L1Addr    DWORD   x
  L2Addr    DWORD   y

.CODE
MyFunction    PROC    Param1:DWORD, Param2:DWORD

Label1:
   mov  eax, 1

Label2:
   mov  ecx, 1

et
MyFunction ENDP

where x = OFFSET Label1 and y = OFFSET Label2

I know I could make both labels public, but I don't want that. Also, disassambly is not an efficient solution, because every time I would change my function I would have to find it again. :eek

Is there any other way? :'(

Thanks
Nick
Title: Re: Label offset
Post by: hutch-- on February 13, 2007, 10:54:34 AM
Nick,

try something like this.


MyFunc proc args etc ....

    .data
      plbl1 dd label1
      plbl2 dd label2
    .code

    ; your code

  label1:

    ; more code

  label2:

    ret

MyFunc endp
Title: Re: Label offset
Post by: TNick on February 13, 2007, 11:13:29 AM
Whohohoooo! Thanks hutch!!! That works perfectly!!
Title: Re: Label offset
Post by: drizz on February 13, 2007, 12:11:28 PM
:: makes label global


.DATA
  L1Addr    DWORD   offset Label1
  L2Addr    DWORD   offset Label2

.CODE
MyFunction    PROC    Param1:DWORD, Param2:DWORD

Label1::
   mov  eax, L1Addr

Label2::
   mov  ecx, L2Addr

   ret
MyFunction ENDP
Title: Re: Label offset
Post by: TNick on February 14, 2007, 08:30:27 AM
Yes, thanks, drizz, but that's exactly what I don't want: a global label ... :)

Regards,
Nick
Title: Re: Label offset
Post by: drizz on February 14, 2007, 11:38:06 AM
ooops i didn't see that hutchs code was surounded by a procĀ (overlookded proc/endp lines) :red