# `cdq`

[x86-64 Documentation](https://asm-editor.specy.app/documentation/x86.md) › [Instructions](https://asm-editor.specy.app/documentation/x86/instruction.md)

Web page: https://asm-editor.specy.app/documentation/x86/instruction/cdq

**Sign-extend eax into edx:eax**

Category: Arithmetic

Sign-extends eax into edx:eax, filling edx with copies of the sign bit of eax.

386 and later

[Intel's reference: CWD/CDQ/CQO](https://intel.github.io/SDM/instruction/CWD-CDQ-CQO.html)

## Flags

| Flag | Effect |
| --- | --- |
| CF | not changed |
| PF | not changed |
| AF | not changed |
| ZF | not changed |
| SF | not changed |
| DF | not changed |
| OF | not changed |

## Forms

- `cdq`

## Description

It writes `edx` as a 32-bit register, so the upper half of `rdx` is cleared. Use it before a 32-bit `idiv`; before a 64-bit one, [`cqo`](https://asm-editor.specy.app/documentation/x86/instruction/cqo.md) extends `rax` into `rdx:rax`.

## Example

```x86
global _start

section .text
_start:
        mov rax, 12
        mov rbx, 5
        mov rcx, 3
        mov rsi, 9

        cdq

        mov rax, 60         ; syscall 60: exit
        xor rdi, rdi
        syscall
```
