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 throughout register forming a doubleword quantity in .
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 in to a signed quad word in by extending the high order bit of throughout .
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 =

 



      “I’m not arguing, I’m just explaining why I’m right.”    
      ― Unknown