您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > DSP2835教程附录3DSP汇编语言
AssemblyProgrammingCopyright©2009TexasInstruments.Allrightsreserved.TechnicalTrainingOrganizationTTOAppendixCTMS320C28x™MCUWorkshopLearningObjectivesPerformsimpleprogramcontrolusingbranchandconditionalcodesWriteC28xcodetoperformbasicarithmeticUsethemultipliertoimplementsum-of-productsequationsUsetheRPTinstruction(repeat)tooptimizeloopsUseMACforlongsum-of-productsEfficientlytransferthecontentsofoneareaofmemorytoanotherExamineread-modify-writeoperationsProgramControlALU/MultiplyOperationsDataMoveLogicalOperationsSpecialInstructionsBranchTypesandRangeBranchoffset+/-32K2-wordinstructionLongBranchabsolute4M2-wordinstructionPCShortBranchoffset+127/-1281-wordinstructionProgramMemory0x0000000x3FFFFF3BranchTypesProgramControl-BranchesFunctionShortBranchSB8bit,cond7/41FastShortBranchSBF8bit,EQ|NEQ|TC|NTC4/41FastRelativeBranchB16bit,cond7/42FastBranchBF16bit,cond4/42AbsoluteBranchLB22bit42DynamicBranchLB*XAR741BranchonARBANZ16bit,ARn--4/22BranchoncompareBAR16bit,ARn,ARn,EQ|NEQ4/22TheassemblerwilloptimizeBtoSBifpossibleNEQEQGTGEQLTLEQHIHIS(C)LO(NC)LOSNOVOVNTCTCUNCNBIOConditionCodeInstructionCyclesT/FSizeConditionflagsaresetontheprioruseoftheALUProgramControl-Call/ReturnFunctionCallCodeCallLCR22bit4LRETR4DynamicCallLCR*XARn4LRETR4InterruptReturnIRET8CyclesReturncodeCyclesMoreCallvariationsintheuserguideareforcodebackwardcompatibilityStackLocalVarRPCOldRPCPCFuncLCRFuncLRETRRPC22-bitoldRetAddrRetAddrNewRPCBANZLoopControlExamplelen.set5x.usect“samp”,6y.set(x+len).sect“code”MOVLXAR2,#xMOVAR3,#len-2MOVAL,*XAR2++sum:ADDAL,*XAR2++BANZsum,AR3--MOV*(0:y),ALAR3COUNTDatax0x1x2x3x4xyXAR240nnxyAuxiliaryregisterusedasloopcounterBranchifAuxiliaryRegisternotzeroTestperformedonlower16-bitsofXARxonlyProgramControlALU/MultiplyOperationsDataMoveLogicalOperationsSpecialInstructionsALUandAccumulatorALUandBarrelShifterACCAH(31-16)AL(15-0)AH.MSBAH.LSBAL.MSBAL.LSB16/32datamem,16/32bitregistersProduct(32)MUXST0,ST18/16ImmAccumulator-BasicMathInstructionsMOVAx,loc16ADDAx,loc16SUBAx,loc16ANDAx,loc16ORAx,loc16XORAx,loc16ANDAx,loc16,#16bNOTAxNEGAxMOVloc16,AxAx=AHorALOperationsxxxAx,#16b;wordxxxBAx,#8b;bytexxxLACC,#32b;longxxx=instruction:MOV,ADD,SUB,...Ax=AH,orALAssemblerwillautomaticallyconvertto1wordinstruction.TwowordinstructionswithshiftoptionOnewordinstruction,noshiftADDACC,#01234h4ADDBAL,#34hACCOperationsMOVACC,loc16shiftADDSUB}frommemory(leftshiftoptional)MOVACC,#16bshiftADDSUB}16-bitconstant(leftshiftoptional)MOVloc16,ACCshift;ALMOVHloc16,ACCshift;AHFormatExVariationShifttheAccumulatorShiftfullACCLSLACCshiftSFRACCshiftLSLACCTSFRACCTACC31………0SFRACC31………0LSL0CCSXMShiftALorAHLSLAXTLSRAXTASRAXTLSLAXshiftLSRAXshiftASRAXshiftAx15………0ASRAx15………0LSL0CCSXMAx15………0LSRC0(1-16)(0-15)32BitShiftOperations[ACC]ACC31………00CExamples:LSLLACC,TLSRLACC,TASRLACC,TACC31………0C0or1ACC31………0C0Note:T(4:0)areused;otherbitsareignoredbasedonSXMLogicalShiftLeft–Long:LSLLLogicalShiftRight–Long:LSRLArithmeticShiftRight–Long:ASRLMultiplyUnitPRegister(32)ACC(32)Shift(PM)32x32MultiplyUnit16x16DataMemorRegisterProgMem(16)orImmed(8,16)XTRegisterMUXTRegisterMultiplierInstructionsInstructionExecutionPurposeMOVT,loc16T=loc16GetfirstoperandMPYACC,T,loc16ACC=T*loc16ForsingleorfirstproductMPYP,T,loc16P=T*loc16FornthproductMPYBACC,T,#8buACC=T*8buUsing8-bitunsignedconstMPYBP,T,#8buP=T*8buUsing8-bitunsignedconstMOVACC,PACC=PMove1stproductPMtoACCADDACC,PACC+=PAddnthproductPMtoACCSUBACC,PACC-=PSubnthproductPMfr.ACCInstructionMPYAP,T,#16bACC+=PPMthenP=T*#16bMPYAP,T,loc16ACC+=PPMthenP=T*loc16MPYSP,T,loc16ACC-=PPMthenP=T*loc16ExecutionMOVPT,loc16ACC=PPMT=loc16MOVAT,loc16ACC+=PPMT=loc16MOVST,loc16ACC-=PPMT=loc16Sum-of-ProductsZAPA;ACC=P=OVC=0MOVT,@X1;T=X1MPYP,T,@A;P=A*X1MOVAT,@X2;T=X2;ACC=A*X1MPYP,T,@B;P=B*X2MOVAT,@X3;T=X3;ACC=A*X1+B*X2MPYP,T,@C;P=C*X3MOVAT,@X4;T=X4;ACC=A*X1+B*X2+C*X3MPYP,T,@D;P=D*X4ADDLACC,PPM;ACC=YMOVL@y,ACCY=A*X1+B*X2+C*X3+D*X432x32LongMultiplicationIMPYALP,XT,loc32P=u(XT)*u(loc32)QMPYALACC,XT,loc32ACC=(XT)*(loc32)XYXXO*Y0Z1Z0IMACLP,loc32,*XAR7ACC+=P;P=u(loc32)*u(loc32)QMACLP,loc32,*XAR7ACC+=P;P=(loc32)*(loc32)Integerlongmultiplicationu(long)=u(long)*u(long)Fractionlongmultiplication:(long)=(long)*(long)(long)64=(long)32*(long)32Y1*X1Z3Z2AccumulatorP-registerRepeatNext:RPTFeatures:NextinstructioniteratedN+1timesSavescodespace-1wordLowoverhead-1cycleEasytouseNon-interruptibleRequiresuseof||beforenextlineMaybenestedwithinBANZloopsOptions:RPT#8bitupto256iterationsRPTloc16location“loc16”holdscountvalueInstructionCyclesRPTBANZ14.NExample:intx[5]={0,0,0,0,0};x.usect“samp”,5MOVAR1,#xRPT#4||MOV*XAR1++,#0RefertoUserGuideformorerepeatableinstructionsSum-of-Products:RPT/MAC190nnnaxyXAR1++X0X1...X19MOVT,loc16ADDACC,PMPYP,T,loc16MOVAT,loc16ACC+=PT=*ARn++P=T*(*ARn++)MAC{ZeroACC&PRepeatsingleDualoperandlastADDZAPARPT#19||MACP,*XAR1++,*XAR7++ADDLACC,PPMx.usect“sample”,20y.usect“result”,2.sect“coefficient”a0:.word0x0101.word0x0202•••.word0x2020.sect“code”SOP:SPM0MOVWDP,#yMOVLXAR1,#xMOVLXAR7,#a0MOVL@y
本文标题:DSP2835教程附录3DSP汇编语言
链接地址:https://www.777doc.com/doc-2871028 .html