This is a collection of inline assembly examples.
BLSR - Reset Lowest Set Bit
BLSR
, or Reset Lowest Set Bit, is an instruction that copies all bits from the source into the destination, and sets the least significant bit to zero. This is equivalent to a &= a-1
.
You can find more information on BLSR
here.
popbit :: (a: u64) -> u64 #expand {
#asm { blsr.q a, a; }
return a;
}
Here is an example of using BSLR
.
a: u64 = 0xFF;
print("%\n", formatInt(a, 2));
a = popbit(a);
print("%\n", formatInt(a, 2));
a = popbit(a);
print("%\n", formatInt(a, 2));
a = popbit(a);
print("%\n", formatInt(a, 2));
When we run this code, we get:
11111111
11111110
11111100
11111000