BSF Opcode is not working
I am using Visual Studio 2010 professional, and I just checked in debug mode that BSF is not working I tried a lot of combinations, none of them worked!
__asm
{
mov ebx, 0ffffffh;
bsf ecx, ebx;
};
the code above at least g开发者_运维百科ive me some results but I got 0 on ecx register (I'm using 64-bit win7 and application is 32-bit)
Here's what Intel says about BSF:
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.
Anybody has any thoughts? Thank you all...
You're getting ecx
set to 0 because the least significant (leastmost?) 1-bit in the value 0xffffff
is bit 0. The binary number for that is 0000 .... 1111 1111 1111 1111 1111 1111
.
In other words, the result you're seeing is correct.
If you were to try it on 0xfc
for example (binary 1111 1100
), you should get 2. This is because the least significant bits are in the rightmost positions of the binary number:
Hex F C
Binary 1111 1100
Bit# 7654 3210
^
|
+-- rightmost (least significant) 1-bit
Don't use inline asm, use compiler intrinsics: _BitScanForward
精彩评论