The CWD instruction

Convert a word into a doubleword.

The CWD instruction format

InstructionDescription
CWDDX:AX := sign extension of AX.

Doubles the size of the operand in the ax register by means of sign extension and stores the result in the DX:AX register. The cwd instruction copies the sign (bit 15) of the value in the ax into every bit position in the dx register. The cwd instruction can be used to obtain a two-word dividend from a word before division by a word.

The cwd instruction is intended for use when the operand-size attribute is 16. Some assemblers may force the operand size to 16 when using cwd.

Usage example

title Author: Evgeny Sergeevich Dovgopolov

.model small
.stack 100h

code segment public        ; Start of the code segment
    assume cs:code

    main proc              ; Start of the main procedure
        mov     ax, 79     ; Copy the value 79 into the ax register
        cwd                ; Perform sign extension

        mov     ax, -4     ; Copy the value -4 into the ax register
        cwd                ; Perform sign extension

        mov     ax, 4C00h  ; Copy the process termination function number into ah and the value into al
        int     21h        ; Call the interrupt
    main endp              ; End of the main procedure

code ends                  ; End of the code segment
end main                   ; End of file. The main procedure is the entry point

Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".

Processor status flags

CF
No
PF
No
AF
No
ZF
No
SF
No
TF
No
IF
No
DF
No
OF
No