flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Nested macros

Author
Thread Post new topic Reply to topic
mwh



Joined: 29 May 2006
Posts: 8
Location: PHILIPPINES
mwh
I would like to defined 3 macros START_INLINE, END_INLINE, and INLINE, that would work as follows:

START_INLINE foo
...assembly code specific to foo...
END_INLINE

would generate:
...generic stuff produced by START_INLINE...
...assembly code specific to foo...
...generic stuff produced by END_INLINE...


INLINE foo

would generate only:
...assembly code specific to foo...

Any help would be appreciated.

Cheers,
Mark
Post 16 Dec 2007, 05:02
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17351
Location: In your JS exploiting you and your system
revolution
I don't see where in your description you need nesting of macros.

But anyway, have a look at the file 'win32ax.inc' in the fasm windows package. It shows one way to do macro nesting.

Also, I posted this code some time back, it also uses nesting:
Code:
macro nest_includeonce{
    macro includeonce path,[instr]\{\common
              file@include equ path
               match head path tail,files@included\\{file@include equ\\}
             match head path,files@included\\{file@include equ\\}
          match file,file@include\\{
                   files@included equ files@included path
                      nest_includeonce
                    include file
                        purge includeonce
                   irp i,instr\\\{i\\\}
                \\}
  \}
}nest_includeonce
files@included equ x 'macros.inc'    
Post 16 Dec 2007, 06:23
View user's profile Send private message Visit poster's website Reply with quote
mwh



Joined: 29 May 2006
Posts: 8
Location: PHILIPPINES
mwh
revolution wrote:
I don't see where in your description you need nesting of macros.


Ok, how would you do it without nesting then?
Post 16 Dec 2007, 10:01
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17351
Location: In your JS exploiting you and your system
revolution
mwh wrote:
Ok, how would you do it without nesting then?
Just use a normal macro.
Code:
START_INLINE macro mac_name {
  macro mac_name \{
  ;beginning code goes here
}

END_INLINE macro {
  ;ending code goes here
  \}
}

INLINE equ

START_INLINE foo
...assembly code specific to foo...
END_INLINE

INLINE foo    
Post 16 Dec 2007, 10:10
View user's profile Send private message Visit poster's website Reply with quote
mwh



Joined: 29 May 2006
Posts: 8
Location: PHILIPPINES
mwh
I'm not sure I understand, this doesn't seem like it produces the two results I'm looking for.

Also isn't this nesting the macro mac_name inside the macro START_INLINE?
Post 16 Dec 2007, 10:50
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17351
Location: In your JS exploiting you and your system
revolution
mwh wrote:
I'm not sure I understand, this doesn't seem like it produces the two results I'm looking for.
Okay, what results are you looking for? An example of produced code would be helpful.
mwh wrote:
Also isn't this nesting the macro mac_name inside the macro START_INLINE?
Nope, nesting is where one macro invokes itself. Or at least that is my understanding of nesting. The code in my last post is merely defining another macro, it is not invoking itself.
Post 16 Dec 2007, 11:35
View user's profile Send private message Visit poster's website Reply with quote
mwh



Joined: 29 May 2006
Posts: 8
Location: PHILIPPINES
mwh
Thanks for persevering with me:

The first result I'm looking for is that when the following appears in my source:

--------------------------------------
START_INLINE foo
...assembly code specific to foo...
END_INLINE
--------------------------------------

it would be substituted with:
--------------------------------------------------
...some assemby code produced by START_INLINE...
...assembly code specific to foo...
...some assembly code produced by END_INLINE...
-------------------------------------------------

The second result is when the following appears in my source:
--------------
INLINE foo
--------------

it would be substituted with only:
--------------------------------------
...assembly code specific to foo...
--------------------------------------
Post 16 Dec 2007, 11:51
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17351
Location: In your JS exploiting you and your system
revolution
Try this code
Code:
START_INLINE macro mac_name {
  ;beginning code goes here
  START_INLINE@name equ mac_name
  macro mac_name \{
}

END_INLINE macro {
  \}START_INLINE@name
  restore START_INLINE@name
  ;ending code goes here
}

INLINE equ
    
All I did was move the start and end code outside the 'foo' macro and auto invoke 'foo' after it is defined.
Post 16 Dec 2007, 12:06
View user's profile Send private message Visit poster's website Reply with quote
mwh



Joined: 29 May 2006
Posts: 8
Location: PHILIPPINES
mwh
START_INLINE macro mac_name {
;beginning code goes here
START_INLINE@name equ mac_name
macro mac_name \{
} <== doesn't compile, gives me an error here
Post 16 Dec 2007, 12:18
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17351
Location: In your JS exploiting you and your system
revolution
Okay, since you want it to be given directly
Code:
macro START_INLINE mac_name {
  ;beginning code goes here
  START_INLINE@name equ mac_name
  macro mac_name \{
}
macro END_INLINE {
  match x,START_INLINE@name\{x\}
  restore START_INLINE@name
  ;ending code goes here
}
END_INLINE fix }END_INLINE

INLINE fix    
Post 16 Dec 2007, 12:42
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
but note that using macrofeatures inside START_INLINE - END_INLINE block is tricky, you must escape symbols just like in nested macro.
Post 16 Dec 2007, 16:17
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
mwh



Joined: 29 May 2006
Posts: 8
Location: PHILIPPINES
mwh
revolution wrote:
Okay, since you want it to be given directly


Huh?

Thanks for the code, I'll try it out.
Post 17 Dec 2007, 13:05
View user's profile Send private message Reply with quote
mwh



Joined: 29 May 2006
Posts: 8
Location: PHILIPPINES
mwh
vid wrote:
but note that using macrofeatures inside START_INLINE - END_INLINE block is tricky, you must escape symbols just like in nested macro.


Perhaps it might be cleaner for me to use an external preprocessor rather than FASM's built-in macroinstructions for this.
Post 17 Dec 2007, 13:09
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
Perhaps it might be cleaner for me to use an external preprocessor rather than FASM's built-in macroinstructions for this.

Perhaps yes. If what you want can't be done with FASM macros using some sane way, using external tool is best option. Do you know some scripting language?
Post 17 Dec 2007, 22:51
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
mwh



Joined: 29 May 2006
Posts: 8
Location: PHILIPPINES
mwh
vid wrote:
Quote:
Perhaps it might be cleaner for me to use an external preprocessor rather than FASM's built-in macroinstructions for this.

Perhaps yes. If what you want can't be done with FASM macros using some sane way, using external tool is best option. Do you know some scripting language?


I usually use AWK for simple filters. Should work fine for this I think.

Cheers
Post 18 Dec 2007, 02:00
View user's profile Send private message 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.