flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > multipass assembling description request

Author
Thread Post new topic Reply to topic
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 30 Jun 2004, 19:54
could you please describe deeper way your multipass assembling works?

You mentioned it somewhere a little bit, about prediction of usage of symbols at end of pass, when assembler somehow decides if it should redo the step etc.

I think it will help many people and maybe someone will even get better idea (to allow
if ~defined ABCD
ABCD=1
like most new users awaits it)
Post 30 Jun 2004, 19:54
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8354
Location: Kraków, Poland
Tomasz Grysztar 30 Jun 2004, 20:56
I had once posted some kind of such description on the old forum: http://board.win32asmcommunity.net/showthread.php?s=&threadid=10640#post80063
Post 30 Jun 2004, 20:56
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8354
Location: Kraków, Poland
Tomasz Grysztar 30 Jun 2004, 21:12
I'm posting a copy of that post updated to cover the latest FASM releases:

FASM is a multi-pass assembler and therefore allows many kinds of forward references. You can access a label before it's defined and check whether it's used before it's actually used, because when FASM is not sure it can give you the right result on the first pass, it does the second, when all values of labels are already known. But it may happen that something (eg. opcode size) was predicted wrong and therefore some labels have changed. In such case FASM does one more pass, on so on.

FASM determines that the one more pass is needed if one of the following situations happens:

  • Undefined symbols: when some symbol is undefined, second pass is done to determine whether it's forward-referenced, this happens only in first pass. In later passes it causes an error, but when FASM needs to do still one more pass, it ignores such error and does the next pass anyway.
  • Changed labels: some labels (or forward-referenced contants, the numerical constants that are defined only once in source can be forward-referenced) have been defined with different values than in previous pass. But if label wasn't actually used, it doesn't cause the next pass.
  • "Used" misprediction: when "used" operator is given a symbol that has not been used in current pass, it has to predict whether it'll be used or not, if it was used in previous pass, it's predicted to be used in next, otherwise it's predicted to be not used. If after finishing the pass FASM determines that some of such predictions were wrong, it does one more pass.
  • "Defined" misprediction: similar to "used" prediction, the "defined" prediction happens when "defined" operator is given a symbol that has not yet been defined in current pass. If after finishing the pass FASM determines that such prediction was wrong, it does one more pass.
  • Lost definitions: when some label was defined in previous pass but not in the current (it's checked after finishing the whole pass, like the mispredictions), one more pass is done. But if such label wasn't used at all in the current pass, this case is ignored.
  • Addresses changed due to formatter's work: after assembler has finished all its passes it may happen that formatter forces it to do once more, when some structures in header have changed their size (eg. there were more sections in PE defined than default 4K header can hold) and therefore all addresses have to move. This is a rare case.
Post 30 Jun 2004, 21:12
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.