flat assembler
Message board for the users of flat assembler.

Index > Windows > section ".reloc" fixups and "invalid use of s

Author
Thread Post new topic Reply to topic
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
This code compiles fine with FASM 1.67.29 without 'section ".reloc" fixups' in it:

Code:
Tmp_Lab: retn ; or some other code
Function1 = Tmp_Lab

;label OutOfCodeAddress at 0
;OutOfCodeAddress = $ - $ ; or some variant to get label = 0
OutOfCodeAddress = 0

 if Function1 <> OutOfCodeAddress
  display "No function address",13,10
 end if
    


But with 'section ".reloc" fixups' it says 'invalid use of symbol' with any 'OutOfCodeAddress' variants.
Somebody please explain me, why it is so? Tomasz, please explain, what limitations does 'section ".reloc" fixups' for code like this?
Thanks.

_________________
Flat Assembler is the best!
Post 10 Jan 2009, 12:49
View user's profile Send private message Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
Sorry,
[code]
if Function1 <> OutOfCodeAddress
[\code]
must be
[code]
if Function1 = OutOfCodeAddress
[\code]
to display correct message, but it does not make this code work )))))
Post 10 Jan 2009, 12:55
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
That is because, since you are allowing the code to be relocated at run-time, the address of Function1 cannot be known at compile-time so it is not possible to tell if Function1 is equal to OutOfCodeAddress or not.
Post 10 Jan 2009, 14:56
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Perhaps you need this?
Code:
CODE_BLOCK_BEGIN:

Tmp_Lab: retn ; or some other code
Function1 = foo

;...

CODE_BLOCK_END:

foo:

macro isInsideCode address*
{
  if address >= CODE_BLOCK_BEGIN & address < CODE_BLOCK_END
    display "Yes, ", `address, " is inside the code!",13,10
  else
    display "No, ", `address, " is not inside the code...", 13, 10
  end if
}

isInsideCode Tmp_Lab
isInsideCode foo    
Note however that the macro will not support tests for constants, only labels will be allowed and this time fasm does not complains because even with relocations the relative address in memory is known in advance.
Post 10 Jan 2009, 15:08
View user's profile Send private message Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
Thanks for your explanation LocoDelAssembly! But I have next question,
but first - code:
Code:
OutOfCode = $$ - 1 

asd:
 A = asd
 
B = OutOfCode

 if A <> OutOfCode
  display "A is in code.",13,10   
 end if
 if B = OutOfCode
  display "B is out of code.",13,10   
 end if
    

The question is - will "OutOfCode" be really out in such case?
Thanks.

_________________
Flat Assembler is the best!
Post 10 Jan 2009, 19:28
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Yes, since it will be one byte behind the base address.

However, if you really want to test if some label (or some label added/subtracted by a constant) belongs to some byte defined by the source code (either instruction bytes or data bytes), then the macro would be this one:
Code:
macro isInsideCode address*
{
  if (address >= $$) & (address < END_OF_SOURCE)
    display "It is inside", 13, 10
  else
    display "It is outside", 13, 10
  end if
}
    
Where END_OF_SOURCE is a label that you must define at the end of the main source file.

Note that it is assumed you will not use the ORG directive anywhere, not only because it kills relocations, but also because the testing of an address gets more complicated (it has to account for every ORG directive used on the source). Testing for labels defined inside virtual blocks won't work properly neither.
Post 10 Jan 2009, 23:25
View user's profile Send private message Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
Thanks for explanation! It is quite enough for me to work fine with just equal comparison, without range checking.
Post 10 Jan 2009, 23:44
View user's profile Send private message 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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.