flat assembler
Message board for the users of flat assembler.

Index > Main > For Tomasz Grysztar new features like cut

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1878
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
Post 11 Jul 2013, 12:32
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 11 Jul 2013, 12:38
I would like to expect new features in the new version of the Fasm.
Post 11 Jul 2013, 12:38
View user's profile Send private message Reply with quote
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    
Post 11 Jul 2013, 16:11
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
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
      ;addss R,B      ;
      addss 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
     ; 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]
Post 11 Jul 2013, 16:24
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
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

And Baldr how about this:
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
Post 11 Jul 2013, 16:31
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4168
Location: vpcmpistri
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
Post 11 Jul 2013, 22:45
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
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 !
Post 13 Jul 2013, 07:59
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 13 Jul 2013, 08:37
Function Set setpose (not cuting). Function Set setpose for function Cut
Post 13 Jul 2013, 08:37
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
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
}
Post 16 Jul 2013, 09:50
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4168
Location: vpcmpistri
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
Post 16 Jul 2013, 11:36
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
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
Post 16 Jul 2013, 13:16
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.