flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Macro tutorials -- continuation

Author
Thread Post new topic Reply to topic
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica 30 Sep 2003, 15:25
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):
prana wrote:
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 (Wink), but let's take a look at the docs first: (It's not as much reading as it seems). Second: panic!!! Twisted Evil Laughing Wink
Code:
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:
Code:
macro stoschar [char]
{
   mov al,char
   stosb
}    

It could be written as:
Code:
macro stoschar [char]
{
forward
   mov al,char
   stosb
}    

what forward does is that for each argument in char (in the example [char] 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 [char].
Code:
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 [char].

Here is another example from the docs:
Code:
    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 [arg] starting with the last argument do this:
"push arg" (where arg is the "current" argument in [arg], 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:
Code:
push 3
push 2
push 1
call AnyProc    


I attach an example file, it contains an example of the use of [var] but with one difference, take a look and see Smile
(btw, compile the file with this command: "fasm test.asm tmp.htm" and open it in a web browser)

_________________
... a professor saying: "use this proprietary software to learn computer science" is the same as English professor handing you a copy of Shakespeare and saying: "use this book to learn Shakespeare without opening the book itself.
- Bradley Kuhn
Post 30 Sep 2003, 15:25
View user's profile Send private message Visit poster's website Reply with quote
prana



Joined: 28 Aug 2003
Posts: 51
prana 06 Oct 2003, 04:13
One problem I am having while I tried to download the IDAFree.zip Privalov has recomended in some other thread to see a disassembly. I d/loaded it twice (size 12230K) but Winzip is unable to open it Sad

Did anyone face the same problem?
Post 06 Oct 2003, 04:13
View user's profile Send private message Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: US
coconut 09 Apr 2004, 01:36
d/led fine for me, but it has a rather old dos/console interface that is pretty awkward to work with. have you tried PVDasm at

http://pvdasm.anticrack.de/index.php
Post 09 Apr 2004, 01:36
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 09 Feb 2005, 13:27
also don't forget about my tutorial http://decard.net/?body=tajga&chapter=preproc
Post 09 Feb 2005, 13:27
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Nikolay Petrov



Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
Nikolay Petrov 09 Feb 2005, 20:33
vid wrote:
also don't forget about my tutorial http://decard.net/?body=tajga&chapter=preproc

Good tutorial vid, very good Smile

macro eax b
{
local i
i b
mov eax,i
}
section.....

eax = 5+7
mov eax,5
... Smile
fasm is great...
Post 09 Feb 2005, 20:33
View user's profile Send private message Reply with quote
mr_luc



Joined: 15 Jun 2005
Posts: 3
mr_luc 15 Jun 2005, 19:01
I thought that this was going to be about continuations, and I clicked it in utter disbelief, my brain already numb from anticipated complexity ... now I feel almost disappointed! Very Happy (But not quite, because I'm not too proud to say that much ASM still makes my head throb).
Post 15 Jun 2005, 19:01
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.