flat assembler
Message board for the users of flat assembler.
Index
> Compiler Internals > Howto: environment identification within fasm |
Author |
|
Raedwulf 22 Dec 2006, 18:00
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. |
|||
22 Dec 2006, 18:00 |
|
nickv 22 Dec 2006, 18:34
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)? |
|||
22 Dec 2006, 18:34 |
|
dead_body 22 Dec 2006, 19:51
see sources of fasmlib
|
|||
22 Dec 2006, 19:51 |
|
vid 22 Dec 2006, 22:15
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 |
|||
22 Dec 2006, 22:15 |
|
nickv 24 Dec 2006, 06:10
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. I can use the different ASMINC variables under different OSes. It's the simples way, definitely! Thanx a lot! Problem is solved. |
|||
24 Dec 2006, 06:10 |
|
vid 24 Dec 2006, 10:29
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 include '%OS%' |
|||
24 Dec 2006, 10:29 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.