News:

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

Calculate Modulo ?

Started by ilian007, November 10, 2009, 10:54:28 PM

Previous topic - Next topic

ilian007

Hello, I need to calculate modulo and trying to find best and short way to do it for example:

9%5=4 beacause 9=1*5+4
8%4=0 because 8=2*4+0

So far I found that way:

Given 11 % 3 how would you find the remainder? Well how would you do divide?
11 - 3 = +1 cycle with 8 left over
8 is > 3 so keep going
8 - 3 = +1 cycle with 5 left over
5 > 3 so...
5 - 3 = +1 cycle with 2 left over
2 is < 3 and > 0 so the remainder is 2 after 11 % 3

Is there any better way ?

Thank you

oex

mov eax, 9
mov ecx, 5
div ecx
modulous in edx
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

ilian007

It works thank you :) just needed to zero the DX prior dividing :)

oex

We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv