assume you have x % y = z
in order to get z, you must remove all multiples of y in x.
In hardware, this is what i'd do.
Starting with mssb x - mssb y as tmp
shift y tmp bits to the right.if the newly shifted number is greater then x then tmp = tmp - 1 if tmp = 0 then you have your remainder in x.else x = x - the shifted y tmp = tmp - 1 if tmp = 0 then we have the remainder.end if
Thats at most you have 31 iterations.
you could probably make it in hw running at 32 iterations.
Also, you can modify it to give you division as well. (so you'd make a divmod instruction instead of both. just saves time)
From,
Nice coder