flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
FrozenKnight 17 Jan 2006, 09:56
How would i check to see if a constant was less than or equil to a value?
|
|||
![]() |
|
Tomasz Grysztar 17 Jan 2006, 10:28
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). |
|||
![]() |
|
Tomasz Grysztar 18 Jan 2006, 10:02
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. |
|||
![]() |
|
FrozenKnight 18 Jan 2006, 21:03
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 {} 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. |
|||
![]() |
|
Tomasz Grysztar 18 Jan 2006, 22:16
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. |
|||
![]() |
|
FrozenKnight 19 Jan 2006, 11:10
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. |
|||
![]() |
|
Tomasz Grysztar 19 Jan 2006, 11:51
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.)
|
|||
![]() |
|
Tomasz Grysztar 19 Jan 2006, 12:09
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. |
|||
![]() |
|
revolution 19 Jan 2006, 12:39
Quote: Here's a small juxtaposition, hope it makes it all less confusing to you: |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.