The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: James Ladd on August 28, 2005, 02:43:32 AM

Title: Address of a label ...
Post by: James Ladd on August 28, 2005, 02:43:32 AM
I have a routine with several labels in it.
Is it possible to get the address of a label ?
Can you give an example as well.

Rgs, striker.
Title: Re: Address of a label ...
Post by: ThoughtCriminal on August 28, 2005, 03:17:24 AM
This should work:

mov eax,offset label

My best guess without more details.
Title: Re: Address of a label ...
Post by: hutch-- on August 28, 2005, 03:44:40 AM
James,

There is a good technique in MASM if you want to hit those labels quickly, make a short table like this.


  table dd lbl1,lbl2,lbl3,lbl4 etc ....


This must match labels in you code and preferrably local in the procedure.



.data
table dd lbl1,lbl2,lbl3,lbl4 etc ....
.code

lbl1:

lbl2:

lbl3:

lbl4:


The assembler resolves the label names to addresses.

Not sure if this is what you are after but is cute anyway.
Title: Re: Address of a label ...
Post by: James Ladd on August 28, 2005, 06:34:39 AM
Thanks Hutch and TC,

I should have tried Offet before asking.
Dang, addr vs offset.
Title: Re: Address of a label ...
Post by: UPucker on August 28, 2005, 07:41:43 AM
Excellent. I have been looking for an easy way to make jump tables.

Title: Re: Address of a label ...
Post by: James Ladd on August 29, 2005, 08:36:35 AM
Hutch,

Do you have a way of this working outside of a local routine ???

Rgs, Striker.
Title: Re: Address of a label ...
Post by: hutch-- on August 29, 2005, 09:01:09 AM
Yes,

Make each label GLOBAL with the notation,


lbl1::

lbl2::

etc ....


The only catch with doing this is the labels must be unique for the entire module where if you use them in LOCAL scope with the table inboard, you don't.
Title: Re: Address of a label ...
Post by: James Ladd on August 29, 2005, 08:50:07 PM
Hutch,

Thanks that worked !    :bg

Rgs, striker.