FASM include по двум возможным адресам?

Assembler programming questions
Post Reply
Kolibrius
Posts: 26
Joined: Wed Sep 22, 2021 9:36 pm

FASM include по двум возможным адресам?

Post by Kolibrius »

Возможно ли в FASM загрузить inc файл если он не найден по одному пути, загрузить его по другому пути.

что-то вроде этого:

Code: Select all

include '../../../macros.inc'
if varible from macros not exist
   include 'rd1/macros.inc'
endif
User avatar
dunkaist
Mentor
Posts: 728
Joined: Mon Oct 19, 2009 10:58 am
Been thanked: 2 times

Re: FASM include по двум возможным адресам?

Post by dunkaist »

The closest to what you are trying to achieve is done via 'include' environment variable, see the corresponding fasm programmer's manual section.
Kolibrius
Posts: 26
Joined: Wed Sep 22, 2021 9:36 pm

Re: FASM include по двум возможным адресам?

Post by Kolibrius »

If 'include' does not find the file, it interrupts compilation and there is no way to skip error. I think solution is not exist.
User avatar
dunkaist
Mentor
Posts: 728
Joined: Mon Oct 19, 2009 10:58 am
Been thanked: 2 times

Re: FASM include по двум возможным адресам?

Post by dunkaist »

The trick (a documented one though) is to provide several paths to look for the included file.

Code: Select all

$ cat main.asm
include 'blah.inc'
display 'hi, ', NAME
db NAME

$ cat one/blah.inc
NAME equ 'Alice'

$ cat two/blah.inc
NAME equ 'Bob'

$ INCLUDE='one;two' fasm main.asm main
flat assembler  version 1.73.28  (16384 kilobytes memory, x64)
hi, Alice
1 passes, 5 bytes.

$ hexdump -C main
00000000  41 6c 69 63 65                                    |Alice|
00000005

$ INCLUDE='two;one' fasm main.asm main
flat assembler  version 1.73.28  (16384 kilobytes memory, x64)
hi, Bob
1 passes, 3 bytes.

$ hexdump -C main
00000000  42 6f 62                                          |Bob|
00000003
Kolibrius
Posts: 26
Joined: Wed Sep 22, 2021 9:36 pm

Re: FASM include по двум возможным адресам?

Post by Kolibrius »

i try in asm file use include:

include "../../../macros.inc;/sys/macros.inc"

but FASM shows error:
Attachments
include.png
include.png (3.25 KiB) Viewed 3344 times
User avatar
dunkaist
Mentor
Posts: 728
Joined: Mon Oct 19, 2009 10:58 am
Been thanked: 2 times

Re: FASM include по двум возможным адресам?

Post by dunkaist »

In my example INCLUDE='one;two' is an environment variable, and the file is included as include 'blah.inc'. Fasm can handle several paths only when they are provided in an environment variable, not after include keyword.

I see that you are using an absolute path /sys/lang.inc, i.e. you are trying to compile from KolibriOS. Well, KolibriOS doesn't support environment variables. If your aim is to be able to compile your program from both KolibriOS and Windows/Linux, then you can do as follows:
  1. Copy all the standard includes (like macros.inc and lang.inc) to the directory of the main *.asm file of your program.
  2. Include these standard includes without specifying any path, just include 'macros.inc'.
  3. Compile from KolibriOS as usual.
  4. Compile from Windows/Linux specifying INCLUDE environment variable with paths to standard includes.
Kolibrius
Posts: 26
Joined: Wed Sep 22, 2021 9:36 pm

Re: FASM include по двум возможным адресам?

Post by Kolibrius »

This is way is possible but it not comfortable when it need to use environment variable.

Are there any ways to get operating system type in FASM code? Or version of FASM? Any variable?
That can able to do something like:

Code: Select all

if FASM_OS = 'Kolibri'
    include '/sys/macros.inc'     ; path for build in KOS   
else
    include '../../../macros.inc'  ; path for build in SVN 
endif
But im look documentation and FASM source code on SVN, and not find varibles for detect OS.
User avatar
dunkaist
Mentor
Posts: 728
Joined: Mon Oct 19, 2009 10:58 am
Been thanked: 2 times

Re: FASM include по двум возможным адресам?

Post by dunkaist »

Try this:

Code: Select all

FASM_OS equ KOLIBRIOS

match =KOLIBRIOS, FASM_OS {
  include 'one/blah.inc'
}

match =LINUX, FASM_OS {
  include 'two/blah.inc'
}
https://board.flatassembler.net/topic.php?t=21883
User avatar
dunkaist
Mentor
Posts: 728
Joined: Mon Oct 19, 2009 10:58 am
Been thanked: 2 times

Re: FASM include по двум возможным адресам?

Post by dunkaist »

Same approach but a bit cleaner:

Code: Select all

match =AUTOBUILD,AUTOBUILD {
  include 'one/blah.inc'
}

match =YES, AUTOBUILD {
  include 'two/blah.inc'
}
Compile from KolibriOS as usual, from Linux/Windows with -dAUTOBUILD=YES.
Kolibrius
Posts: 26
Joined: Wed Sep 22, 2021 9:36 pm

Re: FASM include по двум возможным адресам?

Post by Kolibrius »

I think this is will be work...

Code: Select all

match =NOTHING,AUTOBUILD {
  include ''/sys/lang.inc'
  include ''/sys/macros.inc'
}

match =YES, AUTOBUILD {
  include 'lang.inc'
  include '../../../macros.inc'
}
Ray
Posts: 126
Joined: Sun Aug 09, 2015 3:41 pm

Re: FASM include по двум возможным адресам?

Post by Ray »

: [quote]is will be[/quote]
такого я ещё не видел)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest