Intel bsf instruction using tutorial

  

Introduction: bsfl assembly instruction: intel assembly instruction: bsf oprd1, oprd2; bit scan forward from right to left (from bit 0--> bit 15 or bit 31 The scan word or double word operand oprd2 contains the first bit of "1", and sends the bit number of the first bit containing '1' to the operand oprd1 AT&T format assembly instruction bsfl Bsf, except that the source and destination operands are in reverse order. For example, there is a similar statement analysis on the Internet: .__asm__("bsfl %1,%0/n/t" "jne 1f/n/t" "movl $32, %0/n" "1:" : "=r"(set) :"r"(~ (*p >> bit))); The initial condition before entering the assembly instruction: p: the one at which the start bit pointed to by offset is located Unsigned long type 4B double word at the beginning. Bit: The starting bit pointed to by offset is the first of the unsigned long 4B double words in which it is located. *p >> bit : The pointer to the beginning of the unsigned long type 4B double word at which the start bit pointed to by the offset is located is shifted to the right by the bit, that is, the bit before the start bit pointed to by the offset All are moved out, and the start bit pointed to by offset is shifted to the rightmost end (lowest bit, 0 bit), and the start bit becomes the first bit of the unsigned long type 4B. ~ (*p >> bit) : Invert the bits, originally looking for the first '0' bit from the offset bit. This inversion turns the problem into finding the offset bit. The bit after the first '1' is followed. Bsfl %1,%0 <====> bsfl (~ (*p >> bit)), set finds the first '1' in (~ (*p >> bit)) The bit is stored in the set and returned. Movl $32, %0 : When the next 32 bits from the offset bit are all '0', ie: all '1' before the inversion, then set = 32

Copyright © Windows knowledge All Rights Reserved