x86 Instruction Set Reference
BSF
Bit Scan Forward
Opcode | Mnemonic | Description |
---|---|---|
0F BC |
BSF r16, r/m16 |
Bit scan forward on r/m16 |
0F BC |
BSF r32, r/m32 |
Bit scan forward on r/m32 |
Description |
---|
Searches the source operand (second operand) for the least significant set bit (1 bit). If a least significant 1 bit is found, its bit index is stored in the destination operand (first operand). The source operand can be a register or a memory location; the destination operand is a register. The bit index is an unsigned offset from bit 0 of the source operand. If the content of the source operand is 0, the content of the destination operand is undefined. |
Operation |
---|
if(Source == 0) { ZF = 0; Destination = Undefined; } else { ZF = 0; Temporary = 0; while(Bit(Source, Temporary) == 0) { Temporary = Temporary + 1; Destination = Temporary; } } |
Flags affected |
---|
The ZF flag is set to 1 if all the source operand is 0; otherwise, the ZF flag is cleared. The CF, OF, SF, AF, and PF, flags are undefined. |
Protected Mode Exceptions | ||||||||
---|---|---|---|---|---|---|---|---|
|
Real-Address Mode Exceptions | ||||
---|---|---|---|---|
|
Virtual-8086 Mode Exceptions | ||||||||
---|---|---|---|---|---|---|---|---|
|
Instruction | Latency | Throughput | Execution Unit |
---|---|---|---|
CPUID | 0F3n/0F2n | 0F3n/0F2n | 0F2n |
BSF | 16/8 | 2/4 | - |