收藏 分享(赏)

DSP 2835 教程 附录3 DSP汇编语言.ppt

上传人:scg750829 文档编号:7269028 上传时间:2019-05-12 格式:PPT 页数:29 大小:233KB
下载 相关 举报
DSP  2835  教程  附录3  DSP汇编语言.ppt_第1页
第1页 / 共29页
DSP  2835  教程  附录3  DSP汇编语言.ppt_第2页
第2页 / 共29页
DSP  2835  教程  附录3  DSP汇编语言.ppt_第3页
第3页 / 共29页
DSP  2835  教程  附录3  DSP汇编语言.ppt_第4页
第4页 / 共29页
DSP  2835  教程  附录3  DSP汇编语言.ppt_第5页
第5页 / 共29页
点击查看更多>>
资源描述

1、Assembly Programming,Copyright 2009 Texas Instruments. All rights reserved.,Appendix C TMS320C28x MCU Workshop,Learning Objectives,Perform simple program control using branch and conditional codes Write C28x code to perform basic arithmetic Use the multiplier to implement sum-of-products equations U

2、se the RPT instruction (repeat) to optimize loops Use MAC for long sum-of-products Efficiently transfer the contents of one area of memory to another Examine read-modify-write operations,Program Control ALU / Multiply Operations Data Move Logical Operations Special Instructions,Branch Types and Rang

3、e,PC,Program Memory,0x000000,0x3FFFFF,3 Branch Types,Program Control - Branches,Function,Short Branch SB 8bit,cond 7/4 1 Fast Short Branch SBF 8bit,EQ|NEQ|TC|NTC 4/4 1 Fast Relative Branch B 16bit,cond 7/4 2 Fast Branch BF 16bit,cond 4/4 2 Absolute Branch LB 22bit 4 2 Dynamic Branch LB *XAR7 4 1 Bra

4、nch on AR BANZ 16bit,ARn- 4/2 2 Branch on compare BAR 16bit,ARn,ARn,EQ|NEQ 4/2 2,The assembler will optimize B to SB if possible,NEQ EQ GT GEQ,LT LEQ HI HIS (C),LO (NC) LOS NOV OV,NTC TC UNC NBIO,Condition Code,Instruction,Cycles T/F,Size,Condition flags are set on the prior use of the ALU,Program C

5、ontrol - Call/Return,BANZ Loop Control Example,Auxiliary register used as loop counterBranch if Auxiliary Register not zeroTest performed on lower 16-bits of XARx only,Program Control ALU / Multiply Operations Data Move Logical Operations Special Instructions,ALU and Accumulator,16/32 data mem, 16/3

6、2 bit registers,Product (32),MUX,Accumulator - Basic Math Instructions,MOV Ax, loc16 ADD Ax, loc16 SUB Ax, loc16,AND Ax, loc16 OR Ax, loc16 XOR Ax, loc16,AND Ax,loc16,#16b NOT Ax NEG Ax MOV loc16,Ax,Ax = AH or AL Operations,xxx = instruction: MOV, ADD, SUB, . Ax = AH, or AL Assembler will automatica

7、lly convert to 1 word instruction.,Two word instructions with shift option One word instruction, no shift,ADD ACC, #01234h4 ADDB AL, #34h,ACC Operations,MOV ACC,loc16shift ADD SUB,from memory (left shift optional),MOV loc16,ACC shift ;AL MOVH loc16,ACC shift ;AH,Format,Ex,Variation,Shift the Accumul

8、ator,Shift full ACC,LSL ACC shift,LSL ACC T,ACC,31 0,SFR,ACC,31 0,LSL,0,C,C,SXM,Shift AL or AH,LSL AX T,LSL AX shift,Ax,15 0,ASR,Ax,15 0,LSL,0,C,C,SXM,Ax,15 0,LSR,C,0,(1-16),(0-15),32 Bit Shift Operations ACC,ACC,31 0,0,C,Examples: LSLL ACC, T LSRL ACC, T ASRL ACC, T,ACC,31 0,C,0 or 1,ACC,31 0,C,0,N

9、ote: T(4:0) are used; other bits are ignored,based on SXM,Logical Shift Left Long: LSLL,Logical Shift Right Long: LSRL,Arithmetic Shift Right Long: ASRL,Multiply Unit,Multiplier Instructions,Instruction Execution Purpose,MOV T,loc16 T = loc16 Get first operand,MPY ACC,T,loc16 ACC = T*loc16 For singl

10、e or first product MPY P,T,loc16 P = T*loc16 For nth product,MPYB ACC,T,#8bu ACC = T*8bu Using 8-bit unsigned const MPYB P,T,#8bu P = T*8bu Using 8-bit unsigned const,MOV ACC,P ACC = P Move 1st productPM to ACC ADD ACC,P ACC += P Add nth productPM to ACC SUB ACC,P ACC -= P Sub nth productPM fr. ACC,

11、Sum-of-Products,ZAPA ;ACC = P = OVC = 0 MOV T,X1 ;T = X1 MPY P,T,A ;P = A*X1 MOVA T,X2 ;T = X2 ;ACC = A*X1 MPY P,T,B ;P = B*X2 MOVA T,X3 ;T = X3 ;ACC = A*X1 + B*X2 MPY P,T,C ;P = C*X3 MOVA T,X4 ;T = X4;ACC = A*X1 + B*X2 + C*X3 MPY P,T,D ;P = D*X4 ADDL ACC,PPM ;ACC = Y MOVL y,ACC,Y = A*X1 + B*X2 + C*

