flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Howto: environment identification within fasm

Author
Thread Post new topic Reply to topic
nickv



Joined: 14 Dec 2006
Posts: 3
Location: Russia
nickv
Guys,

I need to wirte the portable asm code between win32 and Linux32.
How can I identify the OS within asm code to perform conditional compilation?
Maybe FASM have some predefined variables like Version, OS etc?
Or, maybe, FASM supports the environment variables?

I read all of the documentations and many threads of the forum, but unsuccesfully.
Please, help...
Post 22 Dec 2006, 17:41
View user's profile Send private message Reply with quote
Raedwulf



Joined: 13 Jul 2005
Posts: 375
Location: United Kingdom
Raedwulf
How do you want to identify the OS? FASM generates executables for Linux, and Win32. For Linux, it is generally recommended to product ELF object files and link with g++ or ld. For Windows, you can generate .exe files straight from the assembler.

If you have read the documentation,
if Something = SomethingElse
...
else
...
end if

FASMLIB 0.4 sounds like the works for you, to generate portable code, but you will still need at least 1 file to be different for each OS.

Please see
http://board.flatassembler.net/topic.php?t=4696

and try some the examples

What asm experience do you have, we can probably help you out more by translating examples from your default assembler?

Cheers.
Post 22 Dec 2006, 18:00
View user's profile Send private message MSN Messenger Reply with quote
nickv



Joined: 14 Dec 2006
Posts: 3
Location: Russia
nickv
Quote:
What asm experience do you have, we can probably help you out more by translating examples from your default assembler?

I'm writing the library. Started from win32 msvc, now I need to port it to Linux. Library have many inline asm code, which, unfortunatelly, incompatible with g++.
I have looked onto standalone assemblers and found the FASM suitable and the best.
The problem is in different FORMAT directive (COFF vs ELF) and different sections' names and maybe smth else.

I would like to use smth like following:
Code:
if _os_ EQ LINUX
  FORMAT ELF
else
  FORMAT MS COFF
endif
    


How can I do it? Or maybe it can be made somehow else (without modifying of asm files)?
Post 22 Dec 2006, 18:34
View user's profile Send private message Reply with quote
dead_body



Joined: 21 Sep 2005
Posts: 187
Location: Ukraine,Kharkov
dead_body
see sources of fasmlib
Post 22 Dec 2006, 19:51
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
nickv: you should read first chapter of fasmlib tutorial. I explain there how to write portable code with FASMLIB.

Note that detecting OS under which is FASM running, and deciding output based on that, is NOT good way. FASM allows to assemble linux outputs under win32 and vice-versa.

I prefer having 3 files: one for code which is portable, one for win32 format settings, and one for linux format settings. Both format settings files include the first one, with code.

Anyway, the tutorial could make it clear for you how, if not, ask here further: http://fasmlib.flatassembler.net/doc/tutorial/part1.txt

Here is also example of portable FASM project with libc: http://board.flatassembler.net/topic.php?t=6369. Uses same idea to be portable, as the one described.

It is still possible to have only one file, and detect os via environment variable
Post 22 Dec 2006, 22:15
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
nickv



Joined: 14 Dec 2006
Posts: 3
Location: Russia
nickv
vid: Thanx a lot!

Quote:
Note that detecting OS under which is FASM running, and deciding output based on that, is NOT good way.

Why not? It's good idea to have N+2 source files (source + two hdrs for win and for linux) instead N*3 (where each source file
needs to have two hdrs)? Or I'm wrong?
Quote:
FASM allows to assemble linux outputs under win32 and vice-versa.

Accepted. But knowledge about FASM version (linux,win,dos etc) do not interfere with it. It's just extends the usability of FASM in portability purpose.

Quote:
It is still possible to have only one file, and detect os via environment variable.

Please - tell me HOW?
I see that FASM can use environment variables in INCLUDE directive like %FASMINC% etc. But how can I use such ability somewhere else? I unable to put this variable, for example, to DISPLAY directive to test it and I even don't know how to use it with IF operator.

Actually, I may to move the conditional stage of compilation to MAKE - just create the proper asmheader file before the rest compilations. But imho it is not so pretty way...

Guys, I'm really stupid. Smile I can use the different ASMINC variables under different OSes. It's the simples way, definitely!

Thanx a lot! Problem is solved.
Post 24 Dec 2006, 06:10
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
Guys, I'm really stupid. I can use the different ASMINC variables under different OSes. It's the simples way, definitely

that is the other way i wanted to suggest Wink
include '%OS%'
Post 24 Dec 2006, 10:29
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number 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 GitHub, YouTube, Twitter.

Website powered by rwasa.