flat assembler
Message board for the users of flat assembler.

 Index > Main > For Tomasz Grysztar new features like cut
Author
Roman

Joined: 21 Apr 2012
Posts: 1718
Roman 11 Jul 2013, 12:32
I mean if we using macro and macro get like this Val EQU a+b-c/d
and new function Cut should be cut from the right Val.
New functions Cut and Set using on macros and with EQU and Fix, define
Example:
Val EQU a+b-c/d
Cut Val,+ ;Then Val = a
And +(plus) put to Snip !

And we have after Cut Val,+
Val=a and Snip(this is part of new function Cut) = + and EndOfLine = b-c/d
If we do not want to spoil Val. We create new ValNew EQU Val and do Cut ValNew,+

This example shows even at the simplest level, the advantages new function Cut.
Another function is Set (using for function Cut). Example Set Val,b
and Cut Val,- we get Val = b and Snip = - and EndOfLine =c/d

My example shows that the Fasm lack such functions.
These new features expand, simplify macros. And for the programmer are more understandable and easy to read.

Last edited by Roman on 11 Jul 2013, 12:48; edited 3 times in total
11 Jul 2013, 12:32
Roman

Joined: 21 Apr 2012
Posts: 1718
Roman 11 Jul 2013, 12:38
I would like to expect new features in the new version of the Fasm.
11 Jul 2013, 12:38
baldr

Joined: 19 Mar 2008
Posts: 1651
baldr 11 Jul 2013, 16:11
Roman,

You must learn existing features better before proposing new ones.
Code:
```match val snip endofline, a+b-c/d {
display "val=", `val, 13, 10
display "snip=", `snip, 13, 10
display "endofline="
irps s, endofline \{ display \`s \}
display 13, 10
}    ```
Output:
Code:
```val=a
snip=+
endofline=b-c/d    ```
11 Jul 2013, 16:11
Roman

Joined: 21 Apr 2012
Posts: 1718
Roman 11 Jul 2013, 16:24
Baldr
I mean this:
Code:
```macro def_XMMath {
macro XMMath [str*] \{
common
define OK =
def_XMMath ; allow recursion

; low precedence operations first

match R == A + B,XREG OK str \\{
restore OK
define OK ,
XMMath A ; recurse on A
restore XREG ; preserve value
XMMath B ; recurse on B
; movss R,A
XREG equ R
\\}
match R == A * B,XREG OK str \\{
restore OK
define OK ,
XMMath A ; recurse on A
restore XREG
XMMath B ; recurse on B
; movss R,A
; mulss R,B
mulss R,XREG
XREG equ R
\\}
match R == A / B,XREG OK str \\{
restore OK
define OK ,
XMMath A ; recurse on A
restore XREG
XMMath B ; recurse on B
;movss R,A ;Esli v primer [.]/[.] work. No ne work if [.]/[.]/[.] !
;divss R,B ;
divss R,XREG
XREG equ R
\\}
; no match, assume memory value
match R ==,XREG OK \\{
movss R,str     ;Tut billo
\\}
purge XMMath
restore OK

\}
} def_XMMath
```

if we write XMMath [_t]/[_t]/[_dv] we get 2.0 ! Must be 0.5 !
_dv dd 2.0
_t dd 4.0

And match is not always convenient and understandable especially if a lot of
operation like this:
XMMath [_dv] + [_t] + [_t] + [_dv] * [_t] + [_dv] +[_t] +[_t]*[_t]
11 Jul 2013, 16:24
Roman

