flat assembler
Message board for the users of flat assembler.

Index > DOS > macro usage

Author
Thread Post new topic Reply to topic
daluca



Joined: 05 Nov 2005
Posts: 86
daluca 13 Nov 2005, 17:22
How can i make some code in a macro be assembled
the first time the macro is used and other piece
of code in the later usage of that macro like:

Code:
;macrofill.inc

macro fill op1,op2,op3
{ if used fill
         ;code....(usage of op1,op2,op3)
         ;code....
         db 'macro fill is already used',13,10
  else
         ;code....(usage of op1,op2,op3)
         ;code....
         db 'macro fill is not used,will be now...',13,10
  end if
}
    

so if i make a simple bin file like this:

include 'macrofill.inc'
fill
fill
fill

i will get a file like this:
macro fill is not used,will be now...
macro fill is already used
macro fill is already used

i use the example above but i get:

macro fill is not used,will be now...
macro fill is not used,will be now...
macro fill is not used,will be now...

how can i solve this?
why the 'used fill' always returns false?
i supouse is something with the preprocesor thing right?
but then how can i acomplish this task?
thanks.....
Post 13 Nov 2005, 17:22
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 13 Nov 2005, 20:44
Try this:
Code:
;macrofill.inc

macro fill op1,op2,op3
{ if defined fill
         ;code....(usage of op1,op2,op3)
         ;code....
         display 'macro fill is already used',13,10
  else
         ;code....(usage of op1,op2,op3)
         ;code....
         display 'macro fill is not used,will be now...',13,10
  end if
  fill = 1
}

fill
fill
fill    


I have a question too, exactly why FASM can't generete the code when something that below appears?
Code:
if ~defined foo
foo = 1
end if    


I suppose this happends because the maximun number of passes is exceded, but why?
Post 13 Nov 2005, 20:44
View user's profile Send private message Reply with quote
daluca



Joined: 05 Nov 2005
Posts: 86
daluca 14 Nov 2005, 05:33
hey¡ thank you that's exactly what i needed
Post 14 Nov 2005, 05:33
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
revolution 14 Nov 2005, 06:09
Code:
if ~defined foo 
foo = 1 
end if    


Start of first pass: foo = undefined
End if first pass: foo = 1
Start of second pass: foo = defined (as 1)
End of second pass: foo = undefined (the IF was skipped)
Start of third pass: foo = undefined ....
etc.

In case you were not aware the way to solve the problem is like this:
Code:
if ~defined foo | defined here
foo = 1
here = 1
end if     
Post 14 Nov 2005, 06:09
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 14 Nov 2005, 11:37
What fool I am, I didn't see that :@

Thanks revolution!!!
Post 14 Nov 2005, 11:37
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 19 Jan 2006, 02:01
Hey wait a minute, my code is a sh*t.

This
Code:
fill
fill    
displays
Code:
macro fill is not used,will be now...
macro fill is already used    
but this
Code:
fill    
displays
Code:
macro fill is already used    


(no idea of how to fix it)
Post 19 Jan 2006, 02:01
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 19 Jan 2006, 08:01
When you define constant only once, it can be forward-referenced. Since "defined"
fasm manual, 2.2.1 wrote:
checks whether the given expression contains only symbols that are defined in the source and accessible from the current position
it will give you true also when it is defined after. To fix it, you have to make sure that it cannot be forward-referenced, like:
Code:
macro fill op1,op2,op3
{ if defined fill
         ;code....(usage of op1,op2,op3)
         ;code....
         display 'macro fill is already used',13,10
  else
         ;code....(usage of op1,op2,op3)
         ;code....
         display 'macro fill is not used,will be now...',13,10
  end if
  fill = 1
  fill = 1
}    

But in my opinion much better would be just to use the value of "fill" instead of checking whether it's accessible:
Code:
fill = 0
macro fill op1,op2,op3
{ if fill
         ;code....(usage of op1,op2,op3)
         ;code....
         display 'macro fill is already used',13,10
  else
         ;code....(usage of op1,op2,op3)
         ;code....
         display 'macro fill is not used,will be now...',13,10
  end if
  fill = 1
}    
Isn't it clearer this way?

And for your other (earlier) problem, read the section 2.2.5
Post 19 Jan 2006, 08:01
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 21 Jan 2006, 22:31
I like more the first one

Thanks Tomasz

PS: Sorry for reply late, my phone/ADSL service was unavailable from thursday morning...
Post 21 Jan 2006, 22:31
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 21 Jan 2006, 23:14
But the first one requires to know to understand how does it work - the "defined" was introduced rather for other appliances.
Post 21 Jan 2006, 23:14
View user's profile Send private message Visit poster's website Reply with quote
daluca



Joined: 05 Nov 2005
Posts: 86
daluca 22 Jan 2006, 07:50
well I like more the second one: it is clearer
Post 22 Jan 2006, 07:50
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.