flat assembler
Message board for the users of flat assembler.

Index > Main > How to include source at the DESIRED place?

Author
Thread Post new topic Reply to topic
alxdef



Joined: 15 Sep 2005
Posts: 4
alxdef
I've already written about my problem but I still can't solve it. Here it is.
I need to write some library under FASM but include functions' sources only if they appear in main code and do it at the end of main code.

In MAIN.ASM:
Code:
include 'my_lib.inc'
lib_call some_func arg0, ... argN
    


In MY_LIB.INC
Code:
if ~defined LIB_INCLUDED
        LIB_INCLUDED equ 0xFF

        macro lib_call f_name*, [args]
        {
                LIB_#f_name args
        }

        include '%asm_lib%/p1.inc'
end if    


In P1.INC
Code:
if ~defined P1_INCLUDED
        P1_INCLUDED equ 0xFF

        macro LIB_some_func [args]
        {
                include '%asm_lib%/some_func.inc'
                common call P1_some_func
        }
end if    


In SOME_FUNC.INC
Code:
if ~defined LIB_SOME_FUNC_INCLUDED
        LIB_SOME_FUNC_INCLUDED equ 0xFF

P1_some_func:
        ; 'SOME_FUNC' code
        ret
end if    


I understand that line
Code:
include '%asm_lib%/some_func.inc'    

will placed right here where it is but I need it in another place (at the end of MAIN.ASM)
Is this problem solvable?
Post 23 Sep 2005, 09:18
View user's profile Send private message ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17492
Location: In your JS exploiting you and your system
revolution
I think your problem is with the way you use "define". Try this.

In MAIN.ASM:
Code:
macro if_ndef name { match =name,name \{ }
include 'my_lib.inc' 
lib_call some_func arg0, ... argN    
In MY_LIB.INC
Code:
if_ndef LIB_INCLUDED
        macro lib_call f_name*, [args] 
        \{ 
                LIB_\#f_name args 
        \} 

        include '%asm_lib%/p1.inc' 
}
define LIB_INCLUDED    
In P1.INC
Code:
if_ndef P1_INCLUDED
        macro LIB_some_func [args] 
        \{ 
                include '%asm_lib%/some_func.inc' 
                common call P1_some_func 
        \} 
}
define P1_INCLUDED    
In SOME_FUNC.INC
Code:
if_ndef LIB_SOME_FUNC_INCLUDED 
P1_some_func: 
        ; 'SOME_FUNC' code 
        ret 
}
define LIB_SOME_FUNC_INCLUDED    
Post 23 Sep 2005, 09:57
View user's profile Send private message Visit poster's website Reply with quote
alxdef



Joined: 15 Sep 2005
Posts: 4
alxdef
May be I'm a lamer, but fasm says
Quote:

define P1_INCLUDED - illegal instruction

???
Post 23 Sep 2005, 11:35
View user's profile Send private message ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
FASM's default "proc" macro doesn't generate the code if procedure isn't used anywhere, if this is what you wanted. But this is task of assembler, not preprocessor.
Post 23 Sep 2005, 13:25
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17492
Location: In your JS exploiting you and your system
revolution
Oops, sorry forgot this
Code:
macro define name { name equ defined }    
Place just after the if_ndef and before you use it.
Post 23 Sep 2005, 13:38
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


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.