?? sincos.asm
字號:
;----------------------------------------------------------------------------------------------------------
;重慶大學(xué)DSP實(shí)驗(yàn)室
;C函數(shù)名:void sin_cos(sincos_struct *p, int angle)
;本函數(shù)采用查表、線性插值的方法同時求
;取函數(shù)參數(shù)angle(單位:度)的正弦和余
;弦函數(shù)值,即sin(angle)、cos(angle)
;插值公式: x-x1
; y=y1+--------(y2-y1)
; x2-x1
;其中,(x1,y1),(x2,y2)分別是正弦表中
;離待求點(diǎn)(x,y)最近的兩個已知點(diǎn)
;入口條件:
; 無符號整形數(shù)angle;范圍:0000h~ffffh;單位:度
; 0000h <----> 0度
; 4000h <----> 90度
; 8000h <----> 180度
; c000h <----> 270度
; ffffh <----> 360度
;出口條件:
; 有符號整形數(shù)sinx,cosx;Q15;范圍:0000h~ffffh
;本函數(shù)可供C語言程序調(diào)用,使用時需在main()函數(shù)前作如下定義:
; 聲明外部函數(shù):
; extern void sin_cos(sincos_struct *p, int angle) ;
; 定義全局變量保存函數(shù)返回值:
; typedef struct
; { int inv_step; ;Q15, 步長的倒數(shù), 對于一個360點(diǎn)的正弦表,其步長為1度,由于
; ;1度用無符號16進(jìn)制可表示成0xffff/360=182.04166667
; ;所以invstep=1/182.04166667=0.0054932=0xB4(Q15)
; int k_cosx; ;cosx=sin(x+pi/2), K_cosx=pi/2=index_max/4=360/4 for a 360 point table
; int sinx; ;Q15, 返回angle的正弦值
; int cosx; ;Q15, 返回angle的余弦值
; }sincos_struct;
;2002,3,4
;-----------------------------------------------------------------------------------------------------------
.def _sin_cos
.global _sin_cos
_sin_cos_frame .set 5h
_sin_cos:
POPD *+
SAR AR0,*+
SAR AR1,*
LAR AR0,#_sin_cos_frame
LAR AR2,*0+,AR2
LAR AR0,#2
LAR AR3,*,AR3 ;C COMPATIBLE
;STACK: angle/ *p/address/ar0/ar1
;ARP:AR3, AR2:AR1, AR3:AR1
SBRK #3
SETC SXM
LAR AR5,*-,AR5
LT *+,AR3
MPYU *,AR2
PAC
SACH *,1 ;index=floor(angle/step)
;STACK:angle/ *p/address/ar0/index
;ARP:AR2, AR2:index, AR3:angle, AR5:k_cosx
SUB *+,15
SACL *- ;Q15, K=(x-x1)/(x2-x1)=(x-x1)/step=x/step-x1/step=x/step-index
;STACK:angle/ *p/address/ar0/index/k
;ARP:AR2, AR2:index, AR3:angle, AR5:k_cosx
LACC *0+
ADD #SIN_TAB
TBLR *+ ;search for sin1
ADD #1
TBLR *+,AR5 ;search for sin2
ADD *+,AR2 ;add pi/2
TBLR *+ ;search for cos2
SUB #1
TBLR *0- ;search for cos1
;STACK:angle/ *p/address/ar0/index/k/sin1/sin2/cos2/cos1
;ARP:AR2, AR2:sin2, AR3:angle, AR5:sinx
LACC *-
SUB *+ ;sin2-sin1
SACL *0- ;STACK:angle/ *p/address/ar0/index/k/sin1/sin2-sin1/cos2/cos1
;ARP:AR2, AR2:k, AR3:angle, AR5:sinx
LT *0+
MPY *- ;kx=(x-x1)*(y2-y1)/(x2-x1)=k*(sin2-sin1)
;ARP:AR2, AR2:sin1, AR3:angle, AR5:sinx
LACC *0+,15,AR5 ;sin1-->ACC
APAC ;sinx=sin1+k*(sin2-sin1)
SACH *+,1,AR2 ;STACK:angle/ *p/address/ar0/index/k/sin1/sin2-sin1/cos2/cos1
;ARP:AR2, AR2:cos2, AR3:angle, AR5:cosx
LACC *+
SUB *-
SACL * ;cos2-cos1
MPY *+ ;K*(cos2-cos1)=(x-x1)(cos2-cos1)/(x2-x1)
LACC *,15,AR5
APAC ;cosx=cos1+(x-x1)*(cos2-cos1)/(x2-x1)
SACH *,1,AR1
SBRK #(_sin_cos_frame+1)
LAR AR0,*-
PSHD *
RET
SIN_TAB:
.word 0, 571, 1143, 1714, 2285, 2855, 3425, 3993, 4560, 5126
.word 5690, 6252, 6812, 7371, 7927, 8480, 9032, 9580, 10125, 10668
.word 11207, 11743, 12275, 12803, 13327, 13848, 14364, 14876, 15383, 15886
.word 16383, 16876, 17364, 17846, 18323, 18794, 19260, 19720, 20173, 20621
.word 21062, 21497, 21926, 22347, 22762, 23170, 23571, 23964, 24351, 24730
.word 25101, 25465, 25821, 26169, 26509, 26841, 27165, 27481, 27788, 28087
.word 28377, 28659, 28932, 29196, 29451, 29697, 29935, 30163, 30381, 30591
.word 30791, 30982, 31164, 31336, 31498, 31651, 31794, 31928, 32051, 32165
.word 32270, 32364, 32449, 32523, 32588, 32643, 32688, 32723, 32748, 32763
.word 32767, 32763, 32748, 32723, 32688, 32643, 32588, 32523, 32449, 32364
.word 32270, 32165, 32051, 31928, 31794, 31651, 31498, 31336, 31164, 30982
.word 30791, 30591, 30381, 30163, 29935, 29697, 29451, 29196, 28932, 28659
.word 28377, 28087, 27788, 27481, 27165, 26841, 26509, 26169, 25821, 25465
.word 25101, 24730, 24351, 23964, 23571, 23170, 22762, 22347, 21926, 21497
.word 21062, 20621, 20173, 19720, 19260, 18794, 18323, 17846, 17364, 16876
.word 16383, 15886, 15383, 14876, 14364, 13848, 13327, 12803, 12275, 11743
.word 11207, 10668, 10125, 9580, 9032, 8480, 7927, 7371, 6812, 6252
.word 5690, 5126, 4560, 3993, 3425, 2855, 2285, 1714, 1143, 571
.word 0, -572, -1144, -1715, -2286, -2856, -3426, -3994, -4561, -5127
.word -5691, -6253, -6813, -7372, -7928, -8481, -9033, -9581, -10126, -10669
.word -11208, -11744, -12276, -12804, -13328, -13849, -14365, -14877, -15384, -15887
.word -16385, -16877, -17365, -17847, -18324, -18795, -19261, -19721, -20174, -20622
.word -21063, -21498, -21927, -22348, -22763, -23171, -23572, -23965, -24352, -24731
.word -25102, -25466, -25822, -26170, -26510, -26842, -27166, -27482, -27789, -28088
.word -28378, -28660, -28933, -29197, -29452, -29698, -29936, -30164, -30382, -30592
.word -30792, -30983, -31165, -31337, -31499, -31652, -31795, -31929, -32052, -32166
.word -32271, -32365, -32450, -32524, -32589, -32644, -32689, -32724, -32749, -32764
.word -32767, -32764, -32749, -32724, -32689, -32644, -32589, -32524, -32450, -32365
.word -32271, -32166, -32052, -31929, -31795, -31652, -31499, -31337, -31165, -30983
.word -30792, -30592, -30382, -30164, -29936, -29698, -29452, -29197, -28933, -28660
.word -28378, -28088, -27789, -27482, -27166, -26842, -26510, -26170, -25822, -25466
.word -25102, -24731, -24352, -23965, -23572, -23171, -22763, -22348, -21927, -21498
.word -21063, -20622, -20174, -19721, -19261, -18795, -18324, -17847, -17365, -16877
.word -16384, -15887, -15384, -14877, -14365, -13849, -13328, -12804, -12276, -11744
.word -11208, -10669, -10126, -9581, -9033, -8481, -7928, -7372, -6813, -6253
.word -5691, -5127, -4561, -3994, -3426, -2856, -2286, -1715, -1144, -572
.word -1, 571, 1143, 1714, 2285, 2855, 3425, 3993, 4560, 5126
.word 5690, 6252, 6812, 7371, 7927, 8480, 9032, 9580, 10125, 10668
.word 11207, 11743, 12275, 12803, 13327, 13848, 14364, 14876, 15383, 15886
.word 16384, 16876, 17364, 17846, 18323, 18794, 19260, 19720, 20173, 20621
.word 21062, 21497, 21926, 22347, 22762, 23170, 23571, 23964, 24351, 24730
.word 25101, 25465, 25821, 26169, 26509, 26841, 27165, 27481, 27788, 28087
.word 28377, 28659, 28932, 29196, 29451, 29697, 29935, 30163, 30381, 30591
.word 30791, 30982, 31164, 31336, 31498, 31651, 31794, 31928, 32051, 32165
.word 32270, 32364, 32449, 32523, 32588, 32643, 32688, 32723, 32748, 32763
.word 32767
.end
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -