flat assembler
Message board for the users of flat assembler.

Index > Main > how to let "extrn" work in the macro definition?

Author
Thread Post new topic Reply to topic
c0d3z



Joined: 25 Aug 2005
Posts: 2
c0d3z 25 Aug 2005, 05:32
Hi,

I wrote a tiny program for fasm with 1.64 on windows sp2.

Code:
; filename: test.asm
;========================================================================================
; a tiny sources written by c0d3z.
;
; COMPILE:
;       fasm test.asm test.obj
; LINK:
;       alink.exe test.obj kernel32.lib user32.lib -o test.exe -oPE -subsys gui -entry start
;========================================================================================
format MS COFF

macro invoke proc, [arg]
{
        if ~ arg eq
                reverse push arg
        end if

        common  call proc
}

extrn MessageBoxA: dword
extrn ExitProcess: dword

section ".code" code readable executable

public start
start:
        invoke MessageBoxA, 0, szText, szInfo, 0
        invoke ExitProcess, 0

section ".data" data readable writeable
        szInfo  db "Hello",0
        szText  db "Hello,world!",0
    


It seems work ok.
But now I want to insert the "extrn" into invoke MACRO definition.
I intend to modify the "invoke" MACRO just like this:

Code:
macro invoke proc, [arg]
{
        if ~ defined proc
                extrn proc: DWORD
        end if

        if ~ arg eq
                reverse push arg
        end if

        common  call proc
}
    


It no work. How should I do?
Thanks.
Post 25 Aug 2005, 05:32
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7103
Location: Slovakia
vid 25 Aug 2005, 08:17
you should read FAQ. you are using "If not defined then define" which is illogical contrusction (because FASM's "defined" operator has scope over whole file, not only before it's used)
Post 25 Aug 2005, 08:17
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
c0d3z



Joined: 25 Aug 2005
Posts: 2
c0d3z 26 Aug 2005, 04:38
thanks for reply, but any solution?
I only want to insert the extrn in this macro.
Post 26 Aug 2005, 04:38
View user's profile Send private message Reply with quote
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM 26 Aug 2005, 15:35
It should be like this:
Code:
format MS COFF

macro invoke proc, [arg]
{

        if ~ arg eq
                reverse push arg
        end if

        common
                if ~ defined proc | defined proc#_defined_here
                extrn proc: DWORD
                proc#_defined_here = 1
        end if
         call proc
}

;extrn MessageBoxA: dword
;extrn ExitProcess: dword

section ".code" code readable executable

public start
start:
        invoke MessageBoxA, 0, szText, szInfo, 0
        invoke ExitProcess, 0

section ".data" data readable writeable
        szInfo  db "Hello",0
        szText  db "Hello,world!",0
    

because it sets a variable defining whether the procedure has been extrn'd yet, so it will continue to do it for all passes. I can't explain well, read the "Design Principles" in the Documentation section.
Also, the extrn definition is in the 'common' section; you wouldn't want to do it multiple times for each procedure to call, would you?

_________________
This calls for... Ultra CRUNCHY Man!
Ta da!! *crunch*
Post 26 Aug 2005, 15:35
View user's profile Send private message Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex 26 Aug 2005, 19:54
Hi UCM,

Thanks for your macro, nice design. Now this invoke macro acts like GoAsm's invoke statement which doesn't require the extrn command.

_________________
Code it... That's all...
Post 26 Aug 2005, 19:54
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.