flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [fasmg] Trick to detect if an instruction is defined

Author
Thread Post new topic Reply to topic
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8103
Location: Kraków, Poland
Tomasz Grysztar 25 Jan 2023, 11:51
I think I never mentioned this before, but there is a simple trick that uses an unconditional label interceptor to detect whether something is a name of an existing instruction:
Code:
struc (present) instruction? name*
        present = 1
        calminstruction (label) ?! any&
                compute present, 0
        end calminstruction
        if 0
                name
        end if
        restruc ?
end struc

macro try name
        is instruction name
        display `name,' is ',string (is xor 1)*'NOT ','defined as instruction.',13,10
end macro

try dq
try dqq
try dqqq    
Because the interceptor is unconditional, it is executed even inside the "if 0" block, but only when the initial symbol of the line is considered a label, which implies that it is not recognized as an existing instruction.

I'm posting this as I'm designing a new set of CALM-specific operations that may allow to perform checks of this kind in an "official" and reliable way. Still, I think it's an interesting trick that demonstrates how some of fasmg's cogs intertwine.
Post 25 Jan 2023, 11:51
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-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.