flat assembler
Message board for the users of flat assembler.

Index > Main > [fasmg] Troubles with defined/definite

Author
Thread Post new topic Reply to topic
Calanor



Joined: 19 Jul 2015
Posts: 35
Location: Sweden
Calanor
I'd like to use a variable as the argument to be sent to "format", e.g. "define var PE64 GUI". First I need to check if "var" has been defined at all. However, as the name of the variable is replaced with its value, defined/definite gets cranky about the extra "GUI" at the end of the line. Is there any way to solve this without resorting to match etc?

[Edit] Guess I am rusty, I forgot about "match =var, var". However, I still need to send the contents of "var" to format. As of now, I am using CALM to arrange and assemble the line, but I feel that I might be missing/forgetting something here.
Post 13 Jan 2021, 16:33
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7990
Location: Kraków, Poland
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.
Post 13 Jan 2021, 17:05
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7990
Location: Kraków, Poland
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    
Post 13 Jan 2021, 17:13
View user's profile Send private message Visit poster's website Reply with quote
Calanor



Joined: 19 Jul 2015
Posts: 35
Location: Sweden
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 Smile Thanks!
Post 13 Jan 2021, 17:22
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7990
Location: Kraków, Poland
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    
Post 13 Jan 2021, 17:23
View user's profile Send private message Visit poster's website Reply with quote
Calanor



Joined: 19 Jul 2015
Posts: 35
Location: Sweden
Calanor
I did use transform, but it never occurred to me to actually check the flag. Interesting approach!
Post 13 Jan 2021, 17:27
View user's profile Send private message 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.