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 |
|
revolution 19 Dec 2009, 07:07
Try with 'match'
Code: match any[address],b { if address=56 ... } |
|||
19 Dec 2009, 07:07 |
|
Azu 19 Dec 2009, 07:14
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 |
|||
19 Dec 2009, 07:14 |
|
revolution 19 Dec 2009, 07:22
Don't forget the backslashes if you are embedding match inside a macro.
|
|||
19 Dec 2009, 07:22 |
|
Azu 19 Dec 2009, 07:35
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." Please help.. |
|||
19 Dec 2009, 07:35 |
|
revolution 19 Dec 2009, 07:47
Show your test code. We have no idea what you are compiling.
|
|||
19 Dec 2009, 07:47 |
|
Azu 19 Dec 2009, 07:54
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 |
|||
19 Dec 2009, 07:54 |
|
revolution 19 Dec 2009, 07:56
backslash goes before the '{', not before 'match'.
'test' is a CPU instruction. |
|||
19 Dec 2009, 07:56 |
|
Borsuc 19 Dec 2009, 23:50
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 _________________ Previously known as The_Grey_Beast |
|||
19 Dec 2009, 23:50 |
|
Azu 20 Dec 2009, 01:47
revolution wrote: backslash goes before the '{', not before 'match'. 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? 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. 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? |
|||
20 Dec 2009, 01:47 |
|
kohlrak 20 Dec 2009, 05:11
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. |
|||
20 Dec 2009, 05:11 |
|
Tomasz Grysztar 20 Dec 2009, 11:06
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. And before I finish that document, you may find some advanced explanations on "match" directive in this thread: Better explanation of the match directive. |
|||
20 Dec 2009, 11:06 |
|
Borsuc 20 Dec 2009, 16:56
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? 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 ) 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... If it doesn't match then it is skipped. _________________ Previously known as The_Grey_Beast |
|||
20 Dec 2009, 16:56 |
|
kohlrak 20 Dec 2009, 23:23
Tomasz Grysztar wrote:
Match is the one that scares me the most, but other things scare other programmers (seems everyone's scared by match though ). 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. |
|||
20 Dec 2009, 23:23 |
|
Azu 20 Dec 2009, 23:49
Borsuc wrote:
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. |
|||
20 Dec 2009, 23:49 |
|
Azu 21 Dec 2009, 02:41
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.. |
|||
21 Dec 2009, 02:41 |
|
Borsuc 21 Dec 2009, 04:08
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 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 |
|||
21 Dec 2009, 04:08 |
|
Azu 21 Dec 2009, 04:30
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? |
|||
21 Dec 2009, 04:30 |
|
revolution 21 Dec 2009, 05:14
Borsuc wrote: anyone got a better solution? 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 |
|||
21 Dec 2009, 05:14 |
|
Azu 21 Dec 2009, 05:32
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? |
|||
21 Dec 2009, 05:32 |
|
Goto page 1, 2, 3 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.