📄 sin.s54
字号:
;******************************************************************************
; SJTU DSP Tech. Center
; Copyright (c) 2003 SJTU DSP Tech. Center. All Rights Reserved.
;
; Description:
; TMS320C54x Program for Students Experiment
;
; History:
; Date Authors Changes
; 2003/08/01 Fu Xuan Created.
;******************************************************************************
STACK_ADDR .set 0x0500
STEP .set 0x0400 ;delta x (must be positive), the more the higher frequency
;T=65536/STEP, f=1/T
.bss sin_out, 1
.mmregs
.global main
.text
main:
stm #STACK_ADDR, SP
stm #0x00A8, PMST ;IPTR=0x0080
stm #0x0000, SWWSR ;software wait status register
sub A
ssbx CPL ;direct address using SP
ssbx FRCT ;fraction mode
ssbx OVM ;overflow mode
ssbx SXM ;sign extension
stm #sin_out, AR6
sin_loop:
pshm AG ;save current x
pshm AH
pshm AL
call calculate_sin ;-pi <= x <= pi
sth A, *AR6 ;store sin(x), add probe point
popm AL
popm AH
popm AG
add #STEP, A ;add delta
sub #0x7fff, A, B ;test if x>pi, B=A-pi
bc normal_increase, BLT
ld #0x8000, A ;A=-pi
add B, A ;A=B+(-pi)=x - 2*pi
normal_increase:
b sin_loop
dead_loop:
nop
nop
nop
nop
b dead_loop
;******************************************************************************
sign .set 0 ;local variable
calculate_sin:
frame -1 ;allocate sign
nop ;no direct addressing next frame
st #0, @sign ;decide sign, 0 for 1st and 2nd quadrant, 1 for 3rd and 4th quadrant
xc 2, ALT
st #1, @sign
abs A ;change to 1st and 2nd quadrant
sub #0x4000, A, B ;test for 1st quadrant
bc first_quadrant, BLEQ;if not change to 1st quadrant
sub #0x7fff, A ;As sin(pi-x)=sinx, let x=pi-x
neg A
first_quadrant:
stm #coef, AR2
stlm A, T ;T=x
ld *AR2+, 16, A ;AH=C5
ld *AR2+, 16, B ;BH=C4
rpt #5-1 ;AH=C5*x^5+C4*x^4+C3*x^3+C2*x^2+C1*x+0
poly *AR2+
ld @sign, B ;pick out sign
sfta A, 3 ;make Q15 format
nop ;nop for B condition test by xc
xc 1, BNEQ ;test sign
neg A ;sin(-x)=-sinx
frame 1
ret
;******************************************************************************
.sect "vectors"
int_RESET:
b main
nop
nop
.space 124*16
;sin(x)=0 + 3.140625x + 0.02026367x^2 - 5.325196x^3 + 0.5446778x^4 + 1.800293x^5
.data
coef: ;As the max value is -5.325196, so Q12 is used
.word 0x1cce ;1.800293 * 4096
.word 0x08b7 ;0.5446778 * 4096
.word 0xaacc ;-5.325196 * 4096
.word 0x0053 ;0.02026367 * 4096
.word 0x3240 ;3.140625 * 4096
.word 0x0000 ;0
.end
;end of Sin.s54
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -