?? sine_calculation.asm
字號:
;This faction generates the sine wave of angle using the Talor series expansion.
;sin(theta)=x(1-x^2/2*3(1-x^2/4*5(1-x^2/6*7(1-x^2/8*9))))
;cos(theta)=1-x^2/2(1-x^2/3*4(1-x^2/5*6(1-x^2/7*8)))
;sin(2*theta)=2*sin(theta)*cos(theta)
.title "sin.s54"
.mmregs
.global _sine_calculation
; .global sin_x
.def sinx,d_xs,d_sinx,cosx,d_xc,d_cosx
sin_x: .usect "sin_x",360
STACK: .usect "STACK",10
k_theta .set 011Dh ;theta=pi/360(deg.)
PA0 .set 0
;--------------------------------------------------------------------
_sine_calculation:
.text
STM #STACK+10, SP
STM k_theta, AR0 ;AR0-->k_theta(increment)
STM 0, AR1 ;(AR1)=x(rad.)
STM #sin_x, AR6 ;AR6-->sin_x
STM #90,BRC ;from sin0(deg.)-->sin90(deg.)
RPTB loop1-1
LDM AR1, A
LD #d_xs,DP
STL A,@d_xs
STL A,@d_xc
CALL sinx
CALL cosx
LD #d_sinx,DP
LD @d_sinx, 16, A ;A=sin(x)
MPYA @d_cosx ;B=sin(x)*cos(x)
STH B, 1, *AR6+ ;AR6-->2*sin(x)*cos(x)
MAR *AR1+0
loop1: STM #sin_x+89,AR7 ;sin91(deg.)--sin179(deg.)
STM #88,BRC
RPTB loop2-1
LD *AR7-,A
STL A,*AR6+
loop2: STM #179,BRC ;sin180(deg.)--sin359(deg.)
STM #sin_x,AR7
RPTB loop3-1
LD *AR7+,A
NEG A
STL A,*AR6+
loop3: STM #sin_x,AR6 ;grnerate sin wave
STM #1,AR0
STM #360,BK
loop4 PORTW *AR6+0%, PA0
B loop4
;-------------------------------------------------------------------
sinx:
.def d_xs,d_sinx
.data
table_s .word 01c7h
.word 030bh ;c1=1/(8*9)
.word 0666h ;c2=1/(6*7)
.word 1556h ;c3=1/(4*5)
d_coef_s .usect "coef_s",4
d_xs .usect "sin_vars",1
d_squr_xs .usect "sin_vars",1
d_temp_s .usect "sin_vars",1
d_sinx .usect "sin_vars",1
d_l_s .usect "sin_vars",1
.text
SSBX FRCT
STM #d_coef_s,AR5
RPT #3
MVPD #table_s,*AR5+
STM #d_coef_s,AR3
STM #d_xs,AR2
STM #d_l_s,AR4
ST #7FFFh,d_l_s
SQUR *AR2+,A
ST A,*AR2
||LD *AR4,B
MASR *AR2+,*AR3+,B,A
MPYA A
STH A,*AR2
MASR *AR2-,*AR3+,B,A
MPYA *AR2+
ST B,*AR2
||LD *AR4,B
MASR *AR2-,*AR3+,B,A
MPYA *AR2+
ST B,*AR2
||LD *AR4,B
MASR *AR2-,*AR3+,B,A
MPYA d_xs
STH B,d_sinx
RET
nop
nop
;------------------------------------------------------------------------
cosx:
.def d_xc,d_cosx
d_coef_c .usect "coef_c",4
.data
table_c .word 0249h ;c1=1/(7*8)
.word 0444h ;c2=1/(5*6)
.word 0aaah ;c3=1/(3*4)
.word 4000h ;c4=1/2
d_xc .usect "cos_vars",1
d_squr_xc .usect "cos_vars",1
d_temp_c .usect "cos_vars",1
d_cosx .usect "cos_vars",1
c_l_c .usect "cos_vars",1
.text
SSBX FRCT
STM #d_coef_c, *AR5 ;move coeff table
RPT #3
MVPD #table_c, *AR5+
STM #d_coef_c, AR3
STM #d_xc, AR2
STM #c_l_c, AR4
ST #7FFFh, c_l_c
squr *AR2+, A ;A=x^2
ST A,*AR2 ;(AR2)=x^2
||LD *AR4,B ;B=1
MASR *AR2+, *AR3+ ,B ,A ;A=1-x^2/56, T=x^2
MPYA A ;A=T*A=x^2(1-x^2/56)
STH A,*AR2 ;(d_temp)=x^2(1-x^2/56)
MASR *AR2-, *AR3+, B, A ;A=1-x^2/30(1-x^56), T=x^2(1-x/56)
MPYA *AR2+ ;B=x^2(1-2/30(1-x^2/56))
ST B,*AR2+ ;(d-temp)=x^2(1-x^2/30(1-x^2/56))
||LD *AR4,B ;B=1
MASR *AR2-,*AR3+,B,A ;A=1-x^2/12(1-x^2/30(1-x^2/56))
SFTA A, -1, A ;-1/2
NEG A
MPYA *AR2+ ;B=-x^2/2(1-x^2/12(1-x^2/30(1-x^2/56)))
MAR *AR2+
RETD
ADD *AR4,16,B ;B=1-x^2/2(1-x^2/12(1-x^2/30(1-x^2/56)))
STH B, d_cosx ;cos(theta)
RET
.end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -