"Use of mnemonics" demonstrations
Bit control and tests

These tests demonstrate the use of the bit control mnemonics, BT, BTS, BTC, BTR, BSF, BSR and BSWAP.
According to my documentation these mnemonics are not particularly fast, although this may change as processors progress. However they are very convenient to use and provide compact coding.
Set the breakpoint BIT_CONTROL, run the test, and single-step through the code.
Remember when using these mnemonics that the bit values are always zero-based. So BT EAX,0 tests the first bit in EAX and BT EAX,31 tests the last (most significant) one.

Here is the code:-

BIT_CONTROL:
MOV EAX,80000001h
BT EAX,31D
JNC >L20
NOP
L20:
BT EAX,0
JNC >L21
NOP
L21:
TEST EAX,80000000h
TEST EAX,1h
CMP EAX,0
;
MOV EAX,0
BT EAX,31D
JNC >L22
NOP
L22:
BT EAX,0
JNC >L23
NOP
L23:
TEST EAX,80000000h
TEST EAX,1h
CMP EAX,0
;
BTS EAX,31D
BTC EAX,31D
BTS EAX,31D
BTR EAX,31D
BTC EAX,31D
;
BTS EAX,0
BTC EAX,0
BTS EAX,0
BTR EAX,0
BTC EAX,0
;
MOV EAX,0
BSF EDX,EAX
MOV EAX,0
BSR EDX,EAX
MOV EAX,800000h
BSF EDX,EAX
MOV EAX,800000h
BSR EDX,EAX
;
MOV EAX,12345678h
BSWAP EAX
;
MOV EDI,OFFSET BUFFER
MOV EAX,3
BTR D[EDI],2D
BTR D[EDI+3],3
BTR [EDI],EAX
BTC D[EDI],2D
BTC D[EDI+3],3
BTC [EDI],EAX
RET
;