flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Macroinstructions > Conditional include

Author
Thread Post new topic Reply to topic
Jin X



Joined: 06 Mar 2004
Posts: 12
Conditional include
I'm doing something like that:

Code:
if      one
    include     'one.inc'
else if two
    include     'two.inc'
else if three
    include     'three.inc'
end if

but fasm loads all 3 files!

And this:

Code:
if      one
    x equ aa
else if two | three
    x equ bb
end if

fasm does x equ aa then x eq bb
Why?

How can I load files and define symbols by conditions?


Last edited by Jin X on 14 Apr 2017, 20:28; edited 1 time in total
Post 14 Apr 2017, 19:03
View user's profile Send private message Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 12
I can't even use macros for define values

Code:
macro set1
{
  const fix 1
}

macro set2
{
  const fix 2
}

these macros definitions (without using) set const to 1 then to 2 !
Very strange... Sad
Post 14 Apr 2017, 19:16
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6302
Location: Kraków, Poland
fasm 1 has multiple processing layers and it is important to know what is processed at what stage. INCLUDE is interpreted by the preprocessor, while IF is processed by the assembler. At the time when the assembler sees the source, all the preprocessing has been done already. Similarly FIX is processed even earlier, as an pre-preprocessing task.
Post 14 Apr 2017, 20:10
View user's profile Send private message Visit poster's website Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 12
Ok, but how can I include different files (or define "equ"s) depending on some conditions?

I need to include a file depending on const that gets value in "virtual" code block (where I check a code size: 32 or 64-bit).

And one more question: why this generates an error?

Code:
a equ hello

macro hello {
  mov eax,ebx
}

a

but "fix" works well...
But I can't use "fix" because I need to select right value depending on some conditions too...
Post 14 Apr 2017, 20:42
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6302
Location: Kraków, Poland

Jin X wrote:
I need to include a file depending on const that gets value in "virtual" code block (where I check a code size: 32 or 64-bit).

It is not possible in fasm 1 architecture, because a value that only becomes known in the assembly stage cannot affect preprocessing stage. It is possible with fasmg engine, though.


Jin X wrote:
And one more question: why this generates an error?

Code:
a equ hello

macro hello {
  mov eax,ebx
}

a

but "fix" works well...
But I can't use "fix" because I need to select right value depending on some conditions too...

The EQU has only an effect for the lines that get passed to the assembler, while macros need to be recognized and processed by the preprocessor. But it possible to extract the value of such variable into a parameter of MATCH macro:

Code:
a equ hello

macro hello { 
  mov eax,ebx 


match valuea {
   value
}

The "value" parameter contains the extracted value of "a" so it gets replaced by "hello" before preprocessing the line in MATCH.
Post 14 Apr 2017, 21:04
View user's profile Send private message Visit poster's website Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 12
Maybe it's worth to do some conditional preprocessor directives that will branch depending on format (pe/pe64/elf32/elf64), bits (16/32/64), symbols using (like "if used") or definitions (like "if defined") and allow to choose "include" file, make "equ"s (maybe "fix" too) and so on? Smile
Post 15 Apr 2017, 08:11
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6302
Location: Kraków, Poland
Preprocessor doesn't know about output format because FORMAT is assembler's directive. But it is possible to define a "format" macro and use MATCH to detect what format does it set.
Post 15 Apr 2017, 09:05
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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.