BSF
Assembly is real open source .
bsf
Usage: BSF dest,src Modifies flags: ZF
Scans source operand for first bit set. Sets ZF if a bit is found set and loads the 'dest' with an index to first set bit. Clears ZF if no bits are found set. BSF scans forward across bit pattern
Bit Scan
BSF reg16,r/m16 ; o16 0F BC /r [386]
BSF reg32,r/m32 ; o32 0F BC /r [386]
BSR reg16,r/m16 ; o16 0F BD /r [386]
BSR reg32,r/m32 ; o32 0F BD /r [386]
BSF searches for the least significant set bit in its source (second) operand, and if it finds one, stores the index in its destination (first) operand. If no set bit is found, the contents of the destination operand are undefined. If the source operand is zero, the zero flag is set.
BSR performs the same function, but searches from the top instead, so it finds the most significant set bit.
Bit indices are from 0 (least significant) to 15 or 31 (most significant). The destination operand can only be a register. The source operand can be a register or a memory location.
Example:
xor eax eax
mov eax 0FF
mov ebx 00_1111_1111_1111_1100
bsf eax ebx ; eax = 2