The MASM Forum Archive 2004 to 2012

Project Support Forums => MASM32 => Topic started by: Matt.J on January 15, 2011, 02:21:50 AM

Title: Defining an explicit address for a function
Post by: Matt.J on January 15, 2011, 02:21:50 AM
Hello,

Is it possible within MASM to define the placement (address) of a function? e.g, foo() to be located at RVA 0x12345
Title: Re: Defining an explicit address for a function
Post by: dedndave on January 15, 2011, 03:19:48 AM
that kind of stuff is kind of frowned on in here
Title: Re: Defining an explicit address for a function
Post by: clive on January 15, 2011, 03:25:33 AM
The first question would be why would you need that level of control?

In 32-bit code you could direct the linker to base the executable at a specific address, provided the system can loaded it where you want, for DLL's the system is likely to want to rebase the code.

In 16-bit code you should be able to specify absolute addresses, but that's not particularly useful as things are usually loaded at arbitrary addresses. Mostly it could be used to specify things in the BIOS ROM, or the BIOS data area, or video buffer.
Title: Re: Defining an explicit address for a function
Post by: Matt.J on January 15, 2011, 04:52:38 AM
Although irrelevant; I'm writing a video emulation layer for an old game.

As I said, defining the relative address of a function; not the load address.
Title: Re: Defining an explicit address for a function
Post by: clive on January 15, 2011, 06:07:14 AM
It's going to be hard to do. You could certainly pad the gap between subroutines to achieve certain goal addresses. You might be able to use the AT directive with the segment definitions, or define multiple segments with specific alignments, say 0x400, 0x1000, 0x10000, within an executable.

Specifically why do the addresses need to be fixed in this manner? Are you trying to achieve some interlinking between some other system/user components? Or splicing some new code into an existing application or DLL?
Title: Re: Defining an explicit address for a function
Post by: redskull on January 17, 2011, 12:30:08 AM
What's wrong with regular old ORG?