flat assembler
Message board for the users of flat assembler.
Index
> Main > sorting the mathematical operations like this 2+102*4/3 Goto page 1, 2 Next 
Author 

Roman
I want sort by mathematical operations and break into groups. And then we get like this first 2*4=x then x/3=z and then 2+10=y and at last we have y+z
I found a bug. If write CoolMath 2*99.99999 work, but if write CoolMath 2*199.99999 fasm swears for number 199.99999. Why ? I use Fasm version 1.69.03 

08 Jul 2013, 08:11 

revolution
Roman wrote: I found a bug. If write CoolMath 2*99.99999 work, but if write CoolMath 2*199.99999 fasm swears for number 199.99999. Why ? Roman wrote: I use Fasm version 1.69.03 

08 Jul 2013, 10:24 

Roman
Revolution
compile this code. And you see.


08 Jul 2013, 13:02 

uart777
`s and \s are misplaced and if should be replaced with match. Try something like this:
Code: macro MATH [p] { forward define ?s 0 match a+b, p \{ display 'add ' define ?s 1 ; success \} match =0 ab, ?s p \{ display 'sub ' define ?s 1 ; success \} match =0 a*b, ?s p \{ display 'mul ' define ?s 1 ; success \} match =0 a/b, ?s p \{ display 'div ' define ?s 1 ; success \} if ?s eq 0 ; no successful match? 'Syntax error' end if } Code: MATH a+b, a*b ; displays 'add mul' 

08 Jul 2013, 18:25 

Roman
uart777
Thanks But how get this: MATH a+b  a*b or MATH a+b + a*b or MATH a+b * a*b uart777 if we write MATH a+b, a*b then it is not clear how the operation will be between a+b and a*b 

09 Jul 2013, 07:00 

uart777
What are you trying to do? Just learning and practicing? How to match this? a+b  a*b? Exactly asis.
Code: match a+b  x*y, p { ; ... } Code: match (i==0=,i<n=,i++), p { ; match (i=0,i<n,i++) ; ... } 

09 Jul 2013, 15:42 

Roman
Now I am writing hands actions for different operations. But how is it easier with macros? The more operations, the more combinations will have to write your hands. It's like a sad write hands:(
Code: macro MMXFlt2 Mesto,[p]{ Dons EQU No match a+b  x*y, p \{ mov eax,a movd xmm1,eax mov eax,b movd xmm2,eax addss xmm1,xmm2 mov eax,x movd xmm3,eax mov eax,y movd xmm4,eax mulss xmm3,xmm4 subss xmm1,xmm3 movss [Mesto],xmm1 Dons EQU Yes ;cvtss2si eax,xmm1 ;convert to integer number \} match =No a+b + x*y, Dons p \{ mov eax,a movd xmm1,eax mov eax,b movd xmm2,eax addss xmm1,xmm2 mov eax,x movd xmm3,eax mov eax,y movd xmm4,eax mulss xmm3,xmm4 addss xmm1,xmm3 movss [Mesto],xmm1 Dons EQU Yes \} match =No a+b * x*y, Dons p \{ mov eax,a movd xmm1,eax mov eax,b movd xmm2,eax ;addss xmm1,xmm2 mov eax,x movd xmm3,eax mov eax,y movd xmm4,eax mulss xmm3,xmm4 mulss xmm3,xmm2 addss xmm1,xmm3 movss [Mesto],xmm1 Dons EQU Yes \} } 

10 Jul 2013, 17:28 

bitRAKE
Here is another possibility:
Code: ; stack of registers rept 8 i:0 { XREG equ xmm#i } 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 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 mulss R,XREG XREG equ R \\} ; no match, assume memory value match R ==,XREG OK \\{ movss R,str \\} purge XMMath restore OK \} } def_XMMath ; Example of use: _dv dd 9.80665 _dx dd 1.973 _t dd 9.12345 _x0 dd 5.0 entry $ ; generate code to put result in XMM7 (top of stack register) XMMath [_dv] * [_t] * [_t] + [_dx] * [_t] + [_x0] Less manual work by programmer, though. (Partly based on the discussion here.) 

10 Jul 2013, 22:19 

Roman
bitRAKE thanks !
Mama Mia ! Incredible and amazing example ! Sad fact that in this way macros are not considered in the documentation on FASM Why ? 

11 Jul 2013, 06:43 

Roman
bitRAKE
Thanks for help. If you know, please tell me about this. In macro (for example Val equal [_dx]*[_x0] ) if i write movss xmm1,Val Fasm will give an error, because we get movss xmm1,[_dx]*[_x0]. But how to make the Val equal [_x0] (and not using match)? I mean depose Val to [_x0]. This can be done without match? 

11 Jul 2013, 07:38 

Roman
Sad
XMMath [_t]/[_t]/[_dv] get value 2.0 ! This is wrong , must be 0.5 ! _dv dd 2.0 _t dd 4.0 

11 Jul 2013, 08:00 

bitRAKE
Topic was kind of split.
Answer should be here, too: 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 \\} 

12 Jul 2013, 00:46 

bitRAKE
Roman wrote: In macro (for example Val equal [_dx]*[_x0] ) p.s. You don't need to PM me for every question. I will respond to the thread if I can. My email is at gmail if you have something private, or want to pay me (paypal) for more prompt replies. Otherwise just be patient, please. 

12 Jul 2013, 01:56 

Roman
bitRAKE
this work if we using only 3 operations But how to make this code more versatile(i mean using in macro)? 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 \\} How to write this example for the next combination? XMMath [_t]/[_t]/[_dv]/../.../ (i mean we dont know how much operations div were. Maybe 4 operations or maybe 7 operations) 

12 Jul 2013, 08:49 

bitRAKE
I'm sorry it was not clear. Use both and it works for any number of "/" operations.
Code: ; stack of availible registers rept 16 i:0 { XREG equ xmm#i } ; amd64 mode macro def_XMMath { macro XMMath [str*] \{ common define OK = def_XMMath ; allow recursion ; low precedence functions 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 addss R,XREG XREG equ R \\} 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 subss R,XREG XREG equ R \\} match R == A * B,XREG OK str \\{ restore OK define OK XMMath A restore XREG XMMath B mulss R,XREG XREG equ R \\} 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 \\} match R == A / B,XREG OK str \\{ restore OK define OK XMMath A restore XREG XMMath B divss R,XREG XREG equ R \\} ; no match, assume memory value match R ==,XREG OK \\{ ; skip top of stack register match =R,str \\\{ restore OK define OK \\\} match ==,OK \\\{ movss R,str \\\} \\} purge XMMath restore OK \} } def_XMMath For example, the register stack could be the 64bit registers r8r15, and the instructions could be changed to use basic integer arithmetic, or fixed point code, etc. A slight adaptation would even work for the FPU math. 

12 Jul 2013, 10:18 

Roman
bitRAKE
Thanks again ! But there is one point, you macro XMMath generated a lot of extra commands. I mean XMMath [_dv]/[_dv]/[_dv]/[_t]+[_t] We get 11 SSE commands ! If write hands we write 5 SSE commands ! if we write a lot of similar (XMMath [_dv]/[_dv]/[_dv]/[_t]+[_t]) we get a lot of extra commands ! In any case, your macro zingy 

12 Jul 2013, 11:31 

bitRAKE
Hmm...maybe you can figure out an optimization to improve the code generation. For example, if B is a register or memory location then it can be used directly in the instruction.
I wonder if the "no match" case could assign the string to another symbol which would work as the second operand to the instructions? Probably something like that. 

12 Jul 2013, 12:27 

Roman
bitRAKE
What about this XMMath [_dv]/2.0/[_dv]/[_t]+11.11 

12 Jul 2013, 12:35 

bitRAKE
Processing constants aren't that difficult.
Code: match R == _ A,XREG OK str \\{ < store constant somewhere and reference it > \\} Different prefixes could be used for integers and float. Could detect common constants for special handling  like 0,+/1, etc. 

12 Jul 2013, 20:25 

Goto page 1, 2 Next < Last Thread  Next Thread > 
Forum Rules:

Copyright © 19992020, Tomasz Grysztar. Also on YouTube, Twitter.
Website powered by rwasa.