flat assembler
Message board for the users of flat assembler.

 Index > Main > Counter in macro. How do?
Author
Roman

Joined: 21 Apr 2012
Posts: 1718
Roman 17 Jul 2013, 11:26
I have 2+3/2-9.
Macro must have counter. Counter shows (in my example) what number is the division sign.

If look my example 2+3/2-9 we see / must have counter= 4. I mean in my 2+3/2-9 division is the fourth operation. This must show counter.
Macro work now !
Quote:

struc Parse [A] {

common

Count2 = 48
Cou = 48
. equ
irps B,A \{
Cou = Cou + 1
__out equ B
match +,B \\{ restore __out

__out equ , \\}
match -,B \\{ restore __out

__out equ , \\}
match *,B \\{
Count2 = Cou \\}
match C,__out \\{
match D,. \\\{

restore .
. equ D\\\#C
\\\}
match ,. \\\{
restore .
. equ C
\\\}
\\}
restore __out
\} }

In code write:
x Parse 2+3/2-9
display Count2 ;Count2 show number of division in my example.
display 13,10
display Cou ;Cou show len of example. Show 7
display 13,10
17 Jul 2013, 11:26
Roman

Joined: 21 Apr 2012
Posts: 1718
Roman 17 Jul 2013, 12:03
New problem.
Count2 work. But if we have this:
2-2*2-3*4
We get Count2 =8 it right. But in 2-2*2-3*4 we have another mul and number first mul = 4.
How restore or what do to have in Count2 two numbers. I mean Coun2=8 and after restore (but restore Count2 not work !) have Count2=4.
17 Jul 2013, 12:03
baldr

Joined: 19 Mar 2008
Posts: 1651
baldr 17 Jul 2013, 12:50
Roman,

Fourth operation or fourth token? Because latter is as much as fasm preprocessor can give you (without efforts; I mean parenthesized subexpressions).

You should mix assembler and preprocessor features in proper proportions to get something edible.

Here is my shot at that:
Code:
```struc reequ value {
restore .
. equ value
}

struc eval expr { rept 1 expr': expr \{ . reequ expr' \} }

struc parse expr {
.count equ 0; assume failure
local _duke; somewhat higher than count
_duke equ 1
match _expr, expr \{; expand symbolics
irps symbol, _expr \\{
match /, symbol \\\{ .count reequ _duke \\\}
_duke eval _duke+1
\\}
\}
restore _duke; kill him
}

expr equ 2+3/2-9
x parse expr
display '0'+x.count    ```
It sets .count to index of last occurrence. To get first, you need to stop assignment if .count!=0 (rept may help).

P.S. This indeed belongs to Macroinstructions, maybe moderators will move it there.
17 Jul 2013, 12:50
Roman

Joined: 21 Apr 2012
Posts: 1718
Roman 17 Jul 2013, 13:27
baldr
Thanks !
But you say "you need to stop assignment if .count!=0"
This is sad, because it complicates.
This is no good for me. Sad
Once again convinced that the macro Fasm, for such things is not calculated for such tasks
17 Jul 2013, 13:27
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum