Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 give 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...

like image 690
MCA Avatar asked Mar 16 '26 20:03

MCA


1 Answers

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
like image 126
paxdiablo Avatar answered Mar 19 '26 14:03

paxdiablo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!