Intel 64 and IA-32 Architectures Software Developers Manual Volume 1, Basic Architecture

7-10 Vol. 1
PROGRAMMING WITH GENERAL-PURPOSE INSTRUCTIONS
Simple conversion — The CBW (convert byte to word), CWDE (convert word to
doubleword extended), CWD (convert word to doubleword), and CDQ (convert
doubleword to quadword) instructions perform sign extension to double the size of
the source operand.
The CBW instruction copies the sign (bit 7) of the byte in the AL register into every bit
position of the upper byte of the AX register. The CWDE instruction copies the sign
(bit 15) of the word in the AX register into every bit position of the high word of the
EAX register.
The CWD instruction copies the sign (bit 15) of the word in the AX register into every
bit position in the DX register. The CDQ instruction copies the sign (bit 31) of the
doubleword in the EAX register into every bit position in the EDX register. The CWD
instruction can be used to produce a doubleword dividend from a word before a word
division, and the CDQ instruction can be used to produce a quadword dividend from
a doubleword before doubleword division.
Move with sign or zero extension — The MOVSX (move with sign extension) and
MOVZX (move with zero extension) instructions move the source operand into a
register then perform the sign extension.
The MOVSX instruction extends an 8-bit value to a 16-bit value or an 8-bit or 16-bit
value to a 32-bit value by sign extending the source operand, as shown in Figure 7-5.
The MOVZX instruction extends an 8-bit value to a 16-bit value or an 8-bit or 16-bit
value to a 32-bit value by zero extending the source operand.
7.3.1.7 Type Conversion Instructions in 64-Bit Mode
The MOVSXD instruction operates on 64-bit data. It sign-extends a 32-bit value to 64
bits. This instruction is not encodable in non-64-bit modes.
7.3.2 Binary Arithmetic Instructions
Binary arithmetic instructions operate on 8-, 16-, and 32-bit numeric data encoded
as signed or unsigned binary integers. The binary arithmetic instructions may also be
used in algorithms that operate on decimal (BCD) values.
Figure 7-5. Sign Extension
31
After Sign
15
0
S
NNNNNNNNN NNNNNNSSSSSSSSSSSSSSSS
Extension
Before Sign
15
0
S
NNNNNNNNN NNNNNN
Extension