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.

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.

.data

tmp1 dd 18

sum dq 179833751207936

.code

fild tmp1

fild sum

fmul

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.

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

EDIT: By the way, the answer is 3237007521742848, not 50353450338222080000.

includelib msvcrt.lib

printf PROTO C :DWORD,:VARARG

.data

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

tmp1 dd 18

sum dq 179833751207936

.code

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.

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.

@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.

ie

sum=345

for i=1 to len(myarray)

sum=sum*myarray

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.

ie

sum=345

for i=1 to len(myarray)

sum=sum*myarray

@roticv

Please give me your big number library details.Thanks.

Can somebody please explain me the difference between fist fistp and fstp ?@roticv

Please give me your big number library details.Thanks.

Can somebody please explain me the difference between fist fistp and fstp ?

*
*

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

To learn about FPU instructions try and get a helpfile like x86eas.hlp (try google) or a tutorial (again, try google)

**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)

If you want to read up on fpu, do take a look at the tutorial by Ray at http://ray.masmcode.com/fpu.html

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.

Edit:Problem solved.I used roy's bignumber library.Thanks everyone.