flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > A problem with defining a macroinstruction [equ if match]

Author
Thread Post new topic Reply to topic
Sasha



Joined: 17 Nov 2011
Posts: 93
Sasha
I defined the macroinstruction this way, and it worked ok.
Code:
        macro Exit arg1{
                if arg1 eq
                        invoke  ExitProcess, eax
                else
                        invoke  ExitProcess, arg1
                end if
        }                          
    


But in the case of more complex function calls I don't want to write this code twice and I tested this option:
Code:
        arg2 equ eax
        push arg2               
    

This code has been compiled ok.
But in case of using this inside the macroinstruction like this
Code:
        macro Exit arg1{
                if arg1 eq
                        tmp1 equ eax
                else
                        tmp1 equ arg1
                end if              
                invoke  ExitProcess, tmp1
        }
    

The fasm compiled it without any errors, but I have got the wrong code like:
Code:
        call [ExitProcess]
    

Without pushing an argument!
I continued to look for a solution and did this:
Code:
        macro Exit arg1{
                if arg1 eq
                        tmp1 equ eax
                else
                        tmp1 equ arg1
                end if              
                push tmp1
        }
    

And here I get the fasm error: invalid operand. Instruction: push
So I understood that tmp1 in the case of arg1 eq is not equals to eax...
My questions are:
How can I solve this problem ?
Why fasm din't give any errors in the case of 'invoke'
Post 17 Nov 2011, 22:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17273
Location: In your JS exploiting you and your system
revolution
You can't mix equ and if like that. All of the equs are processed first before the assembler sees the ifs. A solution is to replace the if blocks with match blocks (see the docs for how to use match). That way the equs will be processed at the same time as the matches.
Post 17 Nov 2011, 23:45
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
why not just do something like this?
Code:
macro Exit arg1{
if arg1 eq
push eax
else
push arg1
end if
call [ExitProcess]
}
    
Post 17 Nov 2011, 23:49
View user's profile Send private message Visit poster's website Reply with quote
Sasha



Joined: 17 Nov 2011
Posts: 93
Sasha
edfed wrote:
why not just do something like this?
Code:
macro Exit arg1{
if arg1 eq
push eax
else
push arg1
end if
call [ExitProcess]
}
    


May be it's a good idea, but not for a procs with many arguments, i think..
And I want to stay with invoke. Thank you for explanation.
Post 18 Nov 2011, 00:13
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.

Powered by rwasa.