flat assembler
Message board for the users of flat assembler.
Index
> Main > how do I use FPU Goto page 1, 2 Next |
Author |
|
HaHaAnonymous 05 Sep 2013, 16:07
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 19:58; edited 1 time in total |
|||
05 Sep 2013, 16:07 |
|
patchariadog 05 Sep 2013, 16:26
thanks it does work but I need you to please help me modify it a little. this is what I did
Code: mov [v1],10.1 mov [v2],5.2 finit fild dword [v1] fild dword [v2] fdivp fistp dword [esp] ; result is now in eax pop eax mov [v3],eax cinvoke wsprintfA,addr v4,"%u",[v3] invoke SetDlgItemTextA,[hWin],maximumoutputpowertext,addr v4 when i calculate it the result textbox gives me 1 as the answer how can I get it to give me 1.94230769231 as the answer also is the 1.94230769231 in eax and it is just rounding it when i use wsprintf or is it rounding it before wsprintf and I also changed the v1 v2 v3 to dd because when I did dq it kept giving me 1 as the answer thanks |
|||
05 Sep 2013, 16:26 |
|
HaHaAnonymous 05 Sep 2013, 16:40
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 19:58; edited 1 time in total |
|||
05 Sep 2013, 16:40 |
|
patchariadog 05 Sep 2013, 16:58
I am sorry but I am kind of new at fasm and dont understand how to edit the code to get the precision
I tried this but it gave me 1 Code: mov [v1],10.1 mov [v2],5.2 finit fild dword [v1] fild dword [v2] fdivp fstp dword [v3] cinvoke wsprintfA,addr v4,"%u",[v3] invoke SetDlgItemTextA,[hWin],maximumoutputpowertext,addr v4 thanks |
|||
05 Sep 2013, 16:58 |
|
HaHaAnonymous 05 Sep 2013, 17:15
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 19:58; edited 2 times in total |
|||
05 Sep 2013, 17:15 |
|
patchariadog 05 Sep 2013, 17:20
it just give me 0001 instead of 1
I also noticed if i do Code: mov [v5],10 mov [v6],5 it will give me 2 but if I do anything with decimals in it it will always give me 1 like Code: mov [v5],22.3 mov [v6],5.1 gives me 1 instead of 3 or 4 |
|||
05 Sep 2013, 17:20 |
|
HaHaAnonymous 05 Sep 2013, 17:26
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 19:58; edited 1 time in total |
|||
05 Sep 2013, 17:26 |
|
patchariadog 05 Sep 2013, 17:38
i tried this and it gives me a fixed number of like 1386456 every time no matter what numbers I use
Code: mov [v1],10.1 mov [v2],5.2 finit fild dword [v1] fild dword [v2] fdivp fistp dword [esp] ; result is now in eax pop eax mov [v3],eax cinvoke sprintf,addr v4,"%0.5f",[v3] invoke SetDlgItemTextA,[hWin],maximumoutputpowertext,addr v4 |
|||
05 Sep 2013, 17:38 |
|
MHajduk 05 Sep 2013, 17:46
I have changed your example a bit to make it working in console (this way it's easier to test its behavior) and it works to me as expected:
Code: format PE console 4.0 entry start include 'win32ax.inc' section '.data' data readable writeable v1 dd 0 v2 dd 0 v3 dq 0 section '.code' code readable executable start: mov [v1], 10.1 mov [v2], 5.2 finit fld dword [v1] fld dword [v2] fdivp fstp qword [v3] cinvoke printf, <13, 10, "%.16lf", 13, 10>, dword [v3], dword [v3 + 4] invoke ExitProcess, 0 section '.idata' import data readable library kernel32, 'kernel32.dll',\ msvcrt, 'msvcrt.dll' import kernel32,\ ExitProcess, 'ExitProcess' import msvcrt,\ printf, 'printf' |
|||
05 Sep 2013, 17:46 |
|
patchariadog 05 Sep 2013, 17:59
hey thanks I compiled it and it works but now can you help me convert it to gui based to(thanks because I was planning to build this project as a console and gui based)
I tried Code: mov [v1], 10.1 mov [v2], 5.2 finit fld dword [v1] fld dword [v2] fdivp fstp qword [v3] cinvoke sprintf,addr v4,"%0.5f",dword [v3] invoke SetDlgItemTextA,[hWin],maximumoutputpowertext,addr v4 ret and i get illegal instruction on the sprintf line maybe its the v4 rb I dont know I changed my data to look like yours now v1 dd v2 dd v3 dq v4 rb 20 |
|||
05 Sep 2013, 17:59 |
|
MHajduk 05 Sep 2013, 18:04
Try to write it like that (remember that v3 is a qword):
Code: cinvoke sprintf, addr v4, "%0.5f", dword [v3], dword [v3 + 4] include 'win32ax.inc' that allows to use inline declarations of strings. |
|||
05 Sep 2013, 18:04 |
|
patchariadog 05 Sep 2013, 18:21
thank you so much it works great. If you dont mind can you help me on one more quick problem because it seems like you know what your doing in fasm.
lets say v1 and v2 are both dq if I have a number in both of them how would I compare them for example .if [v3] > [v6] invoke MessageBoxExA, NULL, "hey", "hey", NULL .endif I get cmp invalid error (I dont care if you show me how to do it in the high level .if or if you use cmp) also how would you do multiple compares like in c++ I would do if (v1 > v2 && v1 > v3) { // do whatever } thanks Last edited by patchariadog on 05 Sep 2013, 18:25; edited 1 time in total |
|||
05 Sep 2013, 18:21 |
|
MHajduk 05 Sep 2013, 18:25
OK, here you have a simple GUI version:
Code: format PE GUI 4.0 entry start include 'win32ax.inc' section '.data' data readable writeable v1 dd 0 v2 dd 0 v3 dq 0 v4 rb 20 section '.code' code readable executable start: mov [v1], 10.1 mov [v2], 5.2 finit fld dword [v1] fld dword [v2] fdivp fstp qword [v3] cinvoke sprintf, v4, "%.16f", dword [v3], dword [v3 + 4] invoke MessageBox, 0, v4, "Result", 0 invoke ExitProcess, 0 section '.idata' import data readable library kernel32, 'kernel32.dll',\ msvcrt, 'msvcrt.dll',\ user32, 'user32.dll' import kernel32,\ ExitProcess, 'ExitProcess' import user32,\ MessageBox, 'MessageBoxA' import msvcrt,\ sprintf, 'sprintf' Last edited by MHajduk on 05 Sep 2013, 19:52; edited 2 times in total |
|||
05 Sep 2013, 18:25 |
|
patchariadog 05 Sep 2013, 18:27
okay thanks. can you please show me how to compare the 2 qwords
thanks |
|||
05 Sep 2013, 18:27 |
|
MHajduk 05 Sep 2013, 18:33
patchariadog wrote: lets say v1 and v2 are both dq You can compare values using FCOM instruction of FPU or MMX comparison instructions. |
|||
05 Sep 2013, 18:33 |
|
patchariadog 05 Sep 2013, 18:38
I looked an it says
fcom ; compare st0 with st1 so if i have a v1 and v2 dq how do I load these in to st0 and st1 and then compare |
|||
05 Sep 2013, 18:38 |
|
MHajduk 05 Sep 2013, 18:44
Intel manual says the following:
After the comparison you can check EFLAGS bits and decide what to do (e.g. jump). |
|||
05 Sep 2013, 18:44 |
|
HaHaAnonymous 05 Sep 2013, 18:51
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 19:58; edited 1 time in total |
|||
05 Sep 2013, 18:51 |
|
MHajduk 05 Sep 2013, 18:58
HaHaAnonymous wrote: Untested. |
|||
05 Sep 2013, 18:58 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.