Joined: 21 Apr 2012
Posts: 1718
Roman 11 Jul 2013, 16:31
Baldr
Thanks for you example:
match val snip endofline, a+b-c/d {
display "val=", `val, 13, 10
display "snip=", `snip, 13, 10
display "endofline="
irps s, endofline \{ display \`s \}
display 13, 10
}

Do not be angry, but in this example,very hard to understand from the first time it is found as a sign + and how this example work.
For this reason, I believe that the match is a crutch.
And new function Cut and Set more easy understand and less to write

match val snip endofline, [a]+b-c/d {
display "val=", `val, 13, 10 ;val = '[' !
display "snip=", `snip, 13, 10
display "endofline="
irps s, endofline \{ display \`s \}
display 13, 10
}
As we can see an example of the more complex the more it is necessary to inflate and complicate
11 Jul 2013, 16:31
bitRAKE

Joined: 21 Jul 2003
Posts: 3974
Location: vpcmipstrm
bitRAKE 11 Jul 2013, 22:45
The manual is very clear about how match works:
Quote:
Each name is always matched with as few symbols as possible, leaving the rest for the following ones
That is why the macro performs from right to left, as pieces are split from left to right until no matches are made.

(a+(b+(...(y+z)...)

If the operator is divide then the result is not what you expect it to be.

(...(a/b)...)/x)/y)/z)

So, your question is how can the macro be changed to process operators from left to right, when match only matches fewest symbols?

I doubt the general solution is needed, but just a match for a/b/c. Note how (a) and (b) will not have any "/" operator due to FASM's matching of fewest possible symbols.
Code:
```    match R == A / B / C,XREG OK str \\{
restore OK
define OK
XMMath A
restore XREG
XMMath B
divss R,XREG
XREG equ R
XMMath R / C
\\}    ```
...seems to work.
Need to get rid of the MOVSS XMM7,XMM7 instructions now.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
11 Jul 2013, 22:45
Roman

Joined: 21 Apr 2012
Posts: 1718
Roman 13 Jul 2013, 07:59
While I believe that the new features are needed (Cut, Set)
+ they more easily understood
+ less to write
+ with Cut and Set macros is not bloated

And function Cut and Set to empower.

Example:
Va EQU [a]+10.0/(a+b/2)
Cut Va,/(a ;its mean function Cut faind in Va this /(a and Va = [a]+10.0
Its more understood and more easily write.

And function Set:
Va EQU [a]+10.0/(a+b/2)
Set Va,(a+b/2) ;
Cut Va,/2) ; Va = (a+b
Set Va,a+b
Cut Va,+b ; Va = a !
13 Jul 2013, 07:59
Roman

Joined: 21 Apr 2012
Posts: 1718
Roman 13 Jul 2013, 08:37
Function Set setpose (not cuting). Function Set setpose for function Cut
13 Jul 2013, 08:37
Roman

Joined: 21 Apr 2012
Posts: 1718
Roman 16 Jul 2013, 09:50
I think the ElseEQU can be useful.
We know that macro does not give the result you think the first time.
Quote:

macro Gh arg {
Ost EQU "5"
if `arg = `-
Ost EQU "123"
end if
}

In code:
Quote:

Gh -1.0
display Ost

We all ways get Ost = "123"

And the macro to be more readable and understandable should be added the ElseEQU.
I look forward to understanding the author of the program.

If we get new ElseEQU then code look like this:
Quote:

macro Gh arg {
Ost EQU "5"
if `arg = `-
ElseEQU Ost EQU "123"
end if
}
16 Jul 2013, 09:50
bitRAKE

Joined: 21 Jul 2003
Posts: 3974
Location: vpcmipstrm
bitRAKE 16 Jul 2013, 11:36
EQU statements happen and are not seen by assembler stage. The IF/END IF are assembler directives - they are transparent to preprocessor (where EQU is evaluated).

Adding another directive would not change this - the two stages are separate.

For example, if we just use assembler stage:
Code:
```macro Gh arg {
Ost = 5
if `arg = `-
Ost = 123
end if
}    ```
...here macro is like paste for assembler.

Okay, now we just use preprocessor:
Code:
```macro Gh arg {
Ost EQU 5
match -,arg \{ Ost EQU 123 \}
}    ```
...here macro is like paste for preprocessor.

The product of the preprocessor is the code for the assembler. This is why there are different names for conceptually similar directives. Different languages for different stages. Similar to the way #define is not a keyword for C++, it is the preprocessor.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
16 Jul 2013, 11:36
Roman

Joined: 21 Apr 2012
Posts: 1718
Roman 16 Jul 2013, 13:16
bitRAKE
Thanks for the explanation. I thank you showed me how can get.
Sorry for the correction. But code must be:
Quote:

macro Gh arg {
Ost EQU 5
match - B,arg \{ Ost EQU 123 \}
}

Example: Gh -1
16 Jul 2013, 13:16
 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