Article View: comp.lang.asm.x86
Article #50Re: Absolute addresses, relative addresses
From: Alex McDonald
Date: Tue, 26 Aug 2003 15:52
Date: Tue, 26 Aug 2003 15:52
72 lines
4131 bytes
4131 bytes
minso@altern.org (Eric Minso) wrote in message news:<7db38e60.0308250121.6135ebc1@posting.google.com>... > Hello, > > I would like to know a bit more about the use of absolute addresses > and relative addresses. > > I have read that Windows DLL have a relocation table : this table is > needed to correct each absolute addresse in the DLL file because you > can't assume the memory location where DLL while be loaded. But, why > don't only use relative addresses ? (because it's not possible, I > guess) It is possible, but there are a couple of downsides; 1. the code is longer, as offsets need to be calculated into addresses 2. the code needs a base register to do this, which on a register-starved machine like the x86 is a problem. > > In fact, my questions are : > > In which cases can you use relative addresses ? > In which cases must you use absolute addresses ? > In which cases can you choose ? (and which choice is better ? (i.e. > for speed...)) As per Koms Bomb's reply in this thread > > Tell me if I am wrong : you can use relative addresses only inside a > code section, and each time you reference another section, you must > use absolute addresses. Is it right ? If the code is liked together from separate assemblies, yes. If it's multiple sections in one assembly, not necessarily, but probably yes. > > A last question before leaving :-) > > This instruction : > mov [ ebp + cst ], val > (with 'ebp' initialised with loading address, and 'cst' initialised > with offset) can solve the absolute addresses problem, so where is the > trap ? There isn't one, except your cst must be a register, as noted above. Here's an example; let's say we have an address in eax that points to an addresss we want to jump to. jmp [eax] If it's to be relocatable then the pointer is an offset, and so is the thing it points to, so mov eax, [eax+edi] add eax, edi jmp eax Longer, needs edi as a base register and adds to the code complexity (unless you're prepared to use macros extensively). Plus, if you get an address back from some other code (like the OS) then you have to sub eax, edi to make it a relative offset too. > > Thank you ! > > Eric. -- Regards Alex McDonald
Technical Details
Message-ID:
<b57b10b6.0308260752.3304c0bf@posting.google.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-post-01!supernews.com!corp.supernews.com!news.crayne.org!clax86!robomod!not-for-mailReferences:
<7db38e60.0308250121.6135ebc1@posting.google.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 114917,44f17f79ebe31523 X-Google-Attributes: gid114917,public X-Google-Thread: feaef,44f17f79ebe31523 X-Google-Attributes: gidfeaef,public X-Google-Thread: f7d8d,44f17f79ebe31523 X-Google-Attributes: gidf7d8d,public X-Google-Thread: 1093da,44f17f79ebe31523 X-Google-Attributes: gid1093da,public X-Google-ArrivalTime: 2003-08-26 08:56:22 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-post-01!supernews.com!corp.supernews.com!news.crayne.org!clax86!robomod!not-for-mail From: alex_mcd@btopenworld.com (Alex McDonald) Newsgroups: comp.lang.asm.x86,alt.lang.asm,alt.os.assembly,borland.public.tasm Subject: Re: Absolute addresses, relative addresses Approved: CLAX86 Moderators <ccrayne@crayne.org> Date: 26 Aug 2003 08:52:47 -0700 Organization: http://groups.google.com/ Message-ID: <b57b10b6.0308260752.3304c0bf@posting.google.com> X-CLAX86-Policy: http://www.pacificsites.com/~ccrayne/clax86.html X-CLAX86-Faq: http://www.faqs.org/faqs/by-newsgroup/comp/comp.lang.asm.x86.html X-CLAX86-Info-1: Send submissions to comp-lang-asm-x86@moderators.isc.org X-CLAX86-Info-2: Send technical complaints to ccrayne@crayne.org X-CLAX86-Info-3: Send complaints about policy to ccrayne@crayne.org X-Comment: moderators do not necessarily agree or disagree with this article. References: <7db38e60.0308250121.6135ebc1@posting.google.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-MailScanner-Information: Please contact the ISP for more information X-MailScanner: Found to be clean X-MailScanner-SpamCheck: not spam (whitelisted), SpamAssassin (score=-1, required 4, QUOTED_EMAIL_TEXT -0.48, REFERENCES -0.50) X-UIDL: ,VL!!=2U!!iI:!!nTC"! X-Complaints-To: abuse@supernews.com Lines: 73