flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > How to get the address in something passed?

Goto page 1, 2, 3  Next
Author
Thread Post new topic Reply to topic
Azu



Joined: 16 Dec 2008
Posts: 1160
Azu
Here is an example of what I'm trying to do

Code:
macro blah a,b{
if a eq 12 or b eq 12
pass1 = 1
else
if a eq 34 or b eq 34
pass2 = 1
else
if a eq 56 or b eq 56
pass3 = 1
else
if a eq 78 or b eq 78
pass4 = 1
end if
}



blah 12,dword[34]
blah dword[56],78

if pass1 & pass2 & pass3 &pass4
display "success"
else
err "failure"
end if    


I know I can use eqtype to see if something is an address, but I can't figure out how to get the address itself.

Please help..

_________________
Post 19 Dec 2009, 07:03
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
Try with 'match'
Code:
match any[address],b {
  if address=56
  ...
}    
Post 19 Dec 2009, 07:07
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1160
Azu
Thanks. I've never had much luck with match though, and again it eludes me.



Code:
match any[address],b { 
  if address=56 
end if
}    

Won't compile


Code:
match any[address],b { 
}    

Won't compile



Code:
match any[address],a { 
}    

Won't compile

Code:
match =any[address],b { 
}    

Won't compile

Code:
match address,any[b] { 
}    

Won't compile


Confused
Post 19 Dec 2009, 07:14
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
Don't forget the backslashes if you are embedding match inside a macro.
Post 19 Dec 2009, 07:22
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1160
Azu
Whoops. Thanks.


One more problem.. if I try to do any kind of comparison on address, it fails to compile. I can't check if it is higher than a number, or lower than it, or anything. e.g. if address > 1 gives "invalid value."


Oh and also, I can't set anything to it. e.g. test = address gives "reserved word used as symbol."


Confused


Please help..

_________________
Post 19 Dec 2009, 07:35
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
Show your test code. We have no idea what you are compiling.
Post 19 Dec 2009, 07:47
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1160
Azu
Code:
macro blah a,b{ 
\match any[address],b { 
if address eq
else
test = address
end if
\}
} 

blah 12,dword[34] 
blah dword[56],78     

_________________
Post 19 Dec 2009, 07:54
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
backslash goes before the '{', not before 'match'.

'test' is a CPU instruction.
Post 19 Dec 2009, 07:56
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
What's so hard about how match works?

On the right of the comma, you put the thing you want matched (i.e a symbolic constant), on the left you put TOKENS.

Have you used any pattern matching language before? That would make it much easier to grasp.

You put symbols on the left that should match symbols on the right. Of course the '=' symbol can be used to match exact LITERAL symbols (like =example) and '==' the literal = symbol, also =, for the comma symbol.

