flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Tomasz Grysztar
You cannot use DEFINED/DEFINITE operators to check the status of symbolic variables, because they are preprocessed before the text of the condition is evaluated. So if you "define var PE GUI", then "if definite var" becomes "if definite PE GUI" before the condition is evaluated, and you end up actually checking whether symbol named "PE" has been defined, with "GUI" appended at the end of condition and causing a syntax error. This actually ends up working quite similarly as it was in fasm 1 with regard to symbolic variables and expression evaluation.
However if you are using CALM, there is a simple trick that allows to check whether a symbol has a value assigned, even a symbolic one. See what the manual says about the TAKE command: fasmg manual, section 15 wrote: If the destination symbol is the same as source, the result flag can be used to check whether there is an available value without affecting it. |
|||
![]() |
|
Tomasz Grysztar
A simple demonstration:
Code: define var ; this is to make CALM code see "var" as global symbol calminstruction Format take var,var jyes use_var ; here handle a case when var is not defined exit use_var: local cmd arrange cmd, =format var assemble cmd end calminstruction restore var ; remove temporary definition ; now test it: define var PE GUI Format |
|||
![]() |
|
Calanor
I resorted to using "match =var, var", followed by the "default" format if no specific one was defined. If the match is false, some CALM-code kicks in order to properly send the argument to format. However, your solution is definitely prettier than mine
![]() |
|||
![]() |
|
Tomasz Grysztar
There is also another method, which you would use if the identifier of the symbol to check for was provided at run-time to the instruction, for example as an argument to macro. Then you can use TRANSFORM and see whether any replacement has been made:
Code: calminstruction Format symbol transform symbol jyes use_var ; here handle a case when symbol is not defined exit use_var: local cmd arrange cmd, =format symbol assemble cmd end calminstruction ; now test it: define var PE GUI Format var |
|||
![]() |
|
Calanor
I did use transform, but it never occurred to me to actually check the flag. Interesting approach!
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.