flat assembler
Message board for the users of flat assembler.

Index > Main > how do I use FPU

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog 05 Sep 2013, 19:23
thanks so much.

one more quick question and then I will be done

I want to replace these 2 lines
Code:
 mov     [v1], 10.1
 mov     [v2], 5.2
    


with getting one number from one textbox and another number from another textbox

I can get the text in a text format using

Code:
invoke GetDlgItemTextA,[hWin],textbox1,addr v1,100 
invoke GetDlgItemTextA,[hWin],textbox2,addr v2,100
    


and when i try it it gives me a new calculation each time but they are off.
eample
textbox 1 = 75.2
textbox2 = 22.3
answer should = 3.372197
but i get = .2500169
do i need to sprintf these before I send them to the FPU and if so how would I do that

thanks so much.
Post 05 Sep 2013, 19:23
View user's profile Send private message Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6115
Location: Poland
MHajduk 05 Sep 2013, 19:25
Use sscanf to convert the obtained strings from the text format to the desired number format then store values in v1 and v2, should work.
Post 05 Sep 2013, 19:25
View user's profile Send private message Visit poster's website Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog 05 Sep 2013, 19:37
I tried this code but it just crashes
Code:
invoke GetDlgItemTextA,[hWin],textbox1,addr v1,100 
invoke GetDlgItemTextA,[hWin],textbox2,addr v2,100
   
   cinvoke sscanf,[v8],"%s",addr v1   
   cinvoke sscanf,[v9],"%s",addr v2

;rest of the code that works

finit
                fld     dword [v8]
                fld     dword [v9]
                fdivp
                fstp    qword [v3] 

cinvoke sprintf, addr v4, "%.16lf", dword [v3], dword [v3 + 4]

            invoke SetDlgItemTextA,[hWin],maximumoutputpowertext,addr v4 

    


I made v8 and v9 dd

I also tried change the %s to %f because I was not sure what to use but it crashes also
Post 05 Sep 2013, 19:37
View user's profile Send private message Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6115
Location: Poland
MHajduk 05 Sep 2013, 19:49
patchariadog wrote:
I tried this code but it just crashes
Code:
invoke GetDlgItemTextA,[hWin],textbox1,addr v1,100 
invoke GetDlgItemTextA,[hWin],textbox2,addr v2,100
   
   cinvoke sscanf,[v8],"%s",addr v1   
   cinvoke sscanf,[v9],"%s",addr v2

;rest of the code that works

finit
                fld     dword [v8]
                fld     dword [v9]
                fdivp
                fstp    qword [v3] 

cinvoke sprintf, addr v4, "%.16lf", dword [v3], dword [v3 + 4]

            invoke SetDlgItemTextA,[hWin],maximumoutputpowertext,addr v4 

    


I made v8 and v9 dd

I also tried change the %s to %f because I was not sure what to use but it crashes also
Well, seems that you have messed it a bit. Wink v8 and v9 should be declared as buffers big enough to store strings taken from the text fields, something like this:
Code:
v8 rb 101
v9 rb 101

(...)

invoke GetDlgItemTextA, [hWin], textbox1, v8, 100 
invoke GetDlgItemTextA, [hWin], textbox2, v9, 100
   
cinvoke sscanf, v8, "%f", v1   
cinvoke sscanf, v9, "%f", v2

finit
fld     dword [v1]
fld     dword [v2]

(...)
    
Post 05 Sep 2013, 19:49
View user's profile Send private message Visit poster's website Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog 05 Sep 2013, 20:03
I changed v8 and v9 to rb 200

then I put this code in and did
textbox1 = 10.1
textbox2 = 5.5
answer should be = 1.83636363636
I get = 519010387852.254564
Code:
invoke GetDlgItemTextA, [hWin], textbox1, v8, 100 
invoke GetDlgItemTextA, [hWin], textbox2, v9, 100
   
cinvoke sscanf, v8, "%s", v1   
cinvoke sscanf, v9, "%s", v2   
             

                finit
fld     dword [v1]
fld     dword [v2] 
                fdivp
                fstp    qword [v3]

cinvoke sprintf, addr v4, "%.16lf", dword [v3], dword [v3 + 4]

            invoke SetDlgItemTextA,[hWin],maximumoutputpowertext,addr v4 

    


thanks for all the help
Post 05 Sep 2013, 20:03
View user's profile Send private message Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog 05 Sep 2013, 20:10
sorry I somehow missed changing the %s to %f now it works thanks so much.
also on this line of the compare code you gave me
Code:
cinvoke sprintf, addr v4, "%.16lf", dword [v3], dword [v3 + 4]
    


what does the dword [v3 + 4] do

thanks
Post 05 Sep 2013, 20:10
View user's profile Send private message Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6115
Location: Poland
MHajduk 05 Sep 2013, 20:10
The formatting strings should be "%f" not "%s" - you want to convert input strings to single precision floating point numbers.
Post 05 Sep 2013, 20:10
View user's profile Send private message Visit poster's website Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6115
Location: Poland
MHajduk 05 Sep 2013, 20:13
patchariadog wrote:
what does the dword [v3 + 4] do
This has to be used because you have been displaying double precision floating point which is contained in qword i.e. two consecutive dwords.
Post 05 Sep 2013, 20:13
View user's profile Send private message Visit poster's website Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog 05 Sep 2013, 20:28
okay thanks for all your help today. I have been searching for how to use the fpu in fasm on and off for about 6 months now so thank you.
Post 05 Sep 2013, 20:28
View user's profile Send private message Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6115
Location: Poland
MHajduk 05 Sep 2013, 20:38
patchariadog wrote:
okay thanks for all your help today. I have been searching for how to use the fpu in fasm on and off for about 6 months now so thank you.
You're welcome. Smile
Post 05 Sep 2013, 20:38
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1617
Location: Toronto, Canada
AsmGuru62 06 Sep 2013, 01:45
Code:
fld [v1]
fld [v2]
fcom
    

This is same as:
Code:
cmp [v2], [v1]
    

To do the opposite (cmp [v1],[v2]) you must load values in opposite order:
Code:
fld [v2]
fld [v1]
    

Also, you do not have to load the 2nd argument -- can save 1 FPU opcode by direct operation with memory argument:
Code:
v1 dq 45.9776
v2 dq 7.0594
v3 dq 0
...
fld [v1]
fmul [v2]
fstp [v3]
    
Post 06 Sep 2013, 01:45
View user's profile Send private message Send e-mail Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6115
Location: Poland
MHajduk 06 Sep 2013, 07:28
AsmGuru62 wrote:
Code:
fld [v1]
fld [v2]
fcom
    

This is same as:
Code:
cmp [v2], [v1]
    
As far as I know, the cmp instruction doesn't accept two memory arguments. You can only compare two registers or register with memory.

But maybe you meant something like a macro shorthand here. Wink
Post 06 Sep 2013, 07:28
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1617
Location: Toronto, Canada
AsmGuru62 06 Sep 2013, 13:08
Yes, I meant it like a pseudocode, because the swapping of the arguments will mean the difference in flags.
Post 06 Sep 2013, 13:08
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.