13.07.2015 Views

Volume 3: General-Purpose and System Instructions - Stanford ...

Volume 3: General-Purpose and System Instructions - Stanford ...

Volume 3: General-Purpose and System Instructions - Stanford ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

AMD64 Technology 24594 Rev. 3.10 February 2005IDIVSigned DivideDivides the signed value in a register by the signed value in the specified register ormemory location. The register to be divided depends on the size of the divisor.When dividing a word, the dividend is in the AX register. The instruction stores thequotient in the AL register <strong>and</strong> the remainder in the AH register.When dividing a doubleword, quadword, or double quadword, the most-significantword of the dividend is in the rDX register <strong>and</strong> the least-significant word is in the rAXregister. After the division, the instruction stores the quotient in the rAX register <strong>and</strong>the remainder in the rDX register.The following table summarizes the action of this instruction:Division Size Dividend Divisor Quotient Remainder Quotient RangeWord/byte AX reg/mem8 AL AH –128 to +127Doubleword/word DX:AX reg/mem16 AX DX –32,768 to +32,767Quadword/doubleword EDX:EAX reg/mem32 EAX EDX –2 31 to 2 31 –1Double quadword/quadwordRDX:RAX reg/mem64 RAX RDX –2 63 to 2 63 –1The instruction truncates non-integral results towards 0. The sign of the remainder isalways the same as the sign of the dividend, <strong>and</strong> the absolute value of the remainder isless than the absolute value of the divisor. An overflow generates a #DE (divide error)exception, rather than setting the OF flag.To avoid overflow problems, precede this instruction with a CBW, CWD, CDQ, or CQOinstruction to sign-extend the dividend.Mnemonic Opcode DescriptionIDIV reg/mem8 F6 /7IDIV reg/mem16 F7 /7Perform signed division of AX by the contents of an 8-bit registeror memory location <strong>and</strong> store the quotient in AL <strong>and</strong> theremainder in AH.Perform signed division of DX:AX by the contents of a 16-bitregister or memory location <strong>and</strong> store the quotient in AX <strong>and</strong> theremainder in DX.144 IDIV

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!