flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Passing TWO paramiters to a MACRO

Author
Thread Post new topic Reply to topic
janequorzar



Joined: 11 Sep 2010
Posts: 60
janequorzar 25 Sep 2010, 21:15
Hello folks, got a Syntax problem I cannot solve.

I use the command in FASM like soo :

include 'macro.inc'

getresult 3,4

then it calls this macro

( this is the MACRO.INC file )

macro getresult onenumber,secondnumber
{
mov ax,160 ; What we are trying to do is multiply
mov bx,[onenumber] ; 160 * [onenumber] = ?
mul bx
mov bx,ax
mov ax,2 ; What we are trying to do is multiply
mov cx,[secondnumber] ; 2 * [secondnumber] = ?
mul cx
add ax,bx ; Add the totals together and send it
mov [totalanswer],ax ; to [totalanswer]
}


the problem is, its not passing 3,4 to the two paramiters :
onenumber and secondnumber.

This is a FASM syntax problem that I have not been able to find
an aswer too anywhere on the Forums or Guide. Anyone know the
proper way on how to write this to make it work ?

NOTE : I have put direct Numbers in place of [onenumber] and
[secondnumber] and this math works just fine.
Post 25 Sep 2010, 21:15
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 25 Sep 2010, 23:35
Code:
somevariable dw ?

macro getresult onenumber,secondnumber,totalanswer {
    ;... do computations
    mov [totalanswer],ax
}

getresult 3,4,somevariable    
Post 25 Sep 2010, 23:35
View user's profile Send private message Visit poster's website Reply with quote
janequorzar



Joined: 11 Sep 2010
Posts: 60
janequorzar 25 Sep 2010, 23:47
revolution wrote:
Code:
somevariable dw ?

macro getresult onenumber,secondnumber,totalanswer {
    ;... do computations
    mov [totalanswer],ax
}

getresult 3,4,somevariable    


Sadly, I have tried that ( your code as well ) and it still doesn't pass the parameters. total answer is what i'm trying to obtain, but it needs onenumber and secondnumber to bring the numbers in. It wont for some reason.

not sure what the problem is.
Post 25 Sep 2010, 23:47
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 25 Sep 2010, 23:56
Macros replace parameters by text substitution. So looking at your code now I see that you have used mov bx,[onenumber] which is replaced by the macro to mov bx,[3]. If you want to pass numeric values and not variable addresses then use mov bx,onenumber without the square brackets.
Post 25 Sep 2010, 23:56
View user's profile Send private message Visit poster's website Reply with quote
janequorzar



Joined: 11 Sep 2010
Posts: 60
janequorzar 26 Sep 2010, 00:03
revolution wrote:
Macros replace parameters by text substitution. So looking at your code now I see that you have used mov bx,[onenumber] which is replaced by the macro to mov bx,[3]. If you want to pass numeric values and not variable addresses then use mov bx,onenumber without the square brackets.


That worked PERFECTLY !!! Thank you.. I got rid of the somevariable.. didn't need it. Now I can just use getresult 1,6 or whatever numbers I want and it does what I need it to do.. awesome man.. thank you.. Smile
Post 26 Sep 2010, 00:03
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.