flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > equ irps argument name

Author
Thread Post new topic Reply to topic
alwaysnub



Joined: 30 Mar 2013
Posts: 26
alwaysnub
I cant seem to find a way to save the current argument of irps.
for example:

Code:
macro mTest label,[arg]
{
    CurrentLoop equ 0
    irps symb,arg
    \{
        if CurrentLoop = 0
            Blah1 equ symb
        else if CurrentLoop = 2
            Blah2 equ symb
        end if
        rept 1 x:CurrentLoop+1 \\{ CurrentLoop equ x \\}
    \}
    CMP Blah1,Blah2
}

mTest 0, EAX = 0    


always says CMP Blah1,Blah2 is an invalid operande.
Post 07 Apr 2013, 02:30
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2940
Location: vpcmipstrm
bitRAKE
FASM preprocesses the source file and then assembles the result. It is very important to make a clear distinction between these two realms of FASM. For all intents the preprocessor manipulates only strings. Which includes: MACRO, IRPS, EQU, etc. (see the manual)

The preprocessor doesn't know what IF/ELSE/END IF are - skips right over them looking for something to preprocess. So, you see, something other than what you intend is happening. By the time the IFs are examined by the assembler, all the EQUs have been resolved.

The listing tool which comes with FASM might assist at better examining the output at another level.

_________________
¯\(°_o)/¯ unlicense.org
Post 07 Apr 2013, 04:41
View user's profile Send private message Visit poster's website Reply with quote
alwaysnub



Joined: 30 Mar 2013
Posts: 26
alwaysnub
Ok its fixed.

Code:
macro mTest label,[arg]
{
    CurrentLoop equ 0
    irps symb,arg
    \{
        match =0, CurrentLoop
        \\{
            v1 equ symb
        \\}
        match =2, CurrentLoop
        \\{
            v2 equ symb
        \\}
        rept 1 x:CurrentLoop+1 \\{ CurrentLoop equ x \\}
    \}
    CMP v1,v2
}    
Post 07 Apr 2013, 17:04
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
alwaysnub,

Due to implicit forward, irps is superfluous.
Post 07 Apr 2013, 18:58
View user's profile Send private message Reply with quote
alwaysnub



Joined: 30 Mar 2013
Posts: 26
alwaysnub
ok.. but il stick with it for now.

I'm having a problem thats related to a problem on one of my other posts.
I'm trying to add on to an equ, for example:

Code:
macro JPCOND label,arg
{
    JMPCONDITION equ JN
    irps symb,arg
    \{
         match ==, symb
         \\{
               JMPCONDITION equ JMPCONDITION\\\#E
         \\}    


After debugging, i know the above code results in JMPCONDITION equ JN#E, if i remove the # it puts a space between JN and E, whitch i cant have. I have tried so many combinations of // #, but i cant get it working. Funy how something so simple can be such a pain...
Post 07 Apr 2013, 20:11
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
alwaysnub,

You don't have to try those combinations. You have to understand how (and when) preprocessor removes backslashes. Rule of thumb: match number of backslashes with that of enclosing block ({}, aha).
Post 07 Apr 2013, 20:42
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
alwaysnub
As a supplement to baldr's comment. You also should understand, that in your code expansion of JMPCONDITION on the right side is mutually exclusive with the concatenation: you can either expand the symbol or concatenate the symbol with E, in which case JMPCONDITION won't be expanded (as it becomes a different symbol JMPCONDITIONE). You can however use the match directive to first expand the symbol, and then concatenate the result of expansion within the match macroblock.

_________________
Faith is a superposition of knowledge and fallacy
Post 07 Apr 2013, 20:54
View user's profile Send private message Reply with quote
alwaysnub



Joined: 30 Mar 2013
Posts: 26
alwaysnub
Quote:
Rule of thumb: match number of backslashes with that of enclosing block ({}, aha).


Yes, i understand, but it was not working the way i wanted so i figured i would experiment Wink

Quote:
you can either expand the symbol or concatenate the symbol with E, in which case JMPCONDITION won't be expanded (as it becomes a different symbol JMPCONDITIONE).


Thats a design flaw, theres no reason i cant do both at the same time. hopfully it is addressed in the future releases of fasm. Untill then:

Code:
match JMPx, JMPCONDITION \{ JMPCONDITION equ JMPx \}    


Removes the # and results in what i wanted. Very Happy
Thanks guys!
Post 07 Apr 2013, 21:45
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
alwaysnub
Quote:
Thats a design flaw, theres no reason i cant do both at the same time.

That's not a design flaw. That's not even a limitation. There's a definition of each directive's and operator's operation. The way you combine them is just not supposed to result (according to those definitions) in what you expect.

It's like saying that there's no reason one can't maximize CPU frequency by overclocking and minimize power consumption at the same time. But there is a reason: the things just work like that.

Quote:
hopfully it is addressed in the future releases of fasm

I really doubt that, because there's actually nothing to address in this case.

_________________
Faith is a superposition of knowledge and fallacy
Post 10 Apr 2013, 21:07
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.