📄 lab7b.asm
字号:
****************************** ***************
** LAB7B sin.asm **
******************************
**************************************************************************
* This function generates the sine wave of angle using the Taylor 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 "lab7b.asm"
.mmregs
.def start
.ref sinx,d_xs,d_sinx,cosx,d_xc,d_cosx
sin_x: .usect "sin_x",360
STACK: .usect "STACK",10
k_theta .set 286 ;theta=pi/360=0.5(deg.)
PA0 .set 0
start:
.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 ;form sin0(deg.)--sin90(deg.)
RPTB loop1-1
LDM AR1,A
LD #d_xs,DP
STL A,@d_xs
STL A,@d_xc
CALL sinx ;(d_sinx)=sin(x)
CALL cosx ;(d_cosx)=cos(x)
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 ;generate 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 ;c1=1/(2*3)
.word 030bh ;c2=1/(4*5)
.word 0666h ;c3=1/(6*7)
.word 1556h ;c4=1/(8*9)
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
c_1_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 #c_1_s,AR4
ST #7FFFh,c_1_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
cosx:
.def d_xc,d_cosx
d_coef_c .usect "coef_c",4
.data
table_c .word 0249h ;c1=1/2
.word 0444h ;c2=1/(3*4)
.word 0aabh ;c3=1/(5*6)
.word 4000h ;c4=1/(7*8)
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_1_c .usect "cos_vars",1
.text
SSBX FRCT
STM #d_coef_c,AR5 ;move coeff stable
RPT #3
MVPD #table_c,*AR5+
STM #d_coef_c,AR3
STM #d_xc,AR2
STM #c_1_c,AR4
ST #7FFFh,c_1_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^2/56)
;T=x^2(1-x^2/56)
MPYA *AR2+ ;B=x^2(1-x^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,*AR2 ;cos(theta)
RET
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -