flat assembler
Message board for the users of flat assembler.

Index > Windows > [solved] fpu addition does not work

Author
Thread Post new topic Reply to topic
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog 14 Jun 2014, 01:00
Hi everybody.
I have this code that works for floating point numbers for fdvip and fmulp but it does not work with faddp and fsubp
Code:
;read in resultlengthXinpixelstextbox

invoke GetDlgItemTextA, [hwnd], resultlengthxpixelstextbox, bufferbuffer1, 100
cinvoke sscanf, bufferbuffer1, "%f", buffer1 

;read in MeasuredlengthXinpixelstextbox

invoke GetDlgItemTextA, [hwnd], measuredlengthxpixelstextbox, bufferbuffer1, 100
cinvoke sscanf, bufferbuffer1, "%f", buffer2

;resultlengthXpixels / MeasuredlengthXpixels

finit
fld dword [buffer1]
fld dword [buffer2] 
fdivp
fstp qword [buffer3]  

cinvoke sprintf, addr buffer1, "%.5lf", dword [buffer3], dword [buffer3 + 4]
invoke SetDlgItemTextA,[hwnd],resultlengthxtextbox,addr buffer1

.data
  bufferbuffer1 dd ?
  buffer1 dd ?
  buffer2 dd ?
  buffer3 dq ?  
    

could someone please show me how to fix it. it keeps giving me the incorrect answer

thanks
Post 14 Jun 2014, 01:00
View user's profile Send private message Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog 14 Jun 2014, 01:27
never mind I figured it out srry.
in case anyone wants a little FPU tutorial here it is

Code:

;in data section do
float1 dq 222.34
float2 dq 233.38
bufferfloat dd ?

;in idata do
library msvcrt,"msvcrt.dll"


import msvcrt,\
         sprintf,"sprintf"
         

;then to add

fld float1     ; Push float1 value to ST(0)
fadd float2    ; Add float2 to ST(0)
fstp float1    ; Pop value from ST(0) to float1

;subtract

fld float1     ; Push float1 value to ST(0)
fsub float2    ; Subtract float2 to ST(0)
fstp float1    ; Pop value from ST(0) to float1

;multiply

fld float1     ; Push float1 value to ST(0)
fmul float2    ; Subtract float2 to ST(0)
fstp float1    ; Pop value from ST(0) to float1

;divide

fld float1     ; Push float1 value to ST(0)
fdiv float2    ; Subtract float2 to ST(0)
fstp float1    ; Pop value from ST(0) to float1

;then to get a readable answer do this
cinvoke sprintf, bufferfloat, "%.5lf", dword [float1], dword [float1 + 4]
invoke  MessageBoxA,[hwnd],bufferfloat,title,MB_OK

;if you need to read the floats from a textbox to the float1 and 22(string to float) do this

invoke GetDlgItemTextA, [hwnd], resultlengthxpixelstextbox, bufferbuffer1, 100
cinvoke sscanf, bufferbuffer1, "%f", float1

;then in idata add sscanf

    


hopefully this simple tutorial helps someone.
Post 14 Jun 2014, 01:27
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.