cdq

Sign-extend eax into edx:eax

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

CFPFAFZFSFDFOF –––––––
  • Changes no flag

Forms

  • cdq

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 extends rax into rdx:rax.

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