80x86 Instruction Set Reference.docx
《80x86 Instruction Set Reference.docx》由会员分享,可在线阅读,更多相关《80x86 Instruction Set Reference.docx(22页珍藏版)》请在冰豆网上搜索。
80x86InstructionSetReference
80x86InstructionSetReference
1.3.3.InstructionOperands
Wheninstructionsarerepresentedsymbolically,asubsetoftheIA-32assemblylanguageisused.Inthissubset,aninstructionhasthefollowingformat:
label:
mnemonicargument1,argument2,argument3
where:
•Alabelisanidentifierwhichisfollowedbyacolon.
•Amnemonicisareservednameforaclassofinstructionopcodeswhichhavethesamefunction.opcode:
operatingcode的缩写。
•Theoperandsargument1,argument2,andargument3areoptional.Theremaybefromzerotothreeoperands,dependingontheopcode.Whenpresent,theytaketheformofeitherliteralsoridentifiersfordataitems.Operandidentifiersareeitherreservednamesofregistersorareassumedtobeassignedtodataitemsdeclaredinanotherpartoftheprogram(whichmaynotbeshownintheexample).Whentwooperandsarepresentinanarithmeticorlogicalinstruction,therightoperandisthesourceandtheleftoperandisthedestination.
Forexample:
LOADREG:
MOVEAX,SUBTOTAL
Inthisexample,LOADREGisalabel,MOVisthemnemonicidentifierofanopcode,EAXisthedestinationoperand,andSUBTOTAListhesourceoperand.Someassemblylanguagesputthesourceanddestinationinreverseorder.
1.3.4.HexadecimalandBinaryNumbers
Base16(hexadecimal)numbersarerepresentedbyastringofhexadecimaldigitsfollowedbythecharacterH(forexample,F82EH).Ahexadecimaldigitisacharacterfromthefollowingset:
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,andF.
Base2(binary)numbersarerepresentedbyastringof1sand0s,sometimesfollowedbythecharacterB(forexample,1010B).The“B”designationisonlyusedinsituationswhereconfusionastothetypeofnumbermightarise.
1.3.5.SegmentedAddressing
Theprocessorusesbyteaddressing.Thismeansmemoryisorganizedandaccessedasasequenceofbytes.Whetheroneormorebytesarebeingaccessed,abyteaddressisusedtolocatethebyteorbytesinmemory.Therangeofmemorythatcanbeaddressediscalledanaddressspace.
Theprocessoralsosupportssegmentedaddressing.Thisisaformofaddressingwhereaprogrammayhavemanyindependentaddressspaces,calledsegments.Forexample,aprogramcankeepitscode(instructions)andstackinseparatesegments.Codeaddresseswouldalwaysrefertothecodespace,andstackaddresseswouldalwaysrefertothestackspace.Thefollowingnotationisusedtospecifyabyteaddresswithinasegment:
Segment-register:
Byte-address
Forexample,thefollowingsegmentaddressidentifiesthebyteataddressFF79HinthesegmentpointedbytheDSregister:
DS:
FF79H
Thefollowingsegmentaddressidentifiesaninstructionaddressinthecodesegment.TheCSregisterpointstothecodesegmentandtheEIPregistercontainstheaddressoftheinstruction.
CS:
EIP
InstructionFormat
2.1.GENERALINSTRUCTIONFORMAT
AllIA-32instructionencodingsaresubsetsoftheformatshowninFigure2-1.Instructionsconsistofoptionalinstructionprefixes(inanyorder),primaryopcodebytesofuptothreeopcodebytes,anaddressing-formspecifier(ifrequired)consistingoftheModR/MbyteandsometimestheSIB(Scale-Index-Base)byte,adisplacement(ifrequired),andanimmediatedatafield(ifrequired).
2.3.OPCODES
Aprimaryopcodecanbe1,2,or3bytesinlength.Anadditional3-bitopcodefieldissometimesencodedintheModR/Mbyte.Smallerfieldscanbedefinedwithintheprimaryopcode.Suchfieldsdefinethedirectionofoperation,sizeofdisplacements,registerencoding,conditioncodes,orsignextension.Theencodingfieldsusedbyanopcodevarydependingontheclassofoperation.
Two-byteopcodeformatsforgeneral-purposeandSIMDinstructionsconsistof:
•Anescapeopcodebyte0FHastheprimaryopcodeandasecondopcodebyte
•Amandatoryprefix(66FH,F2H,F3H),anescapeopcodebyte,andasecondopcodebyte
TheModR/Mbyteconsistsofthreebitfields(seeSection2.4.).Inadditiontotheregfieldbeingtreatedasanextendedopcodefieldforsomeinstructions,somepatternsoftheothertwobitfieldsintheModR/Mbytemayalsobeusedtoexpressopcodeinformation.Usingundefinedexpressionoftheprimaryopcodebytes,and/orundefinedexpressionintheopcodeextensionfieldintheModR/Mbyte,and/orundefinedexpressioninotherbitfieldsoftheModR/Mbyteisreserved.ValidopcodeexpressionsaredefinedinAppendixAandAppendixB.Useofanyofreservedopcodeexpressioncancauseunpredictablebehavior.
2.4.MODR/MANDSIBBYTES
Manyinstructionsthatrefertoanoperandinmemoryhaveanaddressing-formspecifierbyte(calledtheModR/Mbyte)followingtheprimaryopcode.TheModR/Mbytecontainsthreefieldsofinformation:
•Themodfieldcombineswithther/mfieldtoform32possiblevalues:
eightregistersand24addressingmodes.
•Thereg/opcodefieldspecifieseitheraregisternumberorthreemorebitsofopcodeinformation.Thepurposeofthereg/opcodefieldisspecifiedintheprimaryopcode.
•Ther/mfieldcanspecifyaregisterasanoperandoritcanbecombinedwiththemodfieldtoencodeanaddressingmode.Sometimes,certaincombinationsofthemodfieldandther/mfieldisusedtoexpressopcodeinformationforsomeinstructions.
CertainencodingsoftheModR/Mbyterequireasecondaddressingbyte(theSIBbyte).Thebase-plus-indexandscale-plus-indexformsof32-bitaddressingrequiretheSIBbyte.TheSIBbyteincludesthefollowingfields:
•Thescalefieldspecifiesthescalefactor.
•Theindexfieldspecifiestheregisternumberoftheindexregister.
•Thebasefieldspecifiestheregisternumberofthebaseregister.
SeeSection2.6.,“Addressing-ModeEncodingofModR/MandSIBBytes”fortheencodingsoftheModR/MandSIBbytes.
2.5.DISPLACEMENTANDIMMEDIATEBYTES
SomeaddressingformsincludeadisplacementimmediatelyfollowingtheModR/Mbyte(ortheSIBbyteifoneispresent).Ifadisplacementisrequired,itcanrequire1,2,or4bytes.
Iftheinstructionspecifiesanimmediateoperand,theoperandalwaysfollowsanydisplacementbytes.Animmediateoperandcanbe1,2or4bytes.
NOTES:
1.ThedefaultsegmentregisterisSSfortheeffectiveaddressescontainingaBPindex,DSforothereffectiveaddresses.
2.Thedisp16nomenclaturedenotesa16-bitdisplacementthatfollowstheModR/Mbyteandthatisaddedtotheindex.
3.Thedisp8nomenclaturedenotesan8-bitdisplacementthatfollowstheModR/Mbyteandthatissignextendedandaddedtotheindex.
•SRC—Representsthesourceoperand.
•DEST—Representsthedestinationoperand.
3.1.4.FlagsAffected
The“FlagsAffected”sectionliststheflagsintheEFLAGSregisterthatareaffectedbytheinstruction.Whenaflagiscleared,itisequalto0;whenitisset,itisequalto1.Thearithmeticandlogicalinstructionsusuallyassignvaluestothestatusflagsinauniformmanner(seeAppendixA,EFLAGSCross-Reference,intheIA-32IntelArchitectureSoftwareDeveloper’sManual,Volume1).Non-conventionalassignmentsaredescribedinthe“Operation”section.Thevaluesofflagslistedasundefinedmaybechangedbytheinstructioninanindeterminatemanner.Flagsthatarenotlistedareunchangedbytheinstruction.
ADC—AddwithCarry
Description
Addsthedestinationoperand(firstoperand),thesourceoperand(secondoperand),andthecarry(CF)flagandstorestheresultinthedestinationoperand.Thedestinationoperandcanbearegisteroramemorylocation;thesourceoperandcanbeanimmediate,aregister,oramemorylocation.(However,twomemoryoperandscannotbeusedinoneinstruction.)ThestateoftheCFflagrepresentsacarryfromapreviousaddition.Whenanimmediatevalueisusedasanoperand,itissign-extendedtothelengthofthedestinationoperandformat.
TheADCinstructiondoesnotdistinguishbetweensignedorunsignedoperands.Instead,theprocessorevaluatestheresultforbothdatatypesandsetstheOFandCFflagstoindicateacarryinthesignedorunsignedresult,respectively.TheSFflagindicatesthesignofthesignedresult.TheADCinstructionisusuallyexecutedaspartofamultibyteormultiwordadditioninwhichanADDinstructionisfollowedbyanADCinstruction.
ThisinstructioncanbeusedwithaLOCKprefixtoallowtheinstructiontobeexecutedatomically.
Operation
DEST←DEST+SRC+CF;
FlagsAffected
TheOF,SF,ZF,AF,CF,andPFflagsaresetaccordingtotheresult.
ADD—Add
ADDAL,imm8Addimm8toAL
ADDAX,imm16Addimm16toAX
ADDEAX,imm32Addimm32toEAX
ADDr/m8,imm8Addimm8tor/m8
ADDr/m16,imm16Addimm16tor/m16
ADDr/m32,imm32Addimm32tor/m32
ADDr/m16,imm8Addsign-extendedimm8tor/m16
ADDr/m32,imm8Addsign-extendedimm8tor/m32
ADDr/m8,r8Addr8tor/m8
ADDr/m16,r16Addr16tor/m16
ADDr/m32,r32Addr32tor/m32
ADDr8,r/m8Addr/m8tor8
ADDr16,r/m16Addr/m16tor16
ADDr32,r/m32Addr/m32tor32
Description
Addsthefirstoperand(destinationoperand)andthesecondoperand(sourceoperand)andstorestheresultinthedestinationoperand.Thedestinationoperandcanbearegisteroramemorylocation;thesourceoperandcanbeanimmediate,aregister,oramemorylocation.(However,twomemoryoperandscannotbeusedinoneinstruction.)Whenanimmediatevalueisusedasanoperand,itissign-extendedtothelengthofthedestinationoperandformat.
TheADDinstructionperformsintegeraddition.ItevaluatestheresultforbothsignedandunsignedintegeroperandsandsetstheOFandCFflagstoindicateacarry(overflow)inthesignedorunsignedresult,respectively.TheSFflagindicatesthesignofthesignedresult.
ThisinstructioncanbeusedwithaLO