flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > [request] command line include

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
turdus



Joined: 19 Apr 2006
Posts: 8
turdus
Is there a way to include macro definitions on command line?
I guess it should be something like

fasm -i mylittlemacros.inc some.asm some.bin

It would be very useful. It's great for os specific macros, eg
fasm -i oslinux.inc x.asm x
or
fasm -i oswin32.inc x.asm x.exe
etc.
where all contain eg a macro named printf. With this you would be able to write os independent asm sources very-very easily. And that's only one example.

Thx,
Turdus
Post 19 Apr 2006, 15:10
View user's profile Send private message Reply with quote
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM
fasm was designed with NOT having this in mind- the idea is, you can simply compile any file just typing `fasm blah.asm' (and if you get `out of memory' you use -m and increase memory limit), if you did this then people would have to remember to put this as the command line argument.

this is what you could do instead: (putting this in the beginning of the file, of course)
Code:
OS equ linux ;change it to win32 to use oswin32.inc instead
match =linux,OS {
 include 'oslinux.inc'
}
match =win32,OS {
 include 'oswin32.inc'
}
    

Note: if you don't understand this, maybe you should read the `Macroinstructions' part of the manual
Post 20 Apr 2006, 00:00
View user's profile Send private message Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi
Code:
WIN equ 1 ;0 for linux
IF WIN = 1
  include 'oswin32.inc'
ELSE
  include 'oslinux.inc'
ENDIF    


'Conditional Assembly'
http://flatassembler.net/docs.php?article=manual#2.2.2
Post 20 Apr 2006, 01:43
View user's profile Send private message MSN Messenger Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
okasvi, with conditional assembly both macro sets will be included, you must use match instead like UCM. If both, oswin32 and oslinux has a macro named printf then even if "WIN equ 1" is present the linux printf macro will be used.
Post 20 Apr 2006, 02:13
View user's profile Send private message Reply with quote
turdus



Joined: 19 Apr 2006
Posts: 8
turdus
[quote="UCM"]fasm was designed with NOT having this in mind- the idea is, you can simply compile any file just typing `fasm blah.asm' (and if you get `out of memory' you use -m and increase memory limit), if you did this then people would have to remember to put this as the command line argument.

this is what you could do instead: (putting this in the beginning of the file, of course)
[/quote]

You missed the point!!! It was just an example. The point is NOT PUTTING ANYTHING in the beginning of file. I could have used
[code]
include mylittlemacros.inc
[/code]
which is trivial. I think an '-i' switch won't hurt anyone, and you could compile any file just typing 'fasm blah.asm', but others (like me) could type 'fasm -i my.inc blah.asm' too.
So, just make it clear: I want have some macros predefined when processing of blah.asm begins.
Post 20 Apr 2006, 11:36
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7721
Location: Kraków, Poland
Tomasz Grysztar
You can do it with environment variables, like:
Code:
include 'os%ASMOS%.inc'    
Post 20 Apr 2006, 11:56
View user's profile Send private message Visit poster's website Reply with quote
turdus



Joined: 19 Apr 2006
Posts: 8
turdus
Tomasz Grysztar wrote:
You can do it with environment variables, like:
Code:
include 'os%ASMOS%.inc'    

I repeat: the point is not putting anything in beginning of file! Forget the example. Focus on the main topic: command line include, predefined macros.
Please... won't hurt you, and I would appreciate very much.
Post 20 Apr 2006, 12:03
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
okasvi: no, it doesn't work this way. You must use match as UCM showed
Post 20 Apr 2006, 12:06
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7721
Location: Kraków, Poland
Tomasz Grysztar
OK, so without putting anything in your main file Wink

ECHO include 'oswin32.inc' > tmp.asm
ECHO include '%1' >> tmp.asm
fasm tmp.asm %2
del tmp.asm
Post 20 Apr 2006, 12:09
View user's profile Send private message Visit poster's website Reply with quote
turdus



Joined: 19 Apr 2006
Posts: 8
turdus
Tomasz Grysztar wrote:
OK, so without putting anything in your main file Wink

