NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: puttyios on June 13, 2012, 09:29:32 AM
-
mov var, %eax; //varis a global variabley
when linking, the varis may be replaced by that global variable's address,
what is the procedure in which the linker calculate that address?
I guess that is like this : the linker serch the symbole 'var' and find it is in the .data segment,so the linker use the symbol's linear address to update the instruction to ' mov address , %eax ‘ .
Is this right?
-
I think the answer to that is "yes"... although this doesn't appear to be valid Nasm syntax. For (much!) more complete information, you might want to look at the ELF specification...
Best,
Frank
-
hi,Frank:
thank you for your help at this forum!
a symbole's address is caculated to be a offset or a linear address? and is its address reallocatable?
-
You're welcome. Thanks to all the other folks who help at the forum (and make it possible!) too!
An address consists of a segment and an offset. In real mode, the contents of a segment register are multiplied by 16 and added to the offset to form the linear address... which is the same as the physical address...
In protected mode, the rules are different - the value in a segment register serves as an index into a table of structures, each of which contains a "base" (amongst other things) which is added to the offset to form the linear address. In any OS you're likely to encounter, the "base" is zero so the linear address is just the offset. However... the OS has almost certainly enabled "paging", which means that the actual physical address in RAM can be "anywhere it pleases" - even "paged out" to disk and not in RAM at all (for the moment).
In any case, Nasm only knows about the offset from the beginning of the section. All else is up to the linker. An exception is "-f bin" output format, in which the output driver "acts as its own linker". Even in this case, the "assembler" part of Nasm doesn't know what the output driver is going to do, so treats all addresses as "relocatable" (this is what the error message about "scalar values" means: "not relocatable").
Does that answer the question?
Best,
Frank
-
thanks ! Frank:
if a symbol is define in local object file , other than external .o files. then does the symbol's address need to be reallocated?
By the way,Is there some nice forums talking about linux assembly ? I want to lean more about that!
Best Regards!
-
You keep sayin' "reallocatable". I ASSume you mean "relocatable"?... in which case the answer is "yes".
Linux? Linux? I think I've heard of that. My memory's getting fuzzy, but I think I've heard of it recently! Oh yeah, here 'tis:
http://forum.nasm.us/index.php?topic=1424.0
Maybe we need a section of the Forum explicitly named "Linux". Nah, wouldn't do any good! If you check out the AsmCommunity Forum, you'll find some Linux (Gas) code in the "assemblers" section, as well as in the "Linux" section. Sigh. :)
Best,
Frank