flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Comparing numbers with match

Author
Thread Post new topic Reply to topic
FrozenKnight



Joined: 24 Jun 2005
Posts: 128
FrozenKnight
How would i check to see if a constant was less than or equil to a value?
Post 17 Jan 2006, 09:56
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
Look here: manual, sec. 2.2.1

Unlike IF, which is an assembler's directive, MATCH is the one of preprocessor's and thus is used for different purposes (also note the difference between symbolical and numerical constants - again the one type is used by preprocessor, and the other one by assembler).
Post 17 Jan 2006, 10:28
View user's profile Send private message Visit poster's website Reply with quote
FrozenKnight



Joined: 24 Jun 2005
Posts: 128
FrozenKnight
I know what if does but i guess i'm just spoied by C and C++ compilers which can test to see if a constant has is above or below specific value to change what is included in the program. kind of like how a C++ compiler detrumans which version of a struct to use for diffrent versions of windows.
Post 18 Jan 2006, 09:26
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
In general, fasm's preprocessor is text-only, it doesn't work on any numbers (well, to be more exact, it is a token-processing in the terms explained above). The small exception is the REPT directive, and you can try doing actually some operations on numbers with a tricky usage of REPT - but in general it's rather the assembler that goes beyond the simple text processing. I would also suggest to learn to fully utilize the assembler's features before going for the advanced preprocessor's ones. Using mainly the assembler's directives gives more options to your code and allows to utilize the fasm's code resolving to find a good solution to it.

When I wrote the "Design Principles" I also noted once that I would consider writing a compiler that would have preprocessing and assembling merged into one process - what would for example allow things like defining a macros depending on the complex conditions, even defined by some labels in the code (like fasm's assembly time conditions, "if $ mod 4 = 3" etc.). This would however lead to another dialect or even whole new compile-time language, but it has one big disadvantage: the preprocessing and parsing would have to be repeated on each pass, while in fasm' approach it's only the assembly stage that is repeated. This would slow down compilation even by order of magnitude on larger projects.
Post 18 Jan 2006, 10:02
View user's profile Send private message Visit poster's website Reply with quote
FrozenKnight



Joined: 24 Jun 2005
Posts: 128
FrozenKnight
hmm that make a little since but all i really asked for was something simple maybe a 2 paramiter extention to make simple comapirsons to allow for things like correctly synchronizing with the ms structs for the diffrent dll versions.

something like say
Code:
MATCHNUM WIN32_IE >= 0x400
{}    
and let the user do all the nesting.
i don't think something simple like that would be too hard to implement. and i don't think it would require an entire new language to do. but it would alllow your assembler to be more compatable with windows.
Post 18 Jan 2006, 21:03
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
Where you've got that number defined? Wouldn't it be better to simply use textual constants? If you define it with =, it is not ossible to implement anything like that, as preprocessor cannot have access to anything that is defined at assembly time. If you define it with equ, you can aswell define constants like "SYS equ WIN40" etc. and compare them literally.

On the other hand, you can also do the checking inside instead of outside, and be allowed to use any condition in such case, like:
Code:
struc SOME_STRUC
{
  .alpha dd ?
  if VER >= 0x400
   .beta dd ?
  end if
}    

or even things like:
Code:
struc SOME_STRUC version
{
  .alpha dd ?
  if ~version eq & version >= 0x400
   .beta dd ?
  end if
}    

With the "struct" macro it won't work because of the macro tricks it does, but when you need more sophisticated and specialized definitions, it's anyway recommended to go "back to the bones" and use the "struc".
Or make "struct" variant which could do version checking for every specially marked field.

PS. Look at "match" directive more like at the RE matching than anything else.
Post 18 Jan 2006, 22:16
View user's profile Send private message Visit poster's website Reply with quote
FrozenKnight



Joined: 24 Jun 2005
Posts: 128
FrozenKnight
In the case i'm refering to it's easier to use Numaric Constants because that is how the structs were origonaly designed. would it really be that hard to set up a assemble time directive that would poerate as i said. using only numerical data and may be retrun an error if the directive didn't evaluate to a numeric constant.

BTW i dont compleatly understand your last example. your using an IF statement which i thought would perform an runtime compare. however a sstruct being held only in data would not be able to support opcodes.
could you please clarify this because it seems to violate my understanding of the 'if' directive.
Post 19 Jan 2006, 11:10
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
IF is an assembly-time compare, for run-time compare there is an ".if" macro (which is just evaluated to instructions like CMP/JE etc.)
Post 19 Jan 2006, 11:51
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
Here's a small juxtaposition, hope it makes it all less confusing to you:
Code:
                    Condition testing   Repeating              Setting variables

Preprocessing-time  MATCH               REPT/IRP/IRPS          EQU/DEFINE

Assembly-time       IF                  REPEAT/WHILE/TIMES     =/LOAD

Run-time            conditional jumps,  LOOP instruction,      MOV instruction, etc.
                    .if macro           conditional jumps,     (initial values set
                                        .while/.repeat macros  with data directives)
    


The variables for preprocessor are called symbolical constants, the assembler's variables are called numerical constants (and, in fact, all the labels are such, too). They are called constants because they are constants from the run-time point of view, but during the compilation they are in fact variables.
Post 19 Jan 2006, 12:09
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
Quote:
Here's a small juxtaposition, hope it makes it all less confusing to you:
I think you should consider putting more tables like that in the documentation. This sort of thing would help many to understand at-a-glance just what the text of the document is saying.
Post 19 Jan 2006, 12:39
View user's profile Send private message Visit poster's website 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. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.