flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [SOLVED][fasmg]CALM replacement to irpv usage macro example

Author
Thread Post new topic Reply to topic
Jessé



Joined: 03 May 2025
Posts: 128
Location: Brazil
Jessé 05 Jul 2026, 13:34
Hello there,

Continuing with my CALM fever, I have the following macro that I use to kind of fix a problem I couldn't solve otherwise:

Code:
macro put_value dest, src
    irpv curr, src
        indx %%
        dest equ curr
        break
    end irpv
end macro
    


It is used to append a value to a variable (symbol), but I don't know in detail what else it does, I just know it just works for that case (instead of a plain 'dest equ src').
And I know it differs from:

Code:
macro put_value dest, src
    match curr, src
        dest equ curr
    end macro
end macro
    


Because the latter doesn't solve the problem.
In my case, both parameters are variable names which have their values changed very often, and their values may be many things: numbers, registers, labels, strings, sequence of several tokens, other variable or constant names, and so on.

So, is there a replacement that I should try with CALM that actually behaves like 'irpv' version of it?

My attempt (among many others) that fails to behave equally to 'irpv' version:

Code:
        calminstruction put_value dest*, src*
                local tmp, strsrc, strdest
                arrange tmp, src
                transform tmp
                publish dest, tmp
        end calminstruction
    


Also if someone can explain what differs from 'curr' value obtained from 'match' instead 'irpv', it will be of great value, continuing my learning process on fasmg.

Thanks in advance,

_________________
jesse6


Last edited by Jessé on 06 Jul 2026, 23:09; edited 1 time in total
Post 05 Jul 2026, 13:34
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4535
Location: vpcmpistri
bitRAKE 05 Jul 2026, 15:44
My thinking is that this is a result of when process takes place. The multi-pass solver does some actions immediately, some are allowed to change, and others must be done last. All are orchestrated based on class of action and location in source.

IRPV is in the "must happen now" class. MATCH is in the "we can wait" class. IRPV will also bypass if empty - very useful.

In CALM you'd need to use TAKE to achieve the same effect and handle the empty case. Other directives can get the top value, but processing the empty signal is more complicated, imho.

Have you tried TAKE dest,src?

Perhaps this pattern might help?
(Please, ignore all the extra question marks Smile)

_________________
¯\(°_o)/¯ AI may [not] have aided with the above reply.
Post 05 Jul 2026, 15:44
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8543
Location: Kraków, Poland
Tomasz Grysztar 05 Jul 2026, 16:43
Jessé wrote:
Also if someone can explain what differs from 'curr' value obtained from 'match' instead 'irpv', it will be of great value, continuing my learning process on fasmg.
Are you using this macro with variables that have numeric values, defined with "="? Because this is a special case handled by IRPV only, as explained by this passage in the manual:
fasmg manual wrote:
When a variable passed to "irpv" has a value that is not symbolic, the parameter is given a text that produces the same value upon computation. When the value is a positive number, the parameter is replaced with its decimal representation (similarly how the "%" parameter is processed), otherwise the parameter is replaced with an identifier of a proxy symbol holding the value from stack.
And this is likely the difference between the two that is relevant for you.

Your CALM attempt therefore fails because it only handles the symbolic variables and not numeric ones. You need separate paths for these two cases, something like:
Code:
        calminstruction put_value dest*, src*
                local tmp
                match src.equ, src, .
                jyes symbolic
            numeric:
                compute tmp, src
                publish dest, tmp
                exit
            symbolic:
                transform src
                publish dest, src
        end calminstruction    
Post 05 Jul 2026, 16:43
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8543
Location: Kraków, Poland
Tomasz Grysztar 05 Jul 2026, 16:48
Wait, this can be done much simpler:
Code:
        calminstruction put_value dest*, src*
                transform src
                jyes symbolic
                compute src, src
            symbolic:
                publish dest, src
        end calminstruction    
Post 05 Jul 2026, 16:48
View user's profile Send private message Visit poster's website Reply with quote
Jessé



Joined: 03 May 2025
Posts: 128
Location: Brazil
Jessé 06 Jul 2026, 23:02
bitRAKE wrote:
My thinking is that this is a result of when process takes place. The multi-pass solver does some actions immediately, some are allowed to change, and others must be done last. All are orchestrated based on class of action and location in source.

IRPV is in the "must happen now" class. MATCH is in the "we can wait" class. IRPV will also bypass if empty - very useful.

In CALM you'd need to use TAKE to achieve the same effect and handle the empty case. Other directives can get the top value, but processing the empty signal is more complicated, imho.

Have you tried TAKE dest,src?

Perhaps this pattern might help?
(Please, ignore all the extra question marks Smile)


Thank you for the explanations.
Yes, I've tried several of those directives under CALM (including 'take'), but have not found myself one that works. But, it is a blind test, because there are several things I still need to figure out before recognizing myself as someone who understands CALM under fasmg fluently.
But, as always, I just start it by trying and trying again. Wink
I must also admit that I need to review the whole thing I'm trying to adapt to CALM (as much as I can), because, as it is now, I just did something big, without that much experience.
Anyways, I got a lot of success, converting some internals to CALM, and they're already behaving as I expect.

_________________
jesse6
Post 06 Jul 2026, 23:02
View user's profile Send private message Visit poster's website Reply with quote
Jessé



Joined: 03 May 2025
Posts: 128
Location: Brazil
Jessé 06 Jul 2026, 23:08
Tomasz Grysztar wrote:
Wait, this can be done much simpler:
Code:
        calminstruction put_value dest*, src*
                transform src
                jyes symbolic
                compute src, src
            symbolic:
                publish dest, src
        end calminstruction    


The answer is yes, I'm using it with numeric, as well as symbolic variables.
The code suggested worked fine, and I have (for now) replaced my aforementioned 'irpv' block. 0 issues so far.
Thanks for the valuable explanation.

_________________
jesse6
Post 06 Jul 2026, 23:08
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-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.