12、X3 + D*X4,32x32 Long Multiplication,IMPYAL P,XT,loc32 P = u(XT)*u(loc32) QMPYAL ACC,XT,loc32 ACC = (XT)*(loc32),X,Y,X,XO * Y0,Z1 Z0,IMACL P,loc32,*XAR7 ACC += P; P = u(loc32)*u(loc32) QMACL P,loc32,*XAR7 ACC += P; P = (loc32)*(loc32),Integer long multiplication u(long) = u(long) * u(long),Fraction l

13、ong multiplication: (long) = (long) * (long),(long) 64 = (long) 32 * (long) 32,Y1 * X1,Z3 Z2,Accumulator P-register,Repeat Next: RPT,Features: Next instruction iterated N+1 times Saves code space - 1 word Low overhead - 1 cycle Easy to use Non-interruptible Requires use of | | before next line May b

14、e nested within BANZ loops,Options: RPT #8bit up to 256 iterations RPT loc16 location “loc16” holds count value,Refer to User Guide for more repeatable instructions,Sum-of-Products: RPT / MAC,XAR1+,X0,X1,.,X19,MOV T,loc16 ADD ACC,P,MPY P,T,loc16,MOVA T,loc16,MAC,XAR7+,A0,A1,.,A19,Second operand must

15、 use XAR7,Program Control ALU / Multiply Operations Data Move Logical Operations Special Instructions,Data Move Instructions,DATA DATA (4G 64K),DATA PGM (4G 4M),32-bit address memory location,16-bit address concatenated with 16 leading zeros,Conditional Moves,If AB, Then B=A,MOVW DP, #A MOV AL, A CM

16、P AL, B,A .usect “var”,2,1 B .set A+1.sect “code”,MOV B, AL, LT,Before,After,Instruction Execution (if COND is met) MOVL loc32,ACC,COND loc32 = AX,Byte Operations,Byte = 1. Low byte for register addressing2. Low byte for direct addressing3. Selected byte for offset indirect addressing,Byte Addressin

17、g,MOVL XAR2, #MemA,MOVB *+XAR21, AL.LSB,MOVB *+XAR22, AL.MSB,MOVB *+XAR25, AH.LSB,MOVB *+XAR26, AH.MSB,AH.MSB AH.LSB AL.MSB AL.LSB,16 bit memory,12 34 56 78,MOVL XAR2, #MemA,MOVB AL.LSB,*+XAR21,MOVB AL.MSB,*+XAR22,MOVB AH.LSB,*+XAR24,MOVB AH.MSB,*+XAR27,Example of Byte Packing,Example of Byte Un-Pac

18、king,Test and Change Memory,Instruction Execution Affects TBIT loc16,#(0-15) ST0(TC) = loc16(bit_no) TC TSET loc16,#(0-15) Test (loc16(bit) then set bit TC TCLR loc16,#(0-15) Test (loc16(bit) then clr bit TC CMPB AX, #8bit Test (AX - 8bit unsigned) C,N,Z CMP AX, loc16 Test (AX loc16) C,N,Z CMP loc16

19、,#16b Test (loc16 - #16bit signed) C,N,Z CMPL ACC, P Test (ACC - P PM) C,N,Z,MIN/MAX Operations,MOVL ACC,#0MOVL XAR1,#tableRPT #(table_length 1) | MAXL ACC,*XAR1+,Find the maximum 32-bit number in a table:,Read-Modify-Write Instructions,AND loc16,#16b OR loc16,#16b XOR loc16,#16b,ADD loc16,#16b SUBR

20、 loc16,#16b,AND loc16,AX OR loc16,AX XOR loc16,AX,ADD loc16,AX SUB loc16,AX SUBR loc16,AX,INC loc16 DEC loc16,TSET loc16,#bit TCLR loc16,#bit,AH, AL,16- bit constant,Work directly on memory bypass ACCAtomic Operations protected from interrupts,Read-Modify-Write Examples,MOV AL, VarB ADD VarA, AL,Var

21、A += VarB,VarA += 100,VarA += 1,ADD VarA,#100,INC VarA,SETC INTM MOV AL, VarB ADD AL, VarA MOV VarA, AL CLRC INTM,SETC INTM MOV AL, VarA ADD AL, #100 MOV VarA, AL CLRC INTM,SETC INTM MOV AL, VarA ADD AL, #1 MOV VarA, AL CLRC INTM,update with a mem,update with a constant,update by 1,Benefits of Read-

22、Modify-Write Instructions,Lab C: Procedure Assembly Programming,1. Edit .ASM to perform the sum of products Replace initialization routine using load/store operation with a BANZ process Add a MAC-based sum of products implementation In a real system application, the coeff array may well be constant

23、(values do not change), therefore one can modify the initialization routine to skip the transfer of this arrays, thus reducing the amount of data RAM and cycles required for initialization; also, there is no need to copy the zero to clear the result location 2. Build and debug your code using Code Composer StudioOptional LabC-C: Sum-of-Products in C,ti,

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 实用文档 > 简明教程

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报