x86 Instruction Set Reference
BSR
Bit Scan Reverse
Opcode | Mnemonic | Description |
---|---|---|
0F BD |
BSR r16, r/m16 |
Bit scan reverse on r/m16 |
0F BD |
BSR r32, r/m32 |
Bit scan reverse on r/m32 |
Description |
---|
Searches the source operand (second operand) for the most significant set bit (1 bit). If a most 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 source operand is 0, the content of the destination operand is undefined. |
Operation |
---|
if(Source == 0) { ZF = 1; Destination = Undefined; } else { ZF = 0; Temporary = OperandSize - 1; 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/BSR | 16/8 | 2/4 | - |