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: 8359
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
bitRAKE



Joined: 21 Jul 2003
Posts: 4073
Location: vpcmpistri
bitRAKE 30 Apr 2023, 11:56
This example also makes clear an interesting distinction of fasmg:

From a HLL perspective instructions are often thought about as larger puzzle pieces - containing their parameter syntax. Whereas in fasmg a symbol can pass the instruction test and later fail to match parameter requirements during use.

For example, the DQ instruction cannot be used on a line by itself - that is invalid. This does not cause DQ to be interpreted as not an instruction, but an invalid use of a defined instruction.

DQ can be used as not an instruction by prefixing it with a question mark - ?DQ will be seen as a label.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 30 Apr 2023, 11:56
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.