IDIV Instruction (Cont.)

 CWD — Convert Word to Doubleword 
Usage: cwd

Flag O D I S Z A P C
Result                

Extends sign of word in register AX throughout register DX forming a doubleword quantity in DX:AX.
Clocks
Operands 286 386 486 Size Bytes
none 2 3 3 1
 CDQ — Convert Doubleword to Quadword 
Usage: cdq

Flag O D I S Z A P C
Result                

Converts signed DWORD in EAX to a signed quad word in EDX:EAX by extending the high order bit of EAX throughout EDX.
Clocks
Operands 286 386 486 Size Bytes
none   2 3 1

 16-Bit Signed Division   32-Bit Signed Division   Using CDQ 
 .data
 x  SDWORD  00101010h
 y  SWORD   -100h
 .code
 mov    dx, WORD PTR x+2
 movzx  eax, WORD PTR x
 idiv   y
 call   DumpRegs
 .data
 x  SDWORD  -101010h
 y  SDWORD  100h
 .code
 mov   eax, x
 mov   edx, 0FFFFFFFFh
 idiv  y
 call  DumpRegs
 .data
 x  SDWORD  -101010h
 y  SDWORD  100h
 .code
 mov   eax, x
 cdq
 idiv  y
 call  DumpRegs
 Output   Output   Output 
  AX =

  DX =

 

  EAX =

  EDX =

 

  EAX =

EDX =