flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Confusion with defining one macro by another (pg 75)

Author
Thread Post new topic Reply to topic
Eoin



Joined: 16 Jun 2003
Posts: 68
Location: Ireland
Eoin 16 Sep 2005, 23:42
Hi I'm undoubtly being a bit dense here but I'm trying to do something similar to what pg 75 of the pdf demonstrates...

Quote:
Code:
macro tmacro params
{
    macro params {
}

MACRO fix tmacro
ENDM fix }    


defines an alternative syntax for defining macroinstructions, which looks like:

Code:
MACRO stoschar char
    mov al,char
    stosb
ENDM    


But I want to do this so that I can do some extra things at the beginning and end, as such I really need to be able to use a macro for closing the end of the constructed one. There is something about this at the end of the page but I can't figure it out

Quote:
This might be a problem if one needed to perform some additional tasks
one the end of such definition, but there is one more feature which helps
in such cases. Namely it is possible to put any directive, instruction or
macroinstruction just after the } character that ends the macroinstruction

and it will be processed in the same way as if it was put in the next line.


Could someone show me a small example.... please and thank you.
Post 16 Sep 2005, 23:42
View user's profile Send private message Reply with quote
Remy Vincent



Joined: 16 Sep 2005
Posts: 155
Location: France
Remy Vincent 17 Sep 2005, 00:03
Shocked Macro Shocked is a waste of time, is it so hard to copy xx times the two lines... I don't know how Shocked macro Shocked works & i hope i will never have to learn this "unstick from the Code" way of programming ! Shocked

_________________
Groups lower your IQ
Post 17 Sep 2005, 00:03
View user's profile Send private message Visit poster's website Reply with quote
Eoin



Joined: 16 Jun 2003
Posts: 68
Location: Ireland
Eoin 17 Sep 2005, 00:16
Well now, macros aren't all bad. Anyway back on topic I came up with a solution;

Code:
macro tprocMacro mname,[params] {
common
        macro mname,params {
forward
        CheckParam params
common
}

macro tendpMacro {
        ; Do something here too
}

tproc fix tprocMacro
tendp fix tendpMacro }    


It is used as following;
Code:
tproc MacroCode param1,param2 
        ; Do stuff 
tendp    

Now the remaining problem is that param1 seems to be counted as part of the mname parameter and so only param2 gets passed to the CheckParam macro which is supposed to perform some preprocessing on all the parameters for the macro. I take it the lack of a comma between 'MacroCode param1' is the problem, but putting one there gives an error.
Post 17 Sep 2005, 00:16
View user's profile Send private message Reply with quote
Eoin



Joined: 16 Jun 2003
Posts: 68
Location: Ireland
Eoin 17 Sep 2005, 00:33
This seems a bit hacky, but it does work..
Code:
macro tprocMacro mname,[params] {
common
        match a b,mname \{ 
                macro a b,params {
                CheckParam b 
        \}
forward
        CheckParam params
}    

Is there a neater way?
Post 17 Sep 2005, 00:33
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 17 Sep 2005, 01:16
Quote:

Namely it is possible to put any directive, instruction or
macroinstruction just after the } character that ends the macroinstruction


This means that you can do something like:
Code:
tproc fix tprocMacro
tendp fix } tendpMacro    

And "tendpMacro" will be evaluated after finishing the definition started with "tprocMacro".
Post 17 Sep 2005, 01:16
View user's profile Send private message Visit poster's website Reply with quote
Eoin



Joined: 16 Jun 2003
Posts: 68
Location: Ireland
Eoin 19 Sep 2005, 01:49
Thank you for your reply Thomaz, the tendpMacro actually generates some code which needs to go with each instance of the generated macro as opposed to just with its definition, so the ordering tendp fix tendpMacro } works best in my case.

I am still having trouble processing the parameters though. I can't get a consistent method which will work for 0, 1 or 2+ parameters. The one I am using (above) accepts 2+ parameters only and work work with less.
Post 19 Sep 2005, 01:49
View user's profile Send private message Reply with quote
Eoin



Joined: 16 Jun 2003
Posts: 68
Location: Ireland
Eoin 19 Sep 2005, 14:49
Ok I think I've come up with a clean solution which works for the different cases.
Code:
macro tprocMacro name,[param] {
common
        macro name param {
if ~ param eq
        forward
                ; Parameter processing here
        common
end if
}

macro tendpMacro {
        ; End stuff here
}

tproc fix tprocMacro
tendp fix tendpMacro }    

In the end it seems quite simple, but sure thats what yo want.
Post 19 Sep 2005, 14:49
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.