Author Topic: question about addressing  (Read 14267 times)

Offline puttyios

  • Jr. Member
  • *
  • Posts: 26
question about addressing
« 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?

       










Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: question about addressing
« Reply #1 on: June 13, 2012, 03:11:24 PM »
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


Offline puttyios

  • Jr. Member
  • *
  • Posts: 26
Re: question about addressing
« Reply #2 on: June 15, 2012, 01:31:24 PM »
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?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: question about addressing
« Reply #3 on: June 15, 2012, 04:20:09 PM »
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


Offline puttyios

  • Jr. Member
  • *
  • Posts: 26
Re: question about addressing
« Reply #4 on: June 16, 2012, 01:17:03 AM »
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!

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: question about addressing
« Reply #5 on: June 16, 2012, 05:33:53 AM »
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