当前位置:
文档之家› DSP 2835 教程 附录3 DSP汇编语言
DSP 2835 教程 附录3 DSP汇编语言
y
sum:
AR3 COUNT
Program Control ALU / Multiply Operations Data Move
Logical Operations
Special Instructions
ALU and Accumulator
16/32 data mem,
Product (32)
16/32 bit registers
MUX
8/16 Imm
ALU and Barrel Shifter
ST0, ST1
ACC AH (31-16) AL (15-0)
AH.MSB AH.LSB AL.MSB AL.LSB
Accumulator - Basic Math Instructions
Format
loc16,ACC <<shift loc16,ACC <<shift
MOV ADD SUB AND OR XOR AND NOT NEG MOV
Ax, loc16 Ax, loc16 Ax, loc16 Ax, loc16 Ax, loc16 Ax, loc16 Ax,loc16,#16b Ax Ax loc16,Ax
Function Short Branch Fast Short Branch Fast Branch Absolute Branch Dynamic Branch SB SBF BF LB LB BAR Instruction 8bit,cond 8bit,EQ|NEQ|TC|NTC 16bit,cond 16bit,cond 22bit *XAR7 16bit,ARn,ARn,EQ|NEQ Cycles T/F Size 7/4 4/4 7/4 4/4 4 4 1 1 2 2 2 1
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 Use 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 Range
3 Branch Types
0x000000
Program Memory
y xn
n 0
4
Data
x x0 x1 x2 x3 x4 XAR2
len x y
.set .usect .set
.sect MOVL MOV MOV ADD BANZ MOV
5 “samp”,6 (x+len)
“code” XAR2,#x AR3,#len-2 AL,*XAR2++ AL,*XAR2++ sum,AR3-*(0:y),AL
Fast Relative Branch B
Branch on AR
Branch on compare Condition Code
NEQ EQ GT GEQ LT LEQ HI HIS (C)
BANZ 16bit,ARn--
4/2
4/2
2
2
LO (NC) LOS NOV OV
NTC TC UNC NBIO
Sum-of-Products
Y = A*X1 + B*X2 + C*X3 + D*X4
ZAPA MOV MPY MOVA MPY MOVA MPY MOVA MPY ADDL MOVL ;ACC T,@X1 ;T = P,T,@A ;P = T,@X2 ;T = P,T,@B ;P = T,@X3 ;T = P,T,@C ;P = T,@X4 ;T = P,T,@D ;P = ACC,P<<PM ;ACC @y,ACC = P = OVC = 0 X1 A*X1 X2 ;ACC = A*X1 B*X2 X3 ;ACC = A*X1 + B*X2 C*X3 X4;ACC = A*X1 + B*X2 + C*X3 D*X4 = Y
P Register (32)
Shift (PM)
ACC (32)
Multiplier Instructions
Instruction MOV MPY MPY MPYB MPYB MOV ADD SUB T,loc16 ACC,T,loc16 P,T,loc16 ACC,T,#8bu P,T,#8bu ACC,P ACC,P ACC,P T ACC P ACC P ACC ACC ACC Execution = loc16 = T*loc16 = T*loc16 = T*8bu = T*8bu = P += P -= P Purpose Get first operand For single or first product For nth product Using 8-bit unsigned const Using 8-bit unsigned const Move 1st product<<PM to ACC Add nth product<<PM to ACC Sub nth product<<PM fr. ACC
32x32 Long Multiplication
X X Y XO Y1 Z3 * X1 Z2 Z1 Z0 * Y0
Integer long multiplication u(long) = u(long) * u(long) Fraction long multiplication: (long) = (long) * (long) (long) 64 = (long) 32 * (long) 32
Local Var
22-bit old RPC
PC
BANZ Loop Control Example
Auxiliary register used as loop counter Branch if Auxiliary Register not zero Test performed on lower 16-bits of XARx only
Ex
Ax = AH or AL Operations
ACC Operations Variation
MOV ADD SUB MOV ADD SUB MOV MOVH
} }
ACC,loc16<<shift from memory (left shift optional) ACC,#16b<<shift 16-bit constant (left shift optional) ;AL ;AH
Assembly Programming
Appendix C TMS320C28x™ MCU Workshop
T TO
Technical Training Organization
Copyright © 2009 Texas Instruments. All rights reserved.
Learning Objectives
0 or 1
based on SXM
C
Arithmetic Shift Right – Long: ASRL
Multiply Unit
XT Register T Register 32x32 Multiply Unit 16x16 MUX Data Mem or Register
Prog Mem (16) or Immed (8,16)
Shift the Accumulator
Shift full ACC
LSL SFR LSL SFR ACC <<shift ACC >>shift ACC <<T ACC >>T (1-16) (0-15) SXM C
31 ……… 0 ACC
31 ……… 0 ACC
0
LSL
C
SFR
Shift AL or AH
31 ……… 0 ACC
C
0
Logical Shift Left – Long: LSLL
0
31 ……… 0 ACC
C
Examples: LSLL ACC, T LSRL ACC, T ASRL ACC, T
Note: T(4:0) are used; other bits are ignored
Logical Shift Right – Long: LSRL 31 ……… 0 ACC
Short Branch offset +127/128 1-word instruction
Branch offset +/-32K 2-word instruction
Long Branch absolute 4M
2-word instruction
PC 0x3FFFFF
Program Control - Branches