The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: n00b! on March 10, 2009, 04:49:14 PM

Title: wsprintf with floating values
Post by: n00b! on March 10, 2009, 04:49:14 PM
Hi there,
I'm trying to calculate a floating value and print it.
First of all where can I find a FPU Tutorial for beginners?
I tried searching for one but didn't find almost anything.

My Problem:
.data
  dTime dd 0
  dSecond dd 500
  qVar dq 0
  szFormat db "%f", 0
  szBuffer db 100 dup(0)

.code
  mov [dTime], 3894
  fld [dTime]
  fld [dSecond]
  fdiv st(0), st(1)
  fst [qVar]
  invoke wsprintf, addr szBuffer, addr szFormat, qVar


I just tried this FPU code, I don't know yet if it's works since I didn't see the output.
I read the wsprintf article from the MSDN and noticed that it hasn't got a parameter named %f.
So how can i print it?  :'(

PS: Do I have to clean the FPU Stack after I using it?

Thanks very much!
Title: Re: wsprintf with floating values
Post by: PauloH on March 10, 2009, 05:12:52 PM
Hello, n00b!.

Please, take a look at here. (http://www.masm32.com/board/index.php?topic=4646.0)
Your answer is there.

Kind regards,

PauloH
Title: Re: wsprintf with floating values
Post by: n00b! on March 10, 2009, 05:41:35 PM
Thanks  :bg
But do you know something about my FPU questions?
Title: Re: wsprintf with floating values
Post by: GregL on March 10, 2009, 06:05:28 PM
noob!,

QuotePS: Do I have to clean the FPU Stack after I using it?

You should leave the FPU stack empty.

QuoteFirst of all where can I find a FPU Tutorial for beginners?

Simply FPU (http://www.website.masmforum.com/tutorials/fptute/)
Title: Re: wsprintf with floating values
Post by: n00b! on March 10, 2009, 06:41:14 PM
Argh, damnit.
I had that in mind but searched for "simple fpu"....
Thank you  :P
Title: Re: wsprintf with floating values
Post by: donkey on March 11, 2009, 12:43:14 AM
the C run time does a good job converting floats to strings

fstp Double
lea eax,[Double]
lea ecx,[Double+4]
Invoke msvcrt.dll:_gcvt, eax, ecx,12, offset szResult
add esp,16[quote][/quote]
Title: Re: wsprintf with floating values
Post by: raymond on March 11, 2009, 05:25:01 AM
QuotePS: Do I have to clean the FPU Stack after I using it?

You should leave the FPU stack empty.

That would be correct under the following circumstances:
- You intend to use other fpu instructions within the same program and you don't need the data which is currently in the FPU registers.

Otherwise, it simply doesn't matter whether you clean it up or not. All other programs running concurrently or afterwards are provided initially with a clean FPU.

As for the tutorial, after you become a bit more familiar with some of the basic instructions, you can eventually also refer to the source code of the Fpulib (available with the MASM32 package) for some of the more complex operations such as exponentiation, logarithms, etc.