flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > fasm '~defined' only detects var if there is more than one.

Author
Thread Post new topic Reply to topic
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC
I am using the 'defined' operator/command (with the ~ operator) to conditionally initialize the first of potentially many variable-style labels.

when only one variable is defined then FASM doesn't register its' presence.

this macro starts the code: .init.firstCallb is a unique, forward-referenced variable that is defined in the second macro (indeed all 4 labels are defined in the second macro)
Code:
macro ORB.Fx.Header dot
    {
         ali 12, 16
         dw (dot # .end.code        - dot)/8
         dw  dot # .init.firstCallb - dot 
         dw  dot # .lastCall        - dot
         dw  dot # .function        - dot
    }    

this is the segment of code that declares the only '.init' and therefore the only '.init.firstCall':
Code:
                mov r9d, Color.white
                cal m.base.2to10l, .init    


the following is the macro that reads the non-existant '.init.firstCall' and generates the unique '.init.firstCallb' variable.
Code:
 macro ORB.Fx.Footer dot
    {
        
        if ~defined dot # .init.firstCall
            dot # .init.firstCallb = dot
            dot # .lastCall = dot
            else
            dot # .init.firstCallb = dot # .init.firstCall
            dot # .lastCall = dot # .init
        end if
        dot # .function = dot # .f
        virtual at $
            
            rali dot, line
            dot # .end.code:
            
        end virtual
    }    


finally; this is the definition of the described "cal" macro.
Code:
    macro cal dst, lab;lab is the '.init' in 'cal m.base.2to10l, .init'
    {
        if lab eq
                
                call dst
                
            else
                
                if ~ defined lab
                        
                        db 0xE8 ; the op code for CALL rel32
                        lab = $ ; .init
                        lab # .firstCall = $ ; generating .init.firstCall
                        dd ((dst) and (1 shl (32-bits.ll) - 1))
                        
    }    

I omitted the rest of the "cal" macro in the post. the full macro for "cal" begins on line 419 of 'PseudoInstructions.asm' in the set of files I'll upload next.


Description:
Download
Filename: Mathis.zip
Filesize: 300.99 KB
Downloaded: 290 Time(s)


_________________
byte me.
Post 31 Dec 2012, 22:53
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: 17279
Location: In your JS exploiting you and your system
revolution
Post 31 Dec 2012, 23:00
View user's profile Send private message Visit poster's website Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC
revolution:both of your examples involve FASM being incapable of generating the code at all... FASM successfully generates the code I've provided.

_________________
byte me.
Post 31 Dec 2012, 23:28
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: 17279
Location: In your JS exploiting you and your system
revolution
BAiC wrote:
revolution:both of your examples involve FASM being incapable of generating the code at all...
Can you please elaborate. I have not seen any problem.
Post 31 Dec 2012, 23:37
View user's profile Send private message Visit poster's website Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC
revolution: FASM generated the code I gave it but the constants were wrong.

but anyway... nevermind; I've switched my code over to a token method which is working as needed. only took a few minutes to replace "if ~ defined lab" with "if lab = -1" .. and adding a "lab = -1" to the first macro (the header section).
Post 01 Jan 2013, 00:39
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
BAiC
Quote:
Code:
if ~ defined lab 
                         
                        db 0xE8 ; the op code for CALL rel32 
                        lab = $ ; .init 
                        lab # .firstCall = $ ; generating .init.firstCall 
                        dd ((dst) and (1 shl (32-bits.ll) - 1))    

You should clearly understand, that the only situation this condition can be true is when the label lab is defined somewhere below this condition. And that happens exactly when you use the macro cal more than once.
Post 01 Jan 2013, 16:50
View user's profile Send private message Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC
l_inc: it's easy to say something is obvious after the result is clearly visible.
Post 02 Jan 2013, 16:33
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
BAiC
I answered, because you asked a question and you didn't show, that you got an answer and understood your mistake. Your question was still open and there was no "after".
Post 02 Jan 2013, 18:29
View user's profile Send private message Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC
l_inc: regardless of your intentions the words you used did not describe anything new.
Post 03 Jan 2013, 19:26
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
BAiC
You asked for an explanation of a situation you experienced. I gave it. If the explanation wasn't new for you, you shouldn't have asked.
Post 03 Jan 2013, 20:24
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 YouTube, Twitter.

Website powered by rwasa.