Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- iAPx86 - <b>bsf bit scan forward flags: o d i t s z a p c</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
BSF             Bit Scan Forward                     Flags: O D I T S Z A P C
                                                            ? - - - ? * ? ? ?
BSF destination,source                               CPU: 386+

        Logic   if a set bit is found in source
                   ZF . 0
                   destination . bit index of first set bit
                else
                   ZF . 1
                   destination . ?
                endif

    BSF scans (starting with bit 0) source for a one-bit. The zero
    flag (ZF) is set to 1 if the bits are all zero; otherwise, ZF is
    cleared to 0 and destination is loaded with the bit index of the
    first set bit.

        Example:        mov     dx,0110b
                        bsf     cx,dx   ; zf = 0, cx = 1
                        bsr     cx,dx   ; zf = 0, cx = 2

    Note
    Some sources wrongly state different result flags. Some 386 and
    early 486 CPUs change destination if source = 0.


    Opcode      Format
    0F BC       BSF  r16,r/m16
    0F BC       BSF  r32,r/m32


    Length and timing
    Operands    Bytes   8088    186     286     386     486     Pentium
    r16, r16     3                             10+3n    6-42   6-34  NP
    r32, r32     3                             10+3n    6-42   6-42  NP
    r16, m16  3+d(0,1,2)                       10+3n    7-43   6-35  NP
    r32, m32  3+d(0,1,2,4)                     10+3n    7-43   6-43  NP

See Also: BSR TEST SHR

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson