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 2005CMPSCMPSBCMPSWCMPSDCMPSQCompare StringsCompares the bytes, words, doublewords, or quadwords pointed to by the rSI <strong>and</strong> rDIregisters, sets or clears the status flags of the rFLAGS register to reflect the results,<strong>and</strong> then increments or decrements the rSI <strong>and</strong> rDI registers according to the state ofthe DF flag in the rFLAGS register. To perform the comparison, the instructionsubtracts the second oper<strong>and</strong> from the first oper<strong>and</strong> <strong>and</strong> sets the status flags in thesame manner as the SUB instruction, but does not alter the first oper<strong>and</strong>. The twooper<strong>and</strong>s must be the same size.If the DF flag is 0, the instruction increments rSI <strong>and</strong> rDI; otherwise, it decrements thepointers. It increments or decrements the pointers by 1, 2, 4, or 8, depending on thesize of the oper<strong>and</strong>s.The forms of the CMPSx instruction with explicit oper<strong>and</strong>s address the first oper<strong>and</strong>at seg:[rSI]. The value of seg defaults to the DS segment, but may be overridden by asegment prefix. These instructions always address the second oper<strong>and</strong> at ES:[rDI]. ESmay not be overridden. The explicit oper<strong>and</strong>s serve only to specify the type (size) ofthe values being compared <strong>and</strong> the segment used by the first oper<strong>and</strong>.The no-oper<strong>and</strong>s forms of the instruction use the DS:[rSI] <strong>and</strong> ES:[rDI] registers topoint to the values to be compared. The mnemonic determines the size of theoper<strong>and</strong>s.Do not confuse this CMPSD instruction with the same-mnemonic CMPSD (comparescalar double-precision floating-point) instruction in the 128-bit media instruction set.Assemblers can distinguish the instructions by the number <strong>and</strong> type of oper<strong>and</strong>s.For block comparisons, the CMPS instruction supports the REPE or REPZ prefixes(they are synonyms) <strong>and</strong> the REPNE or REPNZ prefixes (they are synonyms). Fordetails about the REP prefixes, see “Repeat Prefixes” on page 10. If a conditionaljump instruction like JL follows a CMPSx instruction, the jump occurs if the value ofthe seg:[rSI] oper<strong>and</strong> is less than the ES:[rDI] oper<strong>and</strong>. This action allowslexicographical comparisons of string or array elements. A CMPSx instruction canalso operate inside a loop controlled by the LOOPcc instruction.110 CMPS

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

Saved successfully!

Ooh no, something went wrong!