Sign Extend Accumulator Into rDX

Encoding

EncodingOperand
zoNone

Description

The CWD/CDQ/CQO instructions sign extend the accumulator into the data register (rDX). This essentially sets every bit of the data register to that of the accumulator.

This instruction is similar to CBW/CWDE/CDQE (Sign Extend Accumulator), but working into the data register.

Operation

public void CWD()
{
    // DX:AX = SignExtend(AX)
    DX = AX.Bit[15] ? 0xFFFF : 0;
}

public void CDQ()
{
    // EDX:EAX = SignExtend(EAX)
    EDX = EAX.Bit[31] ? 0xFFFFFFFF : 0;
}

public void CQO()
{
    // RDX:RAX = SignExtend(RAX)
    RDX = RAX.Bit[63] ? 0xFFFFFFFFFFFFFFFF : 0;
}

Flags Affected

None.

Exceptions

Real-Address Mode

#UD
  • If the
  • LOCK
  • prefix is used.

Virtual-8086 Mode

#UD
  • If the
  • LOCK
  • prefix is used.

Protected Mode

#UD
  • If the
  • LOCK
  • prefix is used.

Compatibility Mode

#UD
  • If the
  • LOCK
  • prefix is used.

Long Mode

#UD
  • If the
  • LOCK
  • prefix is used.