版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
AssemblyProgrammingCopyright©2009TexasInstruments.Allrightsreserved.
TechnicalTrainingOrganizationT
TOAppendixCTMS320C28x™MCUWorkshopLearningObjectivesPerformsimpleprogramcontrolusingbranchandconditionalcodesWriteC28xcodetoperformbasicarithmeticUsethemultipliertoimplementsum-of-productsequationsUsetheRPTinstruction(repeat)tooptimizeloopsUseMACforlongsum-of-productsEfficientlytransferthecontentsofoneareaofmemorytoanotherExamineread-modify-writeoperationsProgramControlALU/MultiplyOperationsDataMoveLogicalOperationsSpecialInstructionsBranchTypesandRangeBranchoffset+/-32K2-word
instructionLongBranchabsolute4M2-word
instructionPCShortBranch
offset+127/-128
1-wordinstructionProgramMemory0x0000000x3FFFFF3BranchTypesProgramControl-BranchesFunctionShortBranch
SB 8bit,cond 7/4 1FastShortBranch
SBF 8bit,EQ|NEQ|TC|NTC 4/4 1FastRelativeBranch
B 16bit,cond 7/4 2FastBranch
BF 16bit,cond 4/4 2AbsoluteBranch
LB 22bit 4 2DynamicBranch
LB *XAR7 4 1BranchonAR
BANZ 16bit,ARn-- 4/2 2Branchoncompare BAR 16bit,ARn,ARn,EQ|NEQ 4/2 2TheassemblerwilloptimizeBtoSBifpossibleNEQEQGTGEQLTLEQHIHIS(C)LO(NC)LOSNOVOVNTCTCUNCNBIOConditionCodeInstructionCyclesT/FSizeConditionflagsaresetontheprioruseoftheALUProgramControl-Call/ReturnFunctionCallCodeCall LCR 22bit 4 LRETR 4DynamicCall LCR *XARn 4 LRETR 4InterruptReturn
IRET 8CyclesReturncodeCyclesMoreCallvariationsintheuserguideareforcodebackwardcompatibilityStackLocal
VarRPCOldRPCPCFuncLCRFuncLRETRRPC22-bitoldRetAddrRetAddrNewRPCBANZLoopControlExamplelen.set5x .usect“samp”,6y .set(x+len) .sect“code” MOVLXAR2,#x MOVAR3,#len-2 MOVAL,*XAR2++sum: ADDAL,*XAR2++ BANZ sum,AR3-- MOV*(0:y),ALAR3COUNTDatax0x1x2x3x4xyXAR2AuxiliaryregisterusedasloopcounterBranchifAuxiliaryRegisternotzeroTestperformedonlower16-bitsofXARxonlyProgramControlALU/MultiplyOperationsDataMoveLogicalOperationsSpecialInstructionsALUandAccumulatorALUandBarrelShifterACCAH(31-16)AL(15-0)AH.MSBAH.LSBAL.MSBAL.LSB16/32datamem,16/32bitregistersProduct(32)MUXST0,ST18/16ImmAccumulator-BasicMathInstructionsMOV Ax,loc16ADD Ax,loc16SUB Ax,loc16AND Ax,loc16OR Ax,loc16XOR Ax,loc16AND Ax,loc16,#16bNOT AxNEG AxMOV loc16,AxAx=AHorALOperationsxxxAx,#16b;wordxxxBAx,#8b;bytexxxL ACC,#32b;longxxx=instruction:MOV,ADD,SUB,...
Ax=AH,orAL
Assemblerwillautomaticallyconvertto1wordinstruction.TwowordinstructionswithshiftoptionOnewordinstruction,noshiftADDACC,#01234h<<4ADDBAL,#34hACCOperationsMOV ACC,loc16<<shiftADD SUB }frommemory(leftshiftoptional)MOV ACC,#16b<<shiftADDSUB }16-bitconstant(leftshiftoptional)MOV loc16,ACC<<shift;ALMOVH loc16,ACC<<shift;AHFormatExVariationShifttheAccumulatorShiftfullACCLSL ACC<<shiftSFR ACC>>shiftLSL ACC<<TSFR ACC>>TACC31………0SFRACC31………0LSL0CCSXMShiftALorAHLSL AX<<TLSR AX<<TASR AX>>TLSL AX<<shift
LSR AX<<shiftASR AX>>shiftAx15………0ASRAx15………0LSL0CCSXMAx15………0LSRC0(1-16)(0-15)32BitShiftOperations[ACC]ACC31………00CExamples:LSLL ACC,TLSRL ACC,T
ASRL ACC,TACC31………0C0or1ACC31………0C0Note:T(4:0)areused;otherbitsareignoredbasedonSXMLogicalShiftLeft–Long:LSLLLogicalShiftRight–Long:LSRLArithmeticShiftRight–Long:ASRLMultiplyUnitPRegister(32)ACC(32)Shift(PM)32x32MultiplyUnit16x16DataMem
orRegister
ProgMem(16)orImmed(8,16)XTRegister
MUXTRegisterMultiplierInstructions
Instruction Execution Purpose MOV T,loc16 T=loc16 GetfirstoperandMPY ACC,T,loc16 ACC=T*loc16 ForsingleorfirstproductMPY P,T,loc16 P=T*loc16 FornthproductMPYB ACC,T,#8bu ACC=T*8bu Using8-bitunsignedconstMPYB P,T,#8bu P=T*8bu Using8-bitunsignedconstMOV ACC,P ACC=P Move1stproduct<<PMtoACCADD ACC,P ACC+=P Addnthproduct<<PMtoACCSUB ACC,P ACC-=P Subnthproduct<<PMfr.ACCInstructionMPYA P,T,#16b ACC+=P<<PM then P=T*#16bMPYA P,T,loc16 ACC+=P<<PM then P=T*loc16MPYS P,T,loc16 ACC-=P<<PM then P=T*loc16ExecutionMOVP T,loc16 ACC=P<<PM T=loc16MOVA T,loc16 ACC+=P<<PM T=loc16
MOVS T,loc16 ACC-=P<<PM T=loc16Sum-of-ProductsZAPA ;ACC=P=OVC=0MOV T,@X1;T=X1MPY P,T,@A;P=A*X1MOVA T,@X2;T=X2;ACC=A*X1MPY P,T,@B;P=B*X2MOVA T,@X3 ;T=X3;ACC=A*X1+B*X2MPY P,T,@C;P=C*X3MOVA T,@X4;T=X4;ACC=A*X1+B*X2+C*X3MPY P,T,@D;P=D*X4ADDLACC,P<<PM;ACC=YMOVL@y,ACC Y=A*X1+B*X2+C*X3+D*X432x32LongMultiplicationIMPYAL P,XT,loc32 P=u(XT)*u(loc32)QMPYAL ACC,XT,loc32 ACC=(XT)*(loc32)XYXXO
*
Y0Z1Z0IMACL P,loc32,*XAR7 ACC+=P;P=u(loc32)*u(loc32)QMACL P,loc32,*XAR7 ACC+=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-1word Lowoverhead-1cycleEasytouseNon-interruptibleRequiresuseof||beforenextlineMaybenestedwithinBANZloopsOptions:RPT#8bit upto256iterationsRPTloc16 location“loc16”holdscountvalueInstruction CyclesRPTBANZ14.NExample:intx[5]={0,0,0,0,0};x .usect“samp”,5 MOV AR1,#x RPT #4|| MOV *XAR1++,#0RefertoUserGuideformorerepeatableinstructionsSum-of-Products:RPT/MACXAR1++X0X1...X19MOVT,loc16ADDACC,PMPYP,T,loc16MOVAT,loc16ACC+=PT=*ARn++
P=T*(*ARn++)MAC{ZeroACC&P
Repeatsingle
Dualoperand
lastADD
ZAPA RPT #19|| MAC P,*XAR1++,*XAR7++ ADDL ACC,P<<PMx .usect“sample”,20y .usect“result”,2 .sect“coefficient”a0: .word 0x0101 .word 0x0202 ••• .word 0x2020 .sect“code”SOP: SPM 0 MOVW DP,#y MOVL XAR1,#xMOVL XAR7,#a0 MOVL @y,ACC BSOP,UNCXAR7++A0A1...A19SecondoperandmustuseXAR7ProgramControlALU/MultiplyOperationsDataMoveLogicalOperationsSpecialInstructionsDataMoveInstructionsDATA«DATA(4G«64K)DATA«PGM(4G«4M)FasterthanLoad/Store,avoidsaccumulatorAllowsaccesstoprogrammemoryOptimalwithRPT(speedandcodesize)InRPT,non-memaddressisauto-incrementedinPCMOVloc16,*(0:16bit)MOV*(0:16bit),loc1632-bitaddressmemorylocation16-bitaddressconcatenatedwith16leadingzeros .sect“.code”START: MOVL XAR5,#x MOVL XAR7,#TBL
RPT #len-1|| PREAD *XAR5++,*XAR7 ...x .usect “.samp”,4 .sect“.coeff”TBL: .word 1,2,3,4len .set $-TBLPREAD loc16,*XAR7PWRITE *XAR7,loc16pointerwitha22-bitprogrammemoryaddressConditionalMovesInstruction Execution(ifCONDismet)MOVloc16,AX,COND[loc16]=AXMOVBloc16,#8bit,COND[loc16]=8bitIfA<B,ThenB=AAccumulator00000120MOVW DP,#AMOV AL,@ACMP AL,@BExampleA.usect “var”,2,1B.set A+1.sect “code”MOV@B,AL,LT01200320DataMemoryBA0120DataMemoryBA0120BeforeAfterInstruction
Execution(ifCONDismet)MOVLloc32,ACC,COND[loc32]=AXByteOperationsMOVBAX.LSB,loc1600000000ByteAXMOVBAX.MSB,loc16ByteNochangeAXMOVBloc16,AX.MSBByteloc16NochangeMOVBloc16,AX.LSBByteloc16NochangeForloc16=*+XARn[Offset]OddOffsetEvenOffsetloc16Byte= 1.Lowbyteforregisteraddressing 2.Lowbytefordirectaddressing 3.SelectedbyteforoffsetindirectaddressingByteAddressingMOVL XAR2,#MemAMOVB *+XAR2[1],AL.LSBMOVB *+XAR2[2],AL.MSBMOVB *+XAR2[5],AH.LSBMOVB *+XAR2[6],AH.MSBAR2AH.MSBAH.LSBAL.MSBAL.LSB16bitmemory01020506123456780407000334561278MOVL XAR2,#MemAMOVBAL.LSB,*+XAR2[1]MOVBAL.MSB,*+XAR2[2]MOVBAH.LSB,*+XAR2[4]MOVBAH.MSB,*+XAR2[7]ExampleofBytePackingExampleofByteUn-PackingTestandChangeMemoryInstruction ExecutionAffectsTBIT loc16,#(0-15) ST0(TC)=loc16(bit_no) TCTSET loc16,#(0-15) Test(loc16(bit))thensetbit TCTCLR loc16,#(0-15) Test(loc16(bit))thenclrbit TCCMPB AX,#8bit
Test(AX-8bitunsigned) C,N,ZCMP AX,loc16 Test(AX–loc16) C,N,ZCMP loc16,#16b Test(loc16-#16bitsigned) C,N,ZCMPL ACC,@P Test(ACC-P<<PM) C,N,ZMIN/MAXOperations MOVL ACC,#0 MOVL XAR1,#table RPT #(table_length–1)|| MAXL ACC,*XAR1++Findthemaximum32-bitnumberinatable:
Instruction ExecutionMAX ACC,loc16 ifACC<loc16,ACC=loc16 ifACC>=loc16,donothingMIN ACC,loc16 ifACC>loc16,ACC=loc16 ifACC<=loc16,donothingMAXL ACC,loc32 ifACC<loc32,ACC=loc32 ifACC>=loc32,donothingMINL ACC,loc32 ifACC>loc32,ACC=loc32 ifACC<=loc32,donothingMAXCUL P,loc32 ifP<loc32,P=loc32(for64bitmath) ifP>=loc32,donothingMINCUL P,loc32 ifP>loc32,P=loc32(for64bitmath) ifP<=loc32,donothingRead-Modify-WriteInstructionsANDloc16,#16bORloc16,#16bXORloc16,#16bADDloc16,#16bSUBRloc16,#16bANDloc16,AXORloc16,AXXORloc16,AXADDloc16,AXSUBloc16,AXSUBRloc16,AXINCloc16DECloc16TSETloc16,#bitTCLRloc16,#bitAH,
AL16-bit
constantWorkdirectlyonmemory–bypassACCAtomicOperations–protectedfrominterruptsRead-Mod
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年跌倒防护指南
- 2026安徽省社会科学院招聘高层次人才16人备考题库带答案详解(达标题)
- 2026黑龙江黑河市嫩江市乡镇卫生院招聘医学相关专业毕业生2人备考题库及参考答案详解(巩固)
- 2026川投(达州)燃气发电有限公司招聘3人备考题库附参考答案详解(培优a卷)
- 2026河南省烟草专卖局(公司)高校毕业生招聘190人备考题库附答案详解(基础题)
- 2026年宿州九中教育集团(宿马南校区) 教师招聘备考题库带答案详解(培优)
- 2026贵州黔东南州麻江县谷硐镇中心卫生院招聘1人备考题库含答案详解(综合题)
- 2026上半年广东广州市越秀区教育局招聘事业编制教师83人备考题库带答案详解(突破训练)
- 2026四川大学华西医院刘吉峰主任医师课题组专职博士后招聘备考题库含答案详解(研优卷)
- 2026中兴财经暑假实习生招聘备考题库带答案详解(夺分金卷)
- 2026年高考语文作文六大主题分类与命题预测
- 2026年池州市保险行业协会工作人员招聘备考题库含答案详解(满分必刷)
- 北京市延庆区2025-2026学年高三下学期高考一模英语试卷
- 2024年12月日语能力考试N2真题答案详解
- 2025-2026学年六年级下学期教科版科学单元测试卷(第二单元)(试题+答案)
- (二诊)德阳市2023级高三第二次诊断考试语文试卷(含标准答案)
- 级配碎石基层监理实施细则
- 2025年离婚抖音作品离婚协议书
- T/CBMMAS 012-2022智能坐便器适老化要求与评价
- 预应力高强混凝土管桩(PHC)施工组织方案
- 奇瑞汽车售后服务管理系统操作手册
评论
0/150
提交评论