Hi,I really dont know much about FPU.I am today stuck with simple math and cant find the solution.I am trying to multiply big numbers via FPU then convert FPU to ASCII without E and dot's.Here is my code.

tmp1 dd 18
sum dq 179833751207936

fild tmp1
fild sum
fistp sum
fild sum
fstp sum

After this operation in OllyDbg ST0 =5.0353450338222080000e+15 I want to print as 50353450338222080000 ie without e and rest.I looked at fpu functions in masm32 library but they print with E.

ps:Above code look long to me is there a anyway to multiply with less code?I will appreciate if you explain.Thanks.
Posted on 2005-06-12 07:23:46 by LaptoniC
You can use printf or sprintf from the C runtime library and the %.0f format, as follows. A quicker way to multiply the numbers is also shown below

includelib msvcrt.lib

szFmt db '%.0f',0dh,0ah,0

tmp1 dd 18
sum dq 179833751207936

fild sum ; st(0) <- sum
fimul tmp1 ; st(0) <- sum * tmp1
sub esp,8
fstp qword ptr
push offset szFmt
call printf
add esp,12

EDIT: By the way, the answer is 3237007521742848, not 50353450338222080000.
Posted on 2005-06-12 08:22:05 by stormix
I think it is better that you use some big int lib instead of fpu. My current library supports multiplication. I can send you the code if you want it.
Posted on 2005-06-12 09:28:35 by roticv
@stormix I couldnt make your code work.I dont use commandline so I used sprintf but it didnt worked.

lea ecx,sum
push ecx
push offset szFmt
push offset szOutput
call sprintf
add esp,12

So please could you fix your code and if possible dont use stack as variable ? Actually my code takes input from array and and multiplies in a loop so I dont multiply just once.Therefore I save result at sum variable.

for i=1 to len(myarray)

Please give me your big number library details.Thanks.

Can somebody please explain me the difference between fist fistp and fstp ?
Posted on 2005-06-12 10:33:46 by LaptoniC
What you've used isn't actually my code... the reason I stored the number on the stack is because that is how you pass it to (s)printf, not as a pointer, as you have done. To use it in a loop, fild sum onto the stack before the loop, use fimul in the loop, then use fstp after the loop. But as roticv suggested, for what you're doing it sounds like a bignum library is more suitable,

To learn about FPU instructions try and get a helpfile like x86eas.hlp (try google) or a tutorial (again, try google)
Posted on 2005-06-12 11:15:57 by stormix
If you want to read up on fpu, do take a look at the tutorial by Ray at http://ray.masmcode.com/fpu.html
Posted on 2005-06-12 11:18:18 by roticv
Thanks for your help.I will read that tutorials and try to understand it.roticv could you PM the details of your big number library with simple example.Thanks.

Edit:Problem solved.I used roy's bignumber library.Thanks everyone.
Posted on 2005-06-12 11:49:03 by LaptoniC