cwtl

Convert Word to Long

CWTL

Sign-extends AX into EAX (also CWDE).

Details

Sign-extends the 16-bit value in AX into the 32-bit register EAX; the sign bit of AX (bit 15) is copied to all high-order bits (31–16) of EAX, and EAX's low 16 bits (AX) remain unchanged. This is a zero-operand instruction with no flags modified. In 64-bit mode, CWDE is the canonical mnemonic and has the same behavior.

Pseudocode Operation

EAX[31:16] ← (AX[15]) ? 0xFFFF : 0x0000;

Example

CWTL

Encoding

Binary Layout
98
+0
 
Format Legacy
Opcode 98
Extension Base

Operands

Reference (Intel® SDM)

Instruction Forms

Opcode Instruction Op/En 64/32-bit Mode CPUID Description
98 CBW ZO Valid Valid AX := sign-extend of AL.
98 CWDE ZO Valid Valid EAX := sign-extend of AX.
REX.W + 98 CDQE ZO Valid N.E. RAX := sign-extend of EAX.

Description

Double the size of the source operand by means of sign extension. The CBW (convert byte to word) instruction copies the sign (bit 7) in the source operand into every bit in the AH register. The CWDE (convert word to doubleword) instruction copies the sign (bit 15) of the word in the AX register into the high 16 bits of the EAX register. CBW and CWDE reference the same opcode. The CBW instruction is intended for use when the operand-size attribute is 16; CWDE is intended for use when the operand-size attribute is 32. Some assemblers may force the operand size. Others may treat these two mnemonics as synonyms (CBW/CWDE) and use the setting of the operand-size attribute to determine the size of values to be converted. In 64-bit mode, the default operation size is the size of the destination register. Use of the REX.W prefix promotes this instruction (CDQE when promoted) to operate on 64-bit operands. In which case, CDQE copies the sign (bit 31) of the doubleword in the EAX register into the high 32 bits of RAX.

Operation

IF OperandSize = 16 (* Instruction = CBW *)
THEN
AX := SignExtend(AL);
ELSE IF (OperandSize = 32, Instruction = CWDE)
EAX := SignExtend(AX); FI;
ELSE (* 64-Bit Mode, OperandSize = 64, Instruction = CDQE*)
RAX := SignExtend(EAX);
FI;

Flags Affected

None. Exceptions (All Operating Modes) #UD If the LOCK prefix is used. CBW/CWDE/CDQE—Convert Byte to Word/Convert Word to Doubleword/Convert Doubleword to Quadword Vol. 2A 3-138