(I got a few debug erros -- and some strange double^2 post)
Post:
Ok, I've gotten a few debug error oages whil trying to psot and delete double post in the "Macro tutorials" thread.
Here is the post which should be there (including the attachent):
3) The 'forward', 'common', and 'reverse' - why they are required, and are there any other directives for macros? I'm really confused with this directives even though I've gone thru the manual. Pls explain a little.

3) Ok, you've read the manual, first: don't panic (;)), but let's take a look at the docs first: (It's not as much reading as it seems). Second: panic!!! :twisted: :lol: ;)
If after the "macro" directive you enclose some group of arguments' names in

square brackets, it will allow giving more values for this group of arguments
when using that macroinstruction. Any more argument given after the last
argument of such group will begin the new group and will become the first
argument of it. That's why after closing the square bracket no more argument
names can follow. The contents of macroinstruction will be processed for each
such group of arguments separately. The simplest example is to enclose one
argument name in square brackets:

macro stoschar [char]
{
mov al,char
stosb
}

This macroinstruction accepts unlimited number of arguments, and each one
will be processed into these two instructions separately. For example
"stoschar 1,2,3" will be assembled as the following instructions:

mov al,1
stosb
mov al,2
stosb
mov al,3
stosb
......
"forward", "reverse" and "common" directives divide macroinstruction into
blocks, each one processed after the processing of previous is finished. They
differ in behavior only if macroinstruction allows multiple groups of
arguments. Block of instructions that follows "forward" directive is processed
for each group of arguments, from first to last - exactly like the default
block (not preceded by any of these directives). Block that follows "reverse"
directive is processed for each group of argument in reverse order - from last
to first. Block that follows "common" directive is processed only once,
commonly for all groups of arguments. Local name defined in one of the blocks
is available in all the following blocks when processing the same group of
arguments as when it was defined, and when it is defined in common block it is
available in all the following blocks not depending on which group of
arguments is processed.

The first macro showed is this:
macro stoschar [char]

{
mov al,char
stosb
}

It could be written as:
macro stoschar [char]

{
forward
mov al,char
stosb
}

what forward does is that for each argument in char (in the example is three arguments: 1, 2 and 3) is perfomes the code untill either:
1) The macro end.
2) forward, reverse or common is encountered.
The revese does the same as forward, but it starts with the last argument in .


macro stoschar [char] {
reverse
mov al,char
stosb
}
stoschar 1,2,3
;above would be assembled as:
mov al,3
stosb
mov al,2
stosb
mov al,1
stosb


common is only processed one, where as forward and common is processed for every argument in .

Here is another example from the docs:
    macro stdcall proc,[arg]

{
reverse push arg
common call proc
}

;can also be written as:
macro stdcall proc,[arg] {
reverse
push arg
common
call proc
}

stdcall AnyProc, 1,2,3

What happens here is:
First, for every argument in starting with the last argument do this:
"push arg" (where arg is the "current" argument in , in the first "pass" in the macro arg will be 3, in the second "pass" arg will be 2, and in the last it will be 1).
Then, do this (once): "call proc" (where proc will be equal to AnyProc).

So in short, "stdcall AnyProc, 1,2,3" it will compile as:
push 3

push 2
push 1
call AnyProc


I attach an example file, it contains an example of the use of but with one difference, take a look and see :)
(btw, compile the file with this command: "fasm test.asm tmp.htm" and open it in a web browser)
Posted on 2003-09-30 10:29:40 by scientica
Thanks scientica! I grabbed it from here:grin:
Posted on 2003-09-30 23:36:06 by pentagenius