Examples (spaces are, of course, just for clarity, they don't have any meaning):

Code:
define something 55:6
match a:b, something  ; a=55, b=6

define something 2/3:5
match a/b, something  ; a=2 b=3:5 (yes more symbols, because it's at the end)

match a/b:c, something  ; a=2, b=3, c=5

match =2 / =3 a, something  ; a = 5, the 2 and 3 before are literal (i.e symbols, just like '/')

define something 3/3:5

; the match above WON'T MATCH now and will be ignored/skipped (because the literal '2' is replaced by a '3')

match a/=3:b, something  ; a=3, b=5

define something 3/4:5

match a/=3:b, something  ; WON'T MATCH
match a:=4:b, something  ; WON'T MATCH  (: instead of /)

; multiple symbols
define something 3:5/4:6

match a/b, something  ; a=3:5, b=4:6    
clear enough?

_________________
Previously known as The_Grey_Beast
Post 19 Dec 2009, 23:50
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1160
Azu
revolution wrote:
backslash goes before the '{', not before 'match'.

'test' is a CPU instruction.

Thanks.
The backslash placement doesn't matter, and I only put in "test" for the little example. It turns out the reason it wouldn't compile in my program was that sometimes I have registers as part of addresses, and I need to handle those cases specially.


Borsuc wrote:
What's so hard about how match works?

On the right of the comma, you put the thing you want matched (i.e a symbolic constant), on the left you put TOKENS.

Have you used any pattern matching language before? That would make it much easier to grasp.

Match doesn't work like any pattern matching I've used. I'm only familiar with wild cards and the various regular expression syntaxes out there. None of which are even remotely similar to the FASM match thingy.

Borsuc wrote:
You put symbols on the left that should match symbols on the right. Of course the '=' symbol can be used to match exact LITERAL symbols (like =example) and '==' the literal = symbol, also =, for the comma symbol.

Examples (spaces are, of course, just for clarity, they don't have any meaning):

Code:
define something 55:6
match a:b, something  ; a=55, b=6

define something 2/3:5
match a/b, something  ; a=2 b=3:5 (yes more symbols, because it's at the end)

match a/b:c, something  ; a=2, b=3, c=5

match =2 / =3 a, something  ; a = 5, the 2 and 3 before are literal (i.e symbols, just like '/')

define something 3/3:5

; the match above WON'T MATCH now and will be ignored/skipped (because the literal '2' is replaced by a '3')

match a/=3:b, something  ; a=3, b=5

define something 3/4:5

match a/=3:b, something  ; WON'T MATCH
match a:=4:b, something  ; WON'T MATCH  (: instead of /)

; multiple symbols
define something 3:5/4:6

match a/b, something  ; a=3:5, b=4:6    
clear enough?

Thanks, that wasn't the problem though.
But just out of curiosity.. how do you go about using match with something besides punctuation? Like, say, to match anything with the letters a, b, or c? And how do I define minimum/maximum characters to match?

_________________
Post 20 Dec 2009, 01:47
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
I agree honestly. I almost feel as if someone should write a whole tutorial on match itself. Perhaps fasm should have a whole fasm macroinstructions tutorial. They're quite useful, but when you deal with things like eqtype (and are not sure where it does and doesn't work) and match, alot of people (especially people like me) tend to avoid it. IMO, the fasm manual doesn't really do the topic justice. I can say I've talked to one or two people outside of the public forums here and they've loved macro, but are just two afraid to make them because certain things they just can't figure out from the fasm manuals.

I'd write a new thing for syscalls, invokes and cinvokes for the new fasm for linux update, but honestly i'd rather know more macro writing first. That one i already wrote is just sloppy and a better one (perhaps more stable too) would probably help a bit.
Post 20 Dec 2009, 05:11
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7724
Location: Kraków, Poland
Tomasz Grysztar
kohlrak wrote:
I agree honestly. I almost feel as if someone should write a whole tutorial on match itself. Perhaps fasm should have a whole fasm macroinstructions tutorial.

This Understanding fasm was intended to cover all those topics, however I haven't got into it yet. Perhaps the next year. Wink

And before I finish that document, you may find some advanced explanations on "match" directive in this thread:
Better explanation of the match directive.
Post 20 Dec 2009, 11:06
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
Azu wrote:
But just out of curiosity.. how do you go about using match with something besides punctuation? Like, say, to match anything with the letters a, b, or c? And how do I define minimum/maximum characters to match?
First of all, match matches only symbols. Symbols are stuff like : + - / and you can use literal symbols (using = before) but you'll need a space to separate the symbol obviously.

Basically it works like pattern matching in Perl, where any non-symbol (i.e a variable you use for match to access it later) is treated as "any sequence of characters UNTIL the symbol after it is found". There's a similar thing in the NT Command Prompt in FOR /F where you use "tokens" to separate such 'variables' (by definition the tokens are symbols in the exact same way).

If you want to get all the chars to the left of a ':' and use them, use match. If you want to get all the chars between two symbols (and access them as variable), use match.

Example:

Code:
match x : y, 555:222  ; x=555, y=222

match x =symbol y, 555 symbol 222  ; x=555, y=222  (this uses a 'literal' symbol called 'symbol' as you can see Razz)

match x =a y, 555 a 222  ; x=555, y=222

match x =a y, 555 b 222  ; DOESN'T MATCH because THERE'S NO 'a' SYMBOL to be found.    


In Perl you would do:
Code:
([^:]+): (.+)  ; same as the first match, but you access x with $1 and y with $2

((?:.(?!symbol))+)symbol(.+)  ; same as second match, etc...    
basically that says "get all chars until we find the symbol and put it into $1 (or the respective var/constant in match), then get the remaining (or alternatively, if more symbols, get other chars).

If it doesn't match then it is skipped.

_________________
Previously known as The_Grey_Beast
Post 20 Dec 2009, 16:56
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
Tomasz Grysztar wrote:
kohlrak wrote:
I agree honestly. I almost feel as if someone should write a whole tutorial on match itself. Perhaps fasm should have a whole fasm macroinstructions tutorial.

This Understanding fasm was intended to cover all those topics, however I haven't got into it yet. Perhaps the next year. Wink

And before I finish that document, you may find some advanced explanations on "match" directive in this thread:
Better explanation of the match directive.


Match is the one that scares me the most, but other things scare other programmers (seems everyone's scared by match though Laughing). Though, compared to other topics, this certainly isn't top priority in my mind though. I'll take a look at those though, thank you.
Post 20 Dec 2009, 23:23
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1160
Azu
Borsuc wrote:
Azu wrote:
But just out of curiosity.. how do you go about using match with something besides punctuation? Like, say, to match anything with the letters a, b, or c? And how do I define minimum/maximum characters to match?
First of all, match matches only symbols. Symbols are stuff like : + - / and you can use literal symbols (using = before) but you'll need a space to separate the symbol obviously.

Basically it works like pattern matching in Perl, where any non-symbol (i.e a variable you use for match to access it later) is treated as "any sequence of characters UNTIL the symbol after it is found". There's a similar thing in the NT Command Prompt in FOR /F where you use "tokens" to separate such 'variables' (by definition the tokens are symbols in the exact same way).

If you want to get all the chars to the left of a ':' and use them, use match. If you want to get all the chars between two symbols (and access them as variable), use match.

Example:

Code:
match x : y, 555:222  ; x=555, y=222

match x =symbol y, 555 symbol 222  ; x=555, y=222  (this uses a 'literal' symbol called 'symbol' as you can see Razz)

match x =a y, 555 a 222  ; x=555, y=222

match x =a y, 555 b 222  ; DOESN'T MATCH because THERE'S NO 'a' SYMBOL to be found.    


In Perl you would do:
Code:
([^:]+): (.+)  ; same as the first match, but you access x with $1 and y with $2

((?:.(?!symbol))+)symbol(.+)  ; same as second match, etc...    
basically that says "get all chars until we find the symbol and put it into $1 (or the respective var/constant in match), then get the remaining (or alternatively, if more symbols, get other chars).

If it doesn't match then it is skipped.


Thanks


That isn't what I meant though


What I meant was, how would I do something like this?

|[1-5A-Dc-z]{5,20}([^Q]{5}?f?o?o?b?a?r[<>]+)[^3]*|

And process the results for each match found (not just the first one)?


I find the syntax for regular expressions so much more intuitive, and can't figure out how to do the above using match even after following the links posted above.

_________________
Post 20 Dec 2009, 23:49
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1160
Azu
Is there at least a way to use match to tell if something is a number or not? I can't use eqtype because I need to make a symbolic constant, which can't be done in an if statement...


How I'm used to, it would be like this

|([0-9]+)|




But all I know how to do with match is the most absolutely basic wildcard matching. E.G. foo*bar. I can't figure out how to do anything more advanced than that. Please help.. Confused

_________________
Post 21 Dec 2009, 02:41
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
Well if you want to loop through symbols you should use irps... but I don't think it's possible to loop through individual digits or match individual digits, if they are not separated by another symbol or space or something, then they are one symbol. It's how FASM defines symbols, I'm afraid it's not much you can do.

Likewise you can't test if it's a number with match by itself, because you can only test for a literal symbol...

well actually there might be a way, with 'rept', but it will be uber slow to loop through all possible number values and match them.

Code:
define found
rept 5 n:0
{
  match =n, something
  \{
    restore found
    define found +
  \}
}
match +,found
{
  ; it was a number
}
restore found    
anyone got a better solution? (it's obvious the above checks only for the numbers 0...5 Sad


EDIT: alternatively you could change the meaning of the 'symbolic constant' and use a normal constant as a 'trigger' in some assembly level code (not preprocessing) but that may not be possible for your specific situation.

_________________
Previously known as The_Grey_Beast
Post 21 Dec 2009, 04:08
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1160
Azu
Thank you! It works perfect for small numbers.

Two problems though;

1)
I get out of memory error on big ones, and when I try to increase the max memory for FASM to use, I wasn't able to set the max memory higher than 4194303, and it runs out of memory without making the number very big.

2)
Not a really big deal, but it seems I can only set the parameters of rept to constants, so I can't make a totally automatic solution using this method even if I can get it to work with bigger numbers somehow.


I'm trying to make macros for all the instructions that take memory operands and imms and if they are a number within a certain range I want to add their address (more specifically, the address of this operand) to a list and then put this list somewhere as one big DD..
Instead of decompiling it manually and making the list myself and recompiling with it written on the end..
But I need match because unless I use symbolic constants I can't make the list.. it won't let me concatenate the addresses.. so please is there some way with match?

_________________
Post 21 Dec 2009, 04:30
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
Borsuc wrote:
anyone got a better solution?
I don't know if is considered better, but you could always put the parameter as text (using db) in a virtual block and loop through the characters one by one.

But I think this whole approach is wrong anyway. Although fasm might be able to do these things, they are cumbersome and slow, and one is probably expecting too much of it if you have to resort to such contorted and confusing methods. Structuring your code differently will most likely make everything much easier to do and be far less confusing.
Borsuc wrote:
(it's obvious the above checks only for the numbers 0...5 Sad
Erm, 0...4? Right?
Post 21 Dec 2009, 05:14
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1160
Azu
It isn't the structure of my code, but my macros. And I don't know of any other way to structure them to achieve this.

How can I loop through them one by one and see what they are, without using anything like an if statement that makes it impossible to define symbolic constants?

_________________
Post 21 Dec 2009, 05:32
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2, 3  Next

< 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.