NOT takes one operand, a byte or word register or memory location, and inverts every bit in place: each 0 becomes 1 and each 1 becomes 0. This is called the one's complement.

1011 0010 AL = B2h
NOT
= 0100 1101 AL = 4Dh

For a memory operand the assembler needs the size: NOT BYTE PTR [BX] or NOT WORD PTR [SI]. An immediate cannot be inverted at run time; if you need the complement of a constant, write it in the source with the assembler's own NOT operator or just the inverted number.

Flags

NOT changes no flags at all, which is unusual for a logic instruction. If you want to branch on the result, follow it with TEST AL, AL, or use XOR AL, 0FFh, which produces the same bits and does set SF, ZF and PF.

NOT and NEG

In two's complement, NOT x equals -x - 1. NEG gives -x, so NEG is the same as NOT followed by adding 1. For example NOT turns 5 (05h) into FAh, which is -6 as a signed byte, while NEG turns it into FBh, which is -5.

Idioms

The common use is clearing bits whose mask is only known at run time. Build the mask, invert it, then AND: the bits that were 1 in the mask become 0 in the value, and everything else is kept.

Prints 10110010 01001101 01000001
MOV AL, 0B2h ; 1011 0010
CALL SHOWBIN
NOT AL
CALL SHOWBIN ; 0100 1101
MOV BL, 0Ch ; mask: bits 2 and 3
NOT BL ; 1111 0011
AND AL, BL ; clear bits 2 and 3
CALL SHOWBIN ; 0100 0001
SHOWBIN PROC NEAR ; print AL as 8 binary digits and a space
PUSHF ; keep the caller's flags
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV BL, AL
MOV CX, 8
NEXTBIT:
SHL BL, 1 ; the top bit falls into CF
MOV DL, "0"
ADC DL, 0 ; "0" + CF = "0" or "1"
MOV AH, 02h
INT 21h
LOOP NEXTBIT
MOV DL, " "
MOV AH, 02h
INT 21h
POP DX
POP CX
POP BX
POP AX
POPF
RET
SHOWBIN ENDP