Hi i have some more questions about FPU commands
i wrote this piece of code but it doesnt work.  So far i have this

lpDecimal_0      DD      2
result_0      db      250 dup(?)

number1 dd  ?    ; in .data?
number2 dd  ?

this is where the trouble starts

finit               
fld number1           
fld number2
fadd 
invoke FpuFLtoA, 0, ADDR lpDecimal_0, ADDR result_0, SRC1_FPU or SRC2_DMEM 
invoke SetWindowText,hDspl,ADDR result_0 

this code just gives me 0.00 it doesnt matter what number1 and number2 are.  I tried messing with the fadd function but still couldnt find the right answer.  I found out if I have a decleared constant like RNum10 = 3.14
and use the function fiadd, number1 without doing fld to number2 or 1 but only to RNum10 I get the right answer.
I know this is right because the fiadd function uses a memory location in my case its number1 and adds RNum10 which is on the stack.  But how come if i try to push 2 numbers on the stack like i did in my program above the fadd function dont display the right answer.   
  Can someone point out my error please? 

Thanks slim

Posted on 2005-06-28 13:31:59 by slim515
slim,

You need to use fild to load integers. fld is for loading floating-point numbers. Once the integers are both loaded, they have been converted to floating-point format so you use fadd not fiadd. You would use fiadd to add an integer located in memory to ST(0). 

Here is a good reference: SIMPLY FPU


Posted on 2005-06-28 21:28:47 by Greg
number1 dd? ?? ? ; in .data?
number2 dd? ?


Whenever you declare global variables as you did with a "?", they are generally initialized with 0, whether in the .data or .data? sections.

A 0 has a value of 0 as an integer AND as a float. If your program does not change the value of those declared variables, adding them will always result in 0, whether you load them on the FPU as integers with the fild instruction or as floats with the fld instruction.

this code just gives me 0.00 it doesnt matter what number1 and number2 are.


The only assumption I can make to explain the above is that you possibly initialized those variables with integers and then tried to load them to the FPU as floats. Those two data types are entirely different such that an integer smaller than about 16,000,000 would be considered very close to 0 in the floating point format.

greg's reference is a good one. You will find an explanation of the floating point format in Chap.2

Raymond
Posted on 2005-06-28 21:54:01 by Raymond
Thank you guys very much this problem is now solved.  I really appreciate you guys helping.  I am making a calculator with a gui in masm and so far i think i am doing alright.  If you guys want i can post my final code for my calculator once its done. 


thanks again
slim
Posted on 2005-06-29 00:20:16 by slim515
SOrry to bother you guys again.? I am having trouble with the FpuAtoFL function.? I am trying to read a number from a display window and store it as a floating number.?
invoke GetWindowText,hDspl,ADDR buffer,512
invoke FpuAtoFL,addr number3,0,DEST_FPU ? ;i am not sure about the syntax of this function i am trying to store the string that i got from 
                                                                  the  display  to  number3
fld number1? ? ? ? ? ? ? ? ? ?;it is a decloeared as REAL10 and i am trying to use to to keep a total pretty much
fld number3
fadd
fstp number1

can you guys please help me
Posted on 2005-06-30 01:25:02 by slim515
invoke FpuAtoFL,addr number3,0,DEST_FPU


If you are using the FPULIB library of functions, you should also have the Help file and consult it to use the functions properly. According to that Help file, the parameters for the FpuAtoFL are listed as:

FpuAtoFL (
? ?lpszSrc? ? ? ? //pointer to a zero terminated string
? ?lpDest? ? ? ? ?//pointer to destination of result
? ?uID? ? ? ? ? ? //ID flag for destination
)


Your quoted code tries to convert a zero terminated string currently located at the "number3" address and leave the result on the FPU!!! while the previous instruction stored the string you need to convert at the "buffer" address.

If you don't need to reuse that new number you want to convert but only add it to another number in memory, change the source address and simplify your code as follows:

? ?invoke FpuAtoFL,addr buffer,0,DEST_FPU
? ?fadd? number1
? ?fstp number1


Raymond
Posted on 2005-06-30 09:55:47 by Raymond
I dont have the help file i just have the FPULIB file.  Do you know where i can download it from?

thank you so much Raymond for all your help

sliim
Posted on 2005-06-30 12:16:51 by slim515
I have to assume that you don't have the MASM32 package. Otherwise, you would have found it in the HELP folder.

You can download the latest FPULIB package which contains the library, the source code for each function, AND the Help file, from the following:

http://www.ray.masmcode.com/fpu.html#fpulib

Raymond
Posted on 2005-06-30 22:23:50 by Raymond