Basically i need if one value divided with another leaves a remainder. I could of course just use DIV, but DIV, as far as i know, is one of the slowest executing instructions you can use, also it is somewhat tricky to use.

What i want is a modulus function which only leaves the remainder, possibly just a boolean output, 0 for no remainder and 1 if there is a remainder.

I was thinking that maybe you could do somesort of bit manipulation or something, but i have figured out a way yet.

I'm sure that there is some bright heads in here, so i hope for the best.

Thanks in advance
Posted on 2007-01-14 15:15:11 by Zacariaz
Modulus of (x % y) is best done with idiv/div if y is arbitrary. Since you haven't specified y, then you mean y is arbitrary.

But if y is constant, it's easy with MagicDivider (by The Svin and Ewayne).
For instance, if y=271, the proc would be
``Modulo271 macro x:REQmov eax,xmov edx, 4057238479mul edxSHR edx, 8mov eax,271mul edxsub eax,xendm``

; if (x % 271)==0, eax=0 and ZERO flag is set
; otherwise, eax !=0, and ZERO flag is clear
Posted on 2007-01-14 19:17:59 by Ultrano
You could of course do a subtraction loop until the remainder is smaller than the dividend (value to subtract).

In the old days, afaik, this could be faster than a DIV if you knew you would always get a small number of iterations.
Posted on 2007-01-15 03:36:29 by f0dder