The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: mahmudkais on September 20, 2009, 10:15:25 PM

Title: how to divide or multiply percentages in masm32
Post by: mahmudkais on September 20, 2009, 10:15:25 PM
hello

how to divide or multiply percentages in masm32 ??

some example code please to learn ??

thanks
Title: Re: how to divide or multiply percentages in masm32
Post by: mahmudkais on September 20, 2009, 10:53:45 PM
i found it and it is simple

1000 * 0.006  =   (1000 * 6 )/1000  = 6


MOV   EAX, 1000
mov ebx,6
mul   ebx
mov ebx,1000

div   ebx


thanks

Title: Re: how to divide or multiply percentages in masm32
Post by: hutch-- on September 21, 2009, 01:25:43 AM
mahmudkais,

If you are going to be doing much number crunching, have a look at Ray Filiatreault's floating point maths library included in the masm32 sdk, simple interger maths have their place but for more complex work the floating point capacity is a lot more powerful.
Title: Re: how to divide or multiply percentages in masm32
Post by: mahmudkais on September 21, 2009, 06:31:30 AM
thanks
i will
Title: Re: how to divide or multiply percentages in masm32
Post by: donkey on September 21, 2009, 10:10:45 AM
If your just doing simple percentages the FPU is a bit of overkill, mostly they can be done using integer math as you posted above. To save a few clock cycles you can get rid of the DIV instruction...

http://blogs.msdn.com/devdev/archive/2005/12/12/502980.aspx

Edgar
Title: Re: how to divide or multiply percentages in masm32
Post by: BlackVortex on September 21, 2009, 10:54:35 AM
There is a tiny tool that does this, Magic Divider. I mean breaks down the divisions  to multiplication using a constant. Attached.