If you compute modulo a power of two, using bitwise AND is simpler and generally faster than performing division. If b
is a power of two, a % b == a & (b - 1)
.
For example, let's take a value in register EAX, modulo 64.
The simplest way would be AND EAX, 63
, because 63 is 111111 in binary.
The masked, higher digits are not of interest to us. Try it out!
Analogically, instead of using MUL or DIV with powers of two, bit-shifting is the way to go. Beware signed integers, though!