News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

wsprintf with floating values

Started by n00b!, March 10, 2009, 04:49:14 PM

Previous topic - Next topic

n00b!

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!

PauloH

Hello, n00b!.

Please, take a look at here.
Your answer is there.

Kind regards,

PauloH

n00b!

Thanks  :bg
But do you know something about my FPU questions?

GregL

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

n00b!

Argh, damnit.
I had that in mind but searched for "simple fpu"....
Thank you  :P

donkey

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]
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

raymond

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.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com