BT, BTS, BTR, BTC: BIT Test command
; Bt (BIT Test): Bit test; BTS (BIT Test and set): Bit test and reset; BTR (BIT Test and reset): Bit test and reset; BTC (BIT Test and complement): Bit test and inverse test; their results affect CF; their command formats are the same: Bt R16/R32/M16/M32, r16/R32/M16/m32bt R16/R32/M16/M32, i8
; Test23_1.asm.386.model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. codemain proc; BT copies the seventh digit of 10000001b to CF and learns that it is 1 mov dx, 0000001b BT dx, 7 lahf printhex Ah; 47-01000111b (cf = 1 ); BT copies the sixth digit of ipv001b to CF and learns that it is 0 BT dx, 6 lahf printhex Ah; 86-0000110b (cf = 0); While executing the BT command, BTS, set the specified position of the operand to 1 mov dx, 10000001b BTS dx, 6 printhex dl; C1-11000001b; BTR sets the specified position of the operand to 0 mov DX while executing the BT command, 2017001b BTR dx, 7 printhex dl; 01-00000001b; BTC, while executing the BT command, locates the operand in reverse mov dx, 0000001b BTC dx, 0 printhex dl; 80-0000000b BTC dx, 0 printhex dl; 81-0000001b retmain endpend main
BSF and BSR: Bit scan command
; BSF (bit scan forward): Bit scan, low-> high; BSR (bit scan reverse): Bit scan, high-> low; their results affect ZF; after scanning for parameter 2 and finding a bit of 1, set the number of positions to the parameter 1 and set ZF = 0; if no value is found (that is, parameter 2 is 0, set ZF = 1; their command formats are the same: BSF R16/R32, R16/R32/M16/M32
; Test23_2.asm.386.model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. codemain proc; at the time of scanning mov dx, then 1111100001100b bsf cx, DX printdec CX; 2-that is, the left number is 3rd bsr cx, DX printdec CX; 11-that is, the left number is 12th bits; moV CX, 0 ffffh mov dx, 0 bsf cx, DX lahf printhex Ah; C6-11000110 (ZF = 1) printhex CX; FFFF-the destination value retmain endpend main will not be affected when it is not found