flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > another FASMG question: odd behavior (XCALM) asm mvstruc..

Author
Thread Post new topic Reply to topic
fabbel



Joined: 30 Oct 2012
Posts: 83
fabbel 07 Jul 2023, 12:04
Hello Tomasz,

small below code snippet doesn't seem to work as expected - can u pls have a look... what am I missing ?
=> this printouts '** STEST2' where I would have expected '* STEST1'


Code:
include 'utility/xcalm.inc'

calminstruction (lbl) STEST1
                display '* STEST1'
                display 13
                display 10
end calminstruction

calminstruction (lbl) STEST2
                display '** STEST2'
                display 13
                display 10
end calminstruction


calminstruction test
        local _cmd

                asm mvstruc STEST2, STEST1

                arrange _cmd, =foo  =STEST2
                assemble _cmd
end calminstruction

test
    


......it looks as if 'asm mvstruc STEST2, STEST1' is ignored ??
Post 07 Jul 2023, 12:04
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8346
Location: Kraków, Poland
Tomasz Grysztar 07 Jul 2023, 12:25
The "mvstruc STEST2, STEST1" command is interpreted within the local context of "test" instruction, and therefore it's target is interpreted as a symbol in that local namespace, not the global one. Naming the target of "mvstruc" is like defining a new instruction - it therefore creates a new symbol locally. You can observe the same effect with a simple assignment, too:
Code:
STEST1 = '* STEST1'
STEST2 = '* STEST2'

calminstruction test
                asm STEST2 = STEST1 ; defines a local STEST2
end calminstruction

test
display STEST2    
To refer to the symbol in the global namespace, you would need to make the text of executed command use the outer context. The simplest way is to define the text outside and execute it with plain ASSEMBLE:
Code:
_test equ mvstruc STEST2, STEST1

calminstruction test
        local _cmd

                assemble _test

                arrange _cmd, =foo  =STEST2
                assemble _cmd
end calminstruction

test    


A more sophisticated option would be to create a symbolic link to symbol in the right context and then use the value of that link to embed the chosen context exactly at the point where you need it:
Code:
link_to_global_STEST2 equ STEST2

match global_STEST2, link_to_global_STEST2

        calminstruction test
                local _cmd

                asm mvstruc global_STEST2, STEST1

                arrange _cmd, =foo  =STEST2
                assemble _cmd
        end calminstruction

end match

test    
This might be useful when you need to mix references to different context within the text of a single command, etc.
Post 07 Jul 2023, 12:25
View user's profile Send private message Visit poster's website Reply with quote
fabbel



Joined: 30 Oct 2012
Posts: 83
fabbel 07 Jul 2023, 14:04
ok ok .. tx

.. last point though..
... cudn't i simply use # prefix ?
typ:
asm mvstruc #STEST2, STEST1 ?
Post 07 Jul 2023, 14:04
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8346
Location: Kraków, Poland
Tomasz Grysztar 07 Jul 2023, 14:56
fabbel wrote:
ok ok .. tx

.. last point though..
... cudn't i simply use # prefix ?
typ:
asm mvstruc #STEST2, STEST1 ?
The "#" would still be in the same context, it would not change anything.

It would work the other way around if you used it in the last example, though:
Code:
asm mvstruc #global_STEST2, STEST1    
There the prefix would have the local context, forcing the whole identifier to become local, even though the rest of the identifier would carry the global context from symbolic link.
Post 07 Jul 2023, 14:56
View user's profile Send private message Visit poster's website Reply with quote
fabbel



Joined: 30 Oct 2012
Posts: 83
fabbel 07 Jul 2023, 15:35
ok tx for clarifying
Post 07 Jul 2023, 15:35
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.