CWD (convert word to doubleword) has no operands. It fills every bit of DX with the sign bit of AX: DX becomes 0000h when AX is positive or zero, and FFFFh when AX is negative. AX itself is unchanged, and DX:AX now holds the same signed value as a 32-bit number. No flags change.

Before IDIV

A word IDIV divides the 32-bit DX:AX. Load the dividend into AX, then CWD, then divide. Clearing DX with XOR DX, DX would be right only for non-negative dividends; for a negative one it makes a large positive number and the result is wrong.

MOV AX, -20
CWD ; DX:AX = -20
MOV BX, 4
IDIV BX ; AX = -5, DX = 0

Absolute value without a jump

Because DX ends up as either all zeros or all ones, it can be used as a mask. XOR with all ones inverts AX, and subtracting −1 adds one, which together is a negation; XOR and subtraction with zero change nothing. So these three lines replace AX with its absolute value:

Prints 7. Try a positive value in AX: DX is 0 and nothing changes.
MOV AX, -7
CWD ; DX = FFFFh because AX is negative
XOR AX, DX ; FFF9h -> 0006h
SUB AX, DX ; 0006h - (-1) = 0007h
ADD AL, '0' ; digit -> character
MOV DL, AL
MOV AH, 02h ; DOS: print DL
INT 21h

Pitfalls

CWD always overwrites DX, so save anything kept there. It only sign-extends AX; to widen a value in another register, move it to AX first. A byte has to be widened to a word with CBW before CWD can take it further.

Later CPUs

The 386 adds CDQ, which sign-extends EAX into EDX:EAX for 32-bit IDIV.