 <p>You can't really ask a question about assembly code without mentioning what kind of processor assembly code you're talking about. For example, many processors have a dedicated instruction for counting number of bits set. For example, see <a href="http://en.wikipedia.org/wiki/SSE4#POPCNT_and_LZCNT" rel="nofollow">POPCNT</a> </p>