




已阅读5页,还剩46页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
CortexM3Thumb-2指令集,李宁武汉理工大学,Agenda,IntroductionGeneralPointsonSyntaxDataprocessingInstructionsBranchandControlFlowInstructionsMemoryAccessInstructionsExceptionGeneratingInstructionsAccessingSpecialRegistersCoprocessorInstructionsMemoryBarriersandSynchronizationFurtherInformation,ARMinstructionsetevolution,KeyTechnologyAdditionsbyArchitectureGeneration,TheThumb-2instructionset,Variable-lengthinstructionsARMinstructionsareafixedlengthof32bitsThumbinstructionsareafixedlengthof16bitsThumb-2instructionscanbeeither16-bitor32-bitCodesizebenefitsThumb-2givesapproximately26%improvementincodedensityoverARMPerformancebenefitsThumb-2givesapproximately25%improvementinperformanceoverThumbTheCortex-M3implementsONLYtheThumb-2instructionset,Syntax,IntheCortex-M3instructionset,thereareoftenseveralpossiblewaysofencodingagivenoperationSyntaxspecifiessemanticsWherethereismorethanonepossibleinstructionforgivensemanticsAssemblyrulesAlwayspicksmallestinstructionExceptforexternalbrancheswhichchooselargestCanuse.N/.Wtoforce16or32bitinstruction(e.g.foralignment)DisassemblyrulesOne-to-onemappingisdefinedtoensurecorrectre-assembly.W/.NsuffixusedforcaseswhenabitpatternwhichdoesntfollowtheaboverulesisdisassembledBinaryoperatorsalwaysdisassembleto3-operandformsExceptforsomecasesof2-operandThumbADDAvoiduseofr13,r14,r15usesp,lr,pcinstead,Registerusage,Ingeneral,allregistersaregeneral-purpose,exceptforthefollowing.r13isusedastheStackPointeranditsusagereflectsthisSPmanipulationrestrictedtoMovementbetweenspandanothergeneral-purposeregisterUsingADDorSUBtoadjustitbyamultipleof4e.g.ADDsp,sp,#N;Nmustbemultipleof4e.g.SUBSP,SP,Rm,LSL#shift;shift=0-3AsfirstoperandinADD,SUB,CMP,CMNIngeneral,SPcannotbeloadedfrommemoryWherethisispermitted,thisisnotedinthispresentationSPwillbeautomaticallyrestrictedtoword-alignedvaluesHardwarewillignorewritestobits0and1PCisgenerallynotpermittedasanoperand,exceptas:BaseregisterinLDRBaseregisterinTBB/TBHDestinationforLDR,orinthelistforPOP/LDM,Exampleassemblersourcefile,AREAARMEX,CODE,READONLYENTRYTHUMBmainMOVr0,#10MOVr1,#3ADDr2,r0,r1;thisisacommentstopBstopdataDCD0 x11,0 x22,0 x33END,Arithmeticinstructions,ThefollowingarithmeticinstructionareavailableADDADCSUBSBCRSBANDBICEORORRORNGeneralsyntaxADDSRd,Rn,op2op2canbeAnimmediateconstantADDr0,r1,#0 x21AnotherregisterwithanoptionalshiftADDr0,r1,r2,LSL#3TheSsuffixcontrolswhethertheinstructionupdatestheconditioncodeflagsbasedontheresultInsomeinstructionsitisoptional,inotherseithercompulsoryornotallowedatall,Constants,AnimmediateconstantcantakeseveralformsAnyconstantproducedby8bitsshiftedleftbyupto32bitsThisallowsany8consecutivebitstobesettoanyvalueReplicatedhalfwordofform0 x00XY00XYReplicatedhalfwordofform0 xXY00XY00Replicatedbyteconstantofform0 xXYXYXYXYAttemptstouseconstantswhicharenotofthisformwillgenerateanassemblyerrorTherearespecialformsofADDandSUBwhichallowlargerconstantsADDWRd,Rm,#imm12;adds12-bitconstantSUBWRd,Rm,#imm12;subtracts12-bitconstant,Availableshiftoperations,Destination,CF,0,Destination,CF,LSL:LogicalShiftLeft,ASR:ArithmeticShiftRight,Multiplicationbyapowerof2,Divisionbyapowerof2,preservingthesignbit,Destination,CF,.0,Destination,CF,LSR:LogicalShiftRight,ROR:RotateRight,Divisionbyapowerof2,BitrotatewithwraparoundfromLSBtoMSB,Destination,RRX:RotateRightExtended,SinglebitrotatewithwraparoundfromCFtoMSB,CF,Datamovement,ThereareanumberofinstructionsformovingbetweenoneregisterandanotherorsettingaregistertoaconstantMOVSRd,#imm;Rd=#immMOVSRd,Rm,shift;Rd=RmwithoptionalshiftMVNhasidenticalsyntaxtoabovebutmoveslogical1scomplementSpecialformscanuselargerconstantsMOVWRd,#imm16;setlower16bitsofregisterand;clearupperhalfwordMOVTRd,#imm16;settop16bitsofregister,Usefulpseudoinstructions,TheassemblerprovidessomeusefulpseudoinstructionsforloadingvaluesintoregistersLoadingacompile-timeconstantintoaregisterLDRRn,=AssemblerwilluseoptimalinstructionsequencetogenerateconstantintospecifiedregisterLoadinganaddressintoaregisterADRRn,AssemblerwillusePC-relativeADDorSUBtogeneratetheaddressofthelabelintothespecifiedregisterADRLisavailableforreferencesoutsidethecurrentsectionThesearetherecommendedmechanismsforgeneratingconstantsintoregisters,TestandCompareinstructions,TheseinstructionsalwayschangetheconditioncodeflagsCMPRn,#imm;compareRnwithconstantCMPRn,Rm,shift;comparewithregisterCMNhassamesyntaxbutcompareswith2scomplementofoperandTEQperformsa“logicalEOR”betweenitsoperandsUsedfortestingforequalitywithoutchangingVflag(asCMPdoes)TSTperformsa“logicalAND”betweenitsoperandsUsedfortestingwhetheroneormorebitsinasubsetissetAlsofortestingwhetherasinglebitissetorclear,Shift/rotateinstructions,TheshiftandrotatefeaturesarealsoavailableviaseparateinstructionsTheseinstructionscanrotateorshifteitherbyaconstantdistanceorbyavariabledistancecontrolledbyanotherregisterTheshift/rotatedistanceistakenfromtheleastsignificantbyteofRmLSRSRd,Rn,#3;Rd=Rn3LSRSRd,Rn,Rm;Rd=RnRmLSL,ASRandRORarealsoavailableTheseinstructionscanoptionallychangetheconditioncodeflags,BitManipulationInstructions,0,31,0,0,0,0,0,0,0,0,1,0,1,0,1,1,0,0,0,0,0,1,1,1,0,1,0,0,0,31,0,0,0,0,0,0,0,0,1,0,1,0,1,1,0,0,0,1,1,0,1,0,0,0,0,0,1,0,1,0,1,1,BFIBitFieldInsert,UBFXUnsignedBitFieldExtract,BFCBitFieldClear,0,RBITReverseBitOrder,Fordetailsofsyntax,seethedocumentation,1,CountLeadingZeros,CLZRd,RmReturnsnumberofbinaryzerobitsbeforethefirstbinaryonebitinaregistervalueSourceregisterisscannedfrommostsignificantbittoleastsignificantbitExecutesin1-cycleResultis32ifnobitsset,zeroifbit31issetUsedinsoftwaredivideandfloatingpointroutinesLeftshiftofRmbyRdwillnormalizeRmSignednormalizerequires1extracycle,0000001011101101.0,R0=,CLZR1,R0,0 x6,R1=,1011101101000000.0,Rm=,MOVR0,R0,LSLR1,EORR1,R0,R0,LSL#1CLZR1,R1MOVR0,R0,LSLR1,Thereare2classesofmultiply-producing32-bitand64-bitresultsMULr0,r1,r2;r0=r1*r2MLAr0,r1,r2,r3;r0=r3+(r1*r2)MLSr0,r1,r2,r3;r0=r3-(r1*r2)64-bitmultiplyinstructionsofferbothsignedandunsignedversionsFortheseinstructionthereare2destinationregistersU|SMULLr4,r5,r2,r3;r5:r4=r2*r3U|SMLALr4,r5,r2,r3;r5:r4=(r2*r3)+r5:r4TherearesignedandunsignedintegerdivisioninstructionsSDIVRd,Rn,RmUDIVRd,Rn,Rm,MultiplyandDivide,Saturatinginstructions,AlthoughCortex-M3doesnotsupportsaturatedarithmetic,theseinstructionsareusefulfordetectingoverflowofsub-wordquantitiesSSATRd,#bit,Rn,shift;saturateRnat#bitTheoptionalshiftcanbeanydistancebutisrestrictedtoLSLorASRUSATdoesthesamewithunsignedvalues0 x00004E74Saturatedtobit16isunchangedbecauseitislessthan216-1Saturatedtobit8,theresultis0 xFFsinceitisgreaterthan28-1,Unchanged,Saturated,Qflagset,Byteordering,ThefollowinginstructionsareusefulwheninterfacingwithadevicewhoseendiannessdiffersfromthatofthecoreREVRd,Rm;reversebyteorderREV16Rd,Rm;reversesbyteorderinhalfwords;separately(2301inaboveexample)REVSHRd,Rm;reversesbyteorderinlowerhalfword;andsignextends(SS01inaboveexample),ByteandHalfwordextraction,SXTBRd,Rm,rotExtracts8-bitvalueandsignextendsto32bitsOptionalRORallowsanybytetobeextracted,SXTHextractsahalfwordandsignextendsUnsignedformsdonotsignextendUXTB,UXTHGeneralOnlyROR#8,#16or#24arepermitted,Quiz,Whatdothefollowinginstructionsdo?ADDSr0,r1,#5BICr0,r0,#0 xFF00Writeinstructionstocarryoutthefollowingoperations:r0=r0+0 x456r1=r24Arethefollowingconstantsvalidwithdataprocessinginstructions?5.0 x1FF7.0 x84006.0 x120012008.0 xFFFFFFFF,Simplebranchinstructions,BranchescanbePC-relativeorabsolutePC-relativebranchinstructionshavethefollowingformatsBlabelBranchrangeis16MBifunconditional,1MBifconditional,AlsohaveabsolutebranchtoaddressinregisterBXRn;unconditionalonly,Conditioncodes,ThepossibleconditioncodesarelistedbelowNoteAListhedefaultanddoesnotneedtobespecified,Subroutines,ImplementingaconventionalsubroutinecallrequirestwostepsStorethereturnaddressBranchtotheaddressoftherequiredsubroutineThesestepsarecarriedoutinoneinstruction,BLThereturnaddressisstoredinthelinkregister(lr/r14)Branchrangeis16MBReturningisperformedusingBXtobranchbacktotheaddressstoredinlr,CanalsobranchtoaddressinregisterBLXRn;unconditionalonly,Branchtables,TBBr0,r1,offset1,offset2,offset3,offset4,offsetn,+,pc,destination,Theseinstructionscanbeusedtoimplementsimplebranchtables,pccanbeusedasthebaseregister,allowingthetabletobeplacedinlineMaximumbranchrangeis+514bytesfromcurrentinstructionTBHindexesanarrayofhalfwordoffsetsinthesameway,offsetbyr1,x2,CompareandBranch,ComparewithzerofollowedbyabranchisacommonsequenceTraditionally,thisinvolvestwoseparateinstructionsCBZreplacesthesewithoneinstruction,Maximumbranchrangeis+130bytesBranchisforwardsonlyCBNZbranchesontheNEconditionbutisotherwisethesame,If.ThenConditionalBlocks,TheIf.Theninstructioncanbeusedtogenerateblocksofuptofourinstructionsdependentonasinglevalueoftheconditioncodeflags,;if(r0=0);r0=*r1+2;else;r0=*r2+4;ifCMPr0,#0ITTEEEQ;thenLDREQr0,r1ADDEQr0,#2;elseLDRNEr0,r2ADDNEr0,#4,Withintheblock,itisgoodpracticetousetheexplicitconditioncodesoneachinstructionTheITinstructionitselfdoesnotchangetheconditioncodesUnlessspecified,instructionswithintheblockdonotchangethecodeseitherIngeneral,youshouldnotbranchintooroutofanITblockAbranchmaybewrittenasthefinalinstructionSVCmaybeusedanywhereITblockscannotbenested,Quiz,WhatisthedifferencebetweenBandBL?WheredoesBLstorethereturnaddress?Whatistheusualreturninstructionfromasubroutine?Whichhasalongerbranchrange,conditionalorunconditional?WhatisthesizeofeachtableentryinaTBBinstruction?Whichinstructioncanbeusedtoreplaceacompareandaconditionalbranch?HowmanyinstructionscanbemadeconditionalusingIT?,Singleregisterdatatransfer,LDRSTRWordLDRBSTRBByteLDRHSTRHHalfwordLDRSBSignedbyteloadLDRSHSignedhalfwordloadMemorysystemmustsupportallaccesssizesSyntax:LDRRd,STRRd,Notethatmemoryaccessinstructionsdonotupdatetheconditioncodeflags,Addressaccessed,TheaddressaccessedbyLDR/STRisspecifiedbyabaseregisterplusanoffsetTheoffsetcanbeAn8-bitimmediatevaluewhichmaybeaddedorsubtractedLDRr0,r1,#8LDRr0,r1,#-12A12-bitoffset(whichmayonlybeadded)Anotherregister,whichmaybeoptionallyshifted0-3placesleftandaddedLDRr0,r1,r2LDRr0,r1,r2,LSL#2Choiceofpre-indexedorpost-indexedaddressing,0 x5,0 x5,0 x200,r1,BaseRegister,0 x200,0 x5,r0,SourceRegisterforSTR,12,Offset,0 x20c,0 x200,r1,OriginalBaseRegister,0 x200,0 x5,r0,SourceRegisterforSTR,12,Offset,0 x20c,0 x20C,r1,UpdatedBaseRegister,Auto-updateform:STRr0,r1,#12!,PreorPostindexedaddressing?,Pre-indexed:STRr0,r1,#12,Post-indexed:STRr0,r1,#12,Only8-bitconstantoffsetscanbeusedwithpost-indexedaddressing,Load/StoreDouble,LDRDandSTRDtransfertworegistersatatimeMoreefficientthattwoseparateLDR/STRinstructionsFewinstructionfetchesMaymakeuseofsequentialbustransactionsLDRDRd1,Rd2,Rn,#offset!Positiveornegative8-bitoffsetismultipliedby4beforeuseWritebackispossiblebutRncannotbeoneofthedestinationregistersDestinationregistersmustbedifferentLDRDRd1,Rd2,Rn,#offsetPositiveornegative8-bitoffsetismultipliedby4beforeuseAllregistersmustbedifferentSTRDSameaddressingmodesSourceregisterscanbethesameWritebackispossiblebutRnmustnotbeeitherofthesourceregisters,TheLoadandStoreMultipleinstructions(LDM/STM)allowbetween2and16registerstobetransferredtoorfrommemoryOrderofregisterstransferscannotbespecifiedMusthaveatleast2registersinthelistLowestregisternumberisalwaystransferredto/fromlowestmemorylocationaccessedLDMIAr10,r0,r1,r4BaseregisterspecifieswherememoryaccessshouldoccurTheseinstructionsareveryefficientforMovingblocksofdataLDM/STMcanbeinterruptedWillbecontinuedonreturnifpossible,elserestarted,Blockdatatransfers,r10,IncreasingAddress,LDM/STMoperation,Syntax:Rb!,2addressingmodes:LDMIA/STMIA-incrementafterLDMDB/STMDB-decrementbefore,IA,r1,IncreasingAddress,r4,r0,r10,DB,LDMxxr10,r0,r1,r4STMxxr10,r0,r1,r4,BaseRegister(Rb),TheSTM/LDMinstructionscanbeusedforefficientblockcopyingofmemoryForexample;r8pointstostartofsourcedata;r9pointstoendofsourcedata;r10pointstostartofdestinationdataloopLDMIAr8!,r0-r7;load32bytesSTMIAr10!,r0-r7;andstorethemCMPr8,r9;checkfortheendBLTloop;andloopInthisexample8wordsarecopiedperloop,Memoryblockcopying,Stackinstructions,Forstackoperations,therearededicatedPUSHandPOPinstructionsTheseimplementaFullDescendingstackusingr13asthestackpointerTheyareactuallysynonymsforLDMIAandSTMDBPUSHreglistPushesalistofregistersontothestackPOPreglistPopsalistofregistersoffthestackNotethatPUSH/POPwithonlyoneregisterinthelistareencodedusingLDR/STRratherthanLDM/STMe.g.PUSHr0willuseSTRr0,sp,#-4!Inthissituation,LDR/STRarequickerthanLDM/STM,Thestackinoperation,100,FF,1234,A0BE,8034,OperationofaFullDescendingstackTheinstructionsshownarecommonatentryandexitofCprocedures,PUSHr4-r7,lr,Exclusiveloadandstore,Instructionswhichtagamemoryaccessas“exclusive”LDREXRd,Rn,#offsetOperation:Rd=*RnSTREXRd,Rm,Rn,#offsetOperation:*Rn=Rm;Rd=0ifmemoryupdated,else1CLREX;clearsanyrecordofexclusiveaccessforthisprocessorCanbeusedtoimplementOSsemaphoresRequiresmemorysystemsupportonmulti-processorsystemsMOVr1,#0 xFF;loadlocktakenvaluetry_for_lockLDREXr0,LockAddr;loadlockvalueCMPr0,#0;islockfree?STREXEQr0,r1,LockAddr;yes,sotrytoclaimCMPEQr0,#0;succeeded?BNEtry_for_lock;no,sotryagainDMB;yes-nowhavelock,somakesureeveryone;elseknowsaboutitbeforecontinuing,Memoryaccesssizeandalignment,TheARMmemorysystemistreatedasalineararrayofbyteswhichcanbeaccessedaswordsAccesses,ingeneral,mustbealignedonanappropriateboundaryAllalignasexpectedexceptthatdoublewordaccessesrequireonlywordalignmentUnalignedaccessescanresultinavarietyofhardwarebehaviorTheunalignedbitsoftheaddresscanbemaskedandtheaccesstreatedasalignedTheunalignedaccesscanbesupportedinhardwareAppliesonlytowordandhalfwordLDRandSTRandtoTBHAllothertypesofmemoryaccessalwaysgenerateanalignmentfaultGenerateanalignmentfault,Quiz,WhichARMload/storeinstructionsallowyoutoexpresstheaddressasaconstant?WhataretheadvantagesofLDM/STMoverLDR/STR?Whichregisterisusedasthestackpointer?Whichinstructionswouldyouusetoimplementasemaphore?Whichaccesssizesmustthememorysystemsupport?,Exceptiongeneratinginstructions,SVC(formerlySWI)CausesaSystemCallexceptionHandledbythesystemviatheexceptionvectortableUsedtogetaccesstoprivilegedoperationsBKPTCausesentrytodebugstateFaultsifdebugisdisabled(withHardFault)UsedforsemihostingAlwaysunconditional,eveninsideanITblock,Readingspecialregisters,TheMRSinstructionreadsspecialregistersintoageneral-purposeregisterMRSRd,stack_pointerReadsMSPorPSPMRSRd,status_regReadsIPSR,EPSR,APSR,IEPSR,IPSR,EAPSR,PSRMRSRd,mask_regReadsPRIMASK,BASEPRI,BASEPRI_MAX,FAULTMASKMRSRd,control_regReadsCONTROLGeneralUsermodecannotreadanystackpointerorIPSRzeroswillbereturnedAllEPSRbitsreadaszeroduringnormalexecutionbutcanbereadwheninhaltingdebugmode,Writingspecialregisters,TheMSRinstructioncopiesageneral-purposeregistertoaspecialregisterMSRstatus_reg,RnWritesIPSR,EPSR,APSR,IEPSR,IAPSR,EAPSRorPSRMSRstack_pointer,RnWritesMSPorPSPMSRmask_reg,RnWritesPRIMASK,BASEPRI,BASEPRI_MAXorFAULTMASKMSRcontrol_reg,RnWritesCONTROLGeneralUsermodeisonlyallowedtowriteFPSR,anythingelsewillbeignoredIPSRandEPSRarenotwriteableBASEPRI_MASKoptionupdatestheBASEPRImaskregisteronlywhenthenewvalueincreasestheprioritylevel,Someshortcuts,TheCPSinstructionprovidessomeshorthandforcommonoperationsCPSIEiEquivalenttosettingPRIMASKto0CPSIDiEquivalenttosettingPRIMASKto1CPSIEfEquivalenttosettingFAULTMASKto0CPSIDfEquivalenttosettingFAULTMASKto1,Coprocessorinstructions,TheinstructionsetcontainsspaceforoperationsinvolvingexternalcoprocessorsMRC,MCR,MCRR,MRRCTransferregistersbetweencoreandcoprocessorCDPInstructscoprocessortocarryoutadataprocessingoperationLDC,STCAllowscoprocessordirectload/storeaccesstomemoryFaultsIfthespecifiedcoprocessorisnotpresent,thecorewillgenerateanNOCPUsageFaultAnunrecognisedcoprocessorinstructionwillcauseanUNDEFINSTRUsageFaultForthesyntaxofthese,consultthedocumentation,Memorybarriers,DMBEnsureallmemoryaccessesduetopreviousinstructionswillcompletebeforeanyaccessesduetosubsequentinstructionsNotethatthisensuresorderingofaccesse
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 农发行池州市青阳县2025秋招小语种岗笔试题及答案
- 农发行长春市朝阳区2025秋招笔试综合模拟题库及答案
- 广安邻水县中储粮2025秋招面试典型题目及答案
- 国家能源鄂尔多斯市东胜区2025秋招心理测评常考题型与答题技巧
- 国家能源揭阳市榕城区2025秋招笔试言语理解与表达题专练及答案
- 国家能源柳州市柳城县2025秋招半结构化面试模拟30问及答案
- 2025年甘肃省天水市秦安县中医医院招聘编外人员34人模拟试卷及答案详解(必刷)
- 关爱农民工子女服务活动总结
- 参加家长会心得体会
- 员工个人工作总结12篇
- 2025河北水发节水有限公司公开招聘工作人员16人笔试参考题库附答案解析
- 新版中华民族共同体概论课件第十二讲民族危亡与中华民族意识觉醒(1840-1919)-2025年版
- 2025-2026学年人教版(2024)九年级物理全册第十四章 内能的利用(单元同步检测练习)(含答案)
- 第1课时 10的加、减法(教学设计)-2024-2025学年一年级上册数学人教版
- 2025至2030中国聚烯烃行业项目调研及市场前景预测评估报告
- 2025四川达州宣汉县国有资产管理服务中心县属国有企业招聘劳动合同职工26人笔试历年参考题库附带答案详解
- 新教科版小学1-6年级科学需做实验目录
- 《电子商务法律法规》课程标准
- 医院关于印发《即时检验临床应用管理办法》的通知
- 三年级下册书法练习指导全册教案(湖南美术出版社)
- GB/T 17880.5-1999平头六角铆螺母
评论
0/150
提交评论