ECHO include 'oswin32.inc' > tmp.asm
ECHO include '%1' >> tmp.asm
fasm tmp.asm %2
del tmp.asm

That's what I call wasting resources Smile
Wouldn't be simplier
Code:
fasm -i mymacros.inc %1.asm
    

?
It would really really useful. Eg.:
Code:
fasm -i formattingmacros.inc easytoread.asm
fasm -i tasmsyntax.inc tasmcompatible.asm
    

(These are just examples!!!)
Post 20 Apr 2006, 12:54
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
it would be easier, but not efficient, because one of best things on fasm is that result depends ONLY on contents of source, so if you can compile source at one place, you can compile it everywhere.

ever tried to compile som multi-platform GCC sources? 95% times you need to go into sources and change some settings or even code. There is a great mess required to make compilation close-to-possible on many systems with this approach.

You will appreciate it after you use it a while, believe me
Post 20 Apr 2006, 13:00
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7721
Location: Kraków, Poland
Tomasz Grysztar
This is not really related to SSSO principle, as it is not the thing HOW the source is processed, but WHAT source is processed. This is simply the matter of OS interface. I proposed that simple batch script, to show that it's rather a matter of interface than of fasm's core.
Post 20 Apr 2006, 13:38
View user's profile Send private message Visit poster's website Reply with quote
turdus



Joined: 19 Apr 2006
Posts: 8
turdus
Forget it. I've modified the source, now I have predefined macros.
Thanks for your kind help.
Post 20 Apr 2006, 13:56
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
do you think it isn't releated to SSSO? I think this would break SSSO (like environment variables do, but this is acceptable useful exception)
Post 20 Apr 2006, 15:40
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
turdus



Joined: 19 Apr 2006
Posts: 8
turdus
vid wrote:
do you think it isn't releated to SSSO? I think this would break SSSO (like environment variables do, but this is acceptable useful exception)

This is also an acceptable useful exception. Nevertheless gcc and nasm also has it.
Code:
gcc -include file
nasm -P file
    

Bye.
Post 20 Apr 2006, 16:07
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Well, it wouldn't probably do any direct bad, but people will tend to use it, even though in 99.9% of cases there is a better solution.
Post 20 Apr 2006, 16:32
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7721
Location: Kraków, Poland
Tomasz Grysztar
vid wrote:
do you think it isn't releated to SSSO? I think this would break SSSO (like environment variables do, but this is acceptable useful exception)

This, and environment variables, are both, as I said: "not the thing HOW the source is processed, but WHAT source is processed". In the same way like the path that you give in the command line determines what file will be loaded for processing. The paths given inside the INCLUDE directive are interpreted by the system to find the appropriate file and this is where SSSO cannot be applied.
Post 20 Apr 2006, 16:41
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
well, from some point of view. BUt that include file can adjust meaning of things in another file, like overload instruction etc.
Post 20 Apr 2006, 18:04
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7721
Location: Kraków, Poland
Tomasz Grysztar
Of course - this is a different source then.
But I agree that also, from some other point of view, it may be considered a bit SSSO-breaking, though.
Post 20 Apr 2006, 19:32
View user's profile Send private message Visit poster's website Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost
turdus wrote:
vid wrote:
do you think it isn't releated to SSSO? I think this would break SSSO (like environment variables do, but this is acceptable useful exception)

This is also an acceptable useful exception. Nevertheless gcc and nasm also has it.
Code:
gcc -include file
nasm -P file
    

Bye.


nasm is crap compared to fasm, it's a design principle of the assembler and frankly i love it, that's one of the things that really bothered me about nasm was all the command line stuff, i see no reason why preprocessor isn't good enough for you here Surprised

here i provide another solution even

Code:
WIN32 = 1


if defined WIN32
   include 'win32.inc'
else if defined LINUX
   include 'linux.inc'
else
   display 'choose a platform'
end if         
    

_________________
redghost.ca
Post 21 Apr 2006, 11:32
View user's profile Send private message AIM Address MSN Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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.

Powered by rwasa.