flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [solved] is it possible?

Author
Thread Post new topic Reply to topic
ProMiNick



Joined: 24 Mar 2012
Posts: 799
Location: Russian Federation, Sochi
ProMiNick 10 Aug 2024, 18:11
task: macro m1 with params a & C. it displays maximum of a in a sequence of m1 until the source end or until macro m2 that breaks sequence, than it displays a, than if that m1 is last one in sequence of m1 it displays "this is a last one", if not it displays "next is" and displays a passed to next m1 macro in sequence, than it displays difference with a passed to current macro and a passed to next one. all above is true for m1 with parameter C=1, for other C current member of m1 sequence is skiped off, like it never existed without breaking a sequence.
realization:
Code:
macro m1 a,b,C:1{ local next_a
        match =1,C \{
        if ~definite _MAX | _MAX<a
                _MAX = a
        end if
        display _SMAX+'0',",",a+'0',":"
        irpv linked_sym,__LINK_A \\{ common __LINK_A = a \\}
        restore __LINK_A
        __LINK_A equ next_a
        if defined next_a
        display 'next is ',next_a+'0'," "
                if a>next_a
                        display 'diff is -',(a-next_a)+'0',13,10
                else
                        display 'diff is ',(next_a-a)+'0',13,10
                end if
        else
                if ~definite _SMAX
                _SMAX=_MAX
                end if
                display 'this is a last one',13,10
        end if \}
}

macro m2 {}

m1 3
m1 1
m1 4,,0
m1 3
m1 6
m1 5

m2

m1 3
m1 1
m1 4,,0
m1 3
m1 6
m1 5    
output is:
Code:
6,3:next is 1 diff is 2
6,1:next is 3 diff is 2
6,3:next is 6 diff is 3
6,6:next is 5 diff is -1
6,5:next is 3 diff is -2
6,3:next is 1 diff is -2
6,1:next is 3 diff is 2
6,3:next is 6 diff is 3
6,6:next is 5 diff is -1
6,5:this is a last one    

trivial: contents(parameters values) of previous macro in sequence accessed in current one element - works out of the box by fasm design
reached:contents(parameters values) of next macro in sequence accessed in current one element
reached:calculations between args of current and next element of sequence allowed
reached:sequence maximum resolved in first sequence element
reached:sequence end succesfuly determined
unreached:breacking sequence with m2 macro (I no idea what m2 should do with _MAX or _SMAX symbol or m1 itself should be designed differently to make it possible.
I very apreciated for any suggestions. (the only one condition - realization must stay in fasm1 compatible syntax without fasmg not backported features)
(when i start that post _SMAX was out of scope but enclosing it in block if ~definite - helps - that idea comes just in time I publish code here )

_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
Post 10 Aug 2024, 18:11
View user's profile Send private message Send e-mail Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 799
Location: Russian Federation, Sochi
ProMiNick 10 Aug 2024, 20:09
thanks to all, you are best. I know it and I know that request of help will inspire myself in first case.
Code:
macro m2 { local _MAX,_SMAX,__LINK_A
macro m1 a,b,C:1\{ \local next_a
        match =1,C \\{
        if ~definite _MAX | _MAX<a
                _MAX = a
        end if
        display _SMAX+'0',",",a+'0',":"
        irpv linked_sym,__LINK_A \\\{ common __LINK_A = a \\\}
        restore __LINK_A
        __LINK_A equ next_a
        if defined next_a
        display 'next is ',next_a+'0'," "
                if a>next_a
                        display 'diff is -',(a-next_a)+'0',13,10
                else
                        display 'diff is ',(next_a-a)+'0',13,10
                end if
        else
                if ~definite _SMAX
                _SMAX=_MAX
                end if
                display 'this is a last one',13,10
        end if \\}
\} } m2

m1 3
m1 1
m1 4,,0
m1 3
m1 6
m1 5

m2

m1 3
m1 1
m1 4,,0
m1 3
m1 2
m1 5    

output is:
Code:
6,3:next is 1 diff is -2
6,1:next is 3 diff is 2
6,3:next is 6 diff is 3
6,6:next is 5 diff is -1
6,5:this is a last one
5,3:next is 1 diff is -2
5,1:next is 3 diff is 2
5,3:next is 2 diff is -1
5,2:next is 5 diff is 3
5,5:this is a last one    

I found answer just in text of question
Quote:
what m2 should do with _MAX or _SMAX symbol
- m2 should do they local symbols for that macro and define m1 in its body
All my targets are resolved. However I still very appreciated for improvements
like should m2 purge previous definition of m1 or not or something else.
(preprocessor speed is pretty enought 220K of strings with continuously repeated m1 sequences breached with m2 compiled via 7.4 sec, algorithm complexity - 3 passes of assembler stage)

_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
Post 10 Aug 2024, 20:09
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
revolution 11 Aug 2024, 10:20
Sometimes trying to formulate a coherent enough question to ask someone else is enough to discover the answer.

Buy a toy animal and ask it all your questions. It won't respond, of course, but it doesn't need to, you will get the answers you seek.
Post 11 Aug 2024, 10:20
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.