CBW (convert byte to word) has no operands. It copies the top bit of AL, the sign bit, into all eight bits of AH. AX then holds the same signed value as AL did: 05h becomes 0005h, and FBh (−5) becomes FFFBh, which is still −5 as a word. No flags change.
| AL before | AX after | Value |
|---|---|---|
| 05h | 0005h | 5 |
| 7Fh | 007Fh | 127 |
| 80h | FF80h | −128 |
| FBh | FFFBh | −5 |
When to use it
Use it before a byte IDIV, which divides all of AX: put the dividend in AL, CBW, then divide. Use it too whenever a signed byte has to take part in word arithmetic, such as adding a signed byte offset to a word.
MOV AL, -5 ; a signed byte: FBhCBW ; AX = FFFBh, still -5ADD AX, 9 ; AX = 4ADD AL, '0' ; digit -> characterMOV DL, ALMOV AH, 02h ; DOS: print DLINT 21h
Unsigned values
For an unsigned byte, extend with zeros instead: MOV AH, 0 (or XOR AH, AH). CBW would turn 200 (C8h) into FFC8h, which is not 200 any more.
Pitfalls
CBW works only on AL and AH; there is no form for other registers. To sign-extend BL into BX on the 8086, go through AL (MOV AL, BL / CBW / MOV BX, AX), or test the sign and set the high byte yourself.
Later CPUs
The 386 adds CWDE (AX into EAX) and MOVSX, which sign-extends any byte or word register or memory operand into any wider register.