版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
《DSP技術(shù)與應(yīng)用》學(xué)時(shí):32(含8學(xué)時(shí)實(shí)驗(yàn))1第6章
TMS320C54XXDSP匯編程序設(shè)計(jì)舉例
2例7-3(段定義及數(shù)據(jù)傳送舉例)
1.實(shí)現(xiàn)數(shù)組a[20]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}x[20]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}的初始化,將兩數(shù)組置于數(shù)據(jù)存儲器中0100H開始的連續(xù)地址空間中(0100H-0127H);2.將數(shù)據(jù)存儲器中的x[20]復(fù)制到數(shù)組y[20](0128H-013BH);3.將數(shù)據(jù)存儲器中的a[20]寫入到程序存儲器PROM(2000H-2013H);4.程序存儲器PROM中20個(gè)數(shù)據(jù)存入數(shù)據(jù)存儲器DATA(0200H-0213H)。3
.mmregs.def_c_int00
.dataTBL:.word:0,1,2,3,4,5,6,7,8,9,10,11,12.word13,14,15,16,17,18,19.word1,1,1,1,1,1,1,1,1,1.word1,1,1,1,1,1,1,1,1,1PROM: .usect"PROM",20
.bssa,20
.bssx,20
.bssy,20DATA: .usect "DATA",20
匯編源程序:4_c_int00bstartnopnopstart:STM #a,AR1;a[20]={0,1,2,3,4,5,6,7,8,9,10, ;11,12,13,14,15,16,17,18,19} RPT #39 ;x[20]={1,1,1,1,1,1,1,1,1,1
MVPDTBL,*AR1+;1,1,1,1,1,1,1,1,1,1}
;完成任務(wù)1STM#x,AR2;將數(shù)據(jù)存儲器中的數(shù)組x[20]復(fù)制到數(shù)組y[20] STM #y,AR3;y[20]={1,1,1,1,1,1,1,1,1,1RPT #19;1,1,1,1,1,1,1,1,1,1}
MVDD*AR2+,*AR3+
;完成任務(wù)2.text5
STM#a,AR1;數(shù)據(jù)存儲器中a[20]寫入程序存儲器
LD #PROM,A;PROM段
STM #19,AR3LOOP1:WRITA*AR1+;完成任務(wù)3ADD#1,A,ABANZLOOP1,*AR3-LD#PROM-1,A;程序存儲器PROM中20個(gè)數(shù)據(jù)存入數(shù)據(jù)
STM #DATA,AR1;存儲器DATA段
ST #19,BRCRPTBLOOP2ADD#1,A,ALOOP2:READA*AR1+
;該指令為單字指令(完成任務(wù)4)WAIT: NOPBWAIT.end6鏈接命令文件:
MEMORY{PAGE0: RAM:origin=1000h,length=800h RAM1:origin=2000h,length=300hPAGE1:DARAM1:origin=0100h,length=100hDARAM2:origin=0200h,length=100h}SECTIONS{.data:>RAM PAGE0.text:>RAM PAGE0
PROM :>RAM1PAGE0.bss :>DARAM1PAGE1DATA :>DARAM2PAGE1}7定點(diǎn)DSP中數(shù)的定標(biāo)有Q和S兩種表示方法(如下表所示),16位的二進(jìn)制中有一個(gè)符號位、15-Q個(gè)整數(shù)位"."Q個(gè)小數(shù)位。DSP中小數(shù)的表示一般情況下以Q0格式表示整數(shù)以Q15格式表示小數(shù)。兩個(gè)Q15格式的小數(shù)相乘結(jié)果為Q30格式小數(shù),出現(xiàn)符號位冗余,解決方法是將FRCT置1,系統(tǒng)自動將相乘結(jié)果左移1位(即x2),精度允許時(shí)只保存高16位Q15定標(biāo):8[例7-4]使用C54匯編語言編程計(jì)算并觀察計(jì)算結(jié)果:z1=x1+y1;z2=x1-y1;z3=x1*y1;z4=x2*y2.
其中,x1=20,y1=54,x2=0.5,y2=-0.5837
例7-4
(整數(shù)、小數(shù)運(yùn)算舉例)9
匯編源程序:
.title“suanshu.asm”.mmregs.defstart,_c_int00.bssx1,1
;地址0400h.bssx2,1
;地址0401h.bssy1,1
;地址0402h.bssy2,1
;地址0403h.bssz1,1
;地址0404h.bssz2,1
;地址0405h.bssz3_h,1
;地址0406h.bssz3_l,1
;地址0407h.bssz4,1
;地址0408hv1.set014Hv2.set036Hv3.set04000H
;x2=0.5v4.set0b548H
;y2=-0.5837.text_c_int00bstartnopnopstart:LD#x1,DP
;(DP=?)
ST#v1,x1ST#v2,y1LDx1,A
ADDy1,ASTLA,z1
;(單元地址?)NOPLDx1,A
SUBy1,ASTLA,z2
;(單元地址?)NOP
RSBXFRCTLDx1,T
MPYy1,A
STHA,z3_h
;(單元地址?)STLA,z3_l
;(單元地址?)NOPST#v3,x2ST#v4,y2
SSBXFRCTLDx2,16,A
MPYAy2
STH
B,z4
;(單元地址?)NOPend:Bend.end
例7-4(數(shù)據(jù)運(yùn)算舉例)10鏈接命令文件:suanshu.obj-msuanshu.map-osuanshu.outMEMORY{PAGE0:ROM1:origin=0080h,length=1000hROM2:origin=0060h,length=10hPAGE1:OTHER:origin=0400h,length=40h
}SECTIONS{.text:{}>ROM1PAGE0.data:{}>ROM1PAGE0.bss:{}>OTHERPAGE1.stack:{}>OTHERPAGE1}11
例7-5(小數(shù)乘法舉例)
匯編源程序:
.title“chef.asm”.mmregs.defstart,_c_int00.bssx,4.bssa,4.bssy,1.datatable:
.word1*32768/10.word2*32768/10.word-3*32768/10.word4*32768/10.word8*32768/10.word6*32768/10.word-4*32768/10.word-2*32768/10
.text_c_int00bstartnopnop
start:
SSBXFRCTSTM#0,SWWSRSTM#x,AR1RPT#7MVPDtable,*AR1+STM#x,AR2STM#a,AR3STM#y,AR4RPTZA,#3
MAC*AR2+,*AR3+,A
STHA,*AR4done:Bdone.end12鏈接命令文件:
MEMORY{PAGE0: RAM:origin=1000h,length=800h RAM1:origin=2000h,length=300hPAGE1:DARAM1:origin=0100h,length=100hDARAM2:origin=0200h,length=100h}SECTIONS{.data:>RAM PAGE0.text:>RAM PAGE0PROM :>RAM1PAGE0.bss :>DARAM1PAGE1DATA :>DARAM2PAGE1}13例7-6
(帶符號除法且商為小數(shù))匯編源程序:
.title“shuf.asm”.mmregs.defstart,_c_int00.bssnum,1.bssden,1.bssquot,1.datatable.word4*32768/10;分子.word-8*32768/10;分母.text_c_int00bstartnopnop
start:STM#num,AR1;分子RPT#1MVPDtable,*AR1+STM#den,AR1
;分母LD*AR1-,16,A
MPYA*AR1+
ABSA
;分母絕對值STHA,*AR1-
LD*AR1,16,A
ABSA
;分子絕對值
STHA,*AR1LD*AR1+,A
RPT#14
;(15bit除法)SUBC*AR1,A
XC1,BLTNEGA
STLA,*(quot).end14
…..
.mmregs
.bssx,4
.bssy,2
.dataa .word1,2,3,4
.text STM#a,AR2 STM#x,AR3 LD#0,A LD*AR2+,T MAC*AR3+,A LD*AR2+,T
MAC*AR3+,A LD*AR2+,T MAC*AR3+,A LD*AR2,T MAC*AR3,A STLA,@y STHA,@y+1 …..算法一:舉例1:乘加運(yùn)算15鏈接命令文件:
MEMORY{PAGE0: RAM:origin=1000h,length=1000hPAGE1:DARAM:origin=2000h,length=1000h}SECTIONS{.text:>RAM
PAGE0.bss :>DARAMPAGE1.data
:>DARAM
PAGE1}16
…..
.mmregs
.bssx,4
.bssy,2
.dataa .word1,2,3,4
.text STM#a,AR2 STM#x,AR3 LD#0,A STM#3,BRC
RPTBss-1 LD*AR2+,T MAC*AR3+,Ass:STLA,@y STHA,@y+1 …..算法二:舉例1:乘加運(yùn)算17
…..
.mmregs
.bssa,4
.bssx,4
.bssy,2
.datatable .word1,2,3,4
.text STM#a,AR1 RPT#3
MVPDtable,*AR1+ LD#0,A
STM#a,AR2 STM#x,AR3 STM#3,BRC RPTBss-1 LD*AR2+,T MPY*AR3+,Ass: LD#a,DP STLA,@y STHA,@y+1 …..算法三:舉例1:乘加運(yùn)算18鏈接命令文件:
MEMORY{PAGE0: RAM:origin=1000h,length=1000hPAGE1:DARAM:origin=2000h,length=1000h}SECTIONS{.data:>RAM PAGE0.text:>RAM PAGE0.bss :>DARAMPAGE1}19
…..
.mmregs
.bssa,4
.bssx,4
.bssy,2
.datatable .word1,2,3,4
.word8,7,6,5
.text STM#a,AR1 RPT#7
MVPDtable,*AR1+
STM#a,AR2 STM#x,AR3 RPTZA,#3 MAC*AR2+,*AR3+,A LD#a,DP STLA,@y STHA,@y+1 …..算法四:舉例1:乘加運(yùn)算20
.title “DIV" .mmregs .def_c_int00DAT0 .set 01HDAT1 .set 02HDAT2 .set 03HDAT3.set 04H .databuff .space100h*16 .text_c_int00: Bstart舉例2:除法運(yùn)算21
start: LD#020h,DP ;置數(shù)據(jù)頁指針
SSBXINTM ;禁止中斷
DIV: ST#0008h,DAT0 ST#0002h,DAT1 RSBXSXM **無符號除法操作:DAT0÷DAT1;結(jié)果:DAT2:商;DAT3:余數(shù)
LDDAT0,A RPT#15 SUBCDAT1,A STLA,DAT2 STHA,DAT3.end22
.mmregs .bssa,4 .bssx,4 .bssy,1.def_c_int00 .datatable .word1,5,3,4 .word8,6,7,9.sect"vectors"rstB_c_int00 NOPNOP .text_c_int00STM#a,AR1 RPT#7 MVPDtable,*AR1+
CALLMAXend: Bend
MAX: STM#a,AR1 STM#x,AR2 STM#2,AR3 LD*AR1+,T MPY*AR2+,A
loop: LD*AR1+,T MPY*AR2+,B
MAXA BANZloop,*AR3- STLA,@y RET.end
找出乘積項(xiàng)中的最大值舉例3:23鏈接命令文件:
MEMORY{PAGE0: RAM:origin=1000h,length=500h
RAM1:origin=1800h,length=100hPAGE1:DARAM:origin=2000h,length=1000h}SECTIONS{.data:>RAM PAGE0.text:>RAM PAGE0vectors:>RAM1 PAGE0.bss :>DARAMPAGE1}24FIR濾波器設(shè)計(jì)
7.5.1線性緩沖區(qū)法
又稱為延遲線法。對于N階FIR濾波器在數(shù)據(jù)區(qū)開辟一個(gè)N單元的線性緩沖區(qū)存放N個(gè)樣本;每次濾波從最老樣本開始,每個(gè)樣本參與運(yùn)算后下移一單元并在頂部結(jié)束讀入新樣本。其特點(diǎn)是依次下移覆蓋/底部淘汰/頂部更新。設(shè)N階FIR濾波器的系數(shù)(單位脈沖沖擊響應(yīng))為:h(0),h(1),...h(N-1),x(n)表示濾波器在n時(shí)刻的輸入,則n時(shí)刻的輸出y(n)為:線性緩沖區(qū)示意圖(N=6)系數(shù)表x(n-1)x(n-2)x(n-(N-2))x(n-(N-1))1次y(n)計(jì)算結(jié)束ARx指向頂部讀入新樣本,覆蓋更新數(shù)據(jù)延遲算法由LTD指令完成25**采用線性緩沖區(qū)法編寫的FIR數(shù)字濾波器程序*****
.title“fir.asm” .mmregs .defstart .bssy,1x .usect“x”,6h .usect“h”,6PA0 .set0PA1 .set1
.dataTable: .word2*32768/10 .word-3*32768/10 .word4*32768/10 .word-3*32768/10 .word2*32768/10 .word4*32768/10 .textStart: STM#h,AR2 RPT#5 MVPDtable,*AR2+
STM#x+5,AR1
;AR1指向x(n-5) STM#h+5,AR2
;AR2指向h(5)
STM#5,AR0
SSBX,FRCT LD#x,DP
PORTRPA1,@x
FIR: LD*AR1-,T
;x(n-5)--TLD#0,A
MPY*AR2-,A
;h5*x(n-5)--A
LTD*AR1-
;x(n-4)--T,x(n-4)--(n-5)
MAC*AR2-,A
LTD*AR1-
;x(n-3)--T,x(n-3)--(n-4)
MAC*AR2-,A
LTD*AR1-
;x(n-2)--T,x(n-2)--(n-3)
MAC*AR2-,A
LTD*AR1-
;x(n-1)--T,x(n-1)--(n-2)
MAC*AR2-,A
LTD*AR1
;x(n)--T,x(n)--(n-1)
MAC*AR2+0,A STHA,@y
;savey(n)
Portw@y,PA0 BDFIR
PORTRPA1,*AR1+0
;
x(n+1)--頂部
.end26MEMORY{PAGE0:RAM:origin=1000h,length=100h RAM1:origin=1200h,length=500hPAGE1:DARAM1:origin=0100h,length=100h DARAM2:origin=0200h,length=100h}SECTIONS{.data:>RAMPAGE0.text:>RAM1PAGE0.bss:>DARAM1PAGE1x:>DARAM2PAGE1h:>DARAM2PAGE1}鏈接命令文件:27FIR濾波器設(shè)計(jì)
7.5.2循環(huán)緩沖區(qū)法
又稱為滑動窗法。對于N階FIR濾波器在數(shù)據(jù)區(qū)開辟一個(gè)N單元的循環(huán)緩沖區(qū)存放N個(gè)樣本;每次濾波從更新最老樣本開始,在循環(huán)尋址作用下于最老樣本結(jié)束讀入新樣本。其特點(diǎn)是用最新樣本覆蓋最老樣本/其余數(shù)據(jù)無需移動。x(n-1)x(n-2)x(n-(N-2))x(n-(N-1))1次y(n)計(jì)算結(jié)束ARx指向最老樣本被最新樣本覆蓋,更新數(shù)據(jù)設(shè)N階FIR濾波器的系數(shù)(單位脈沖沖擊響應(yīng))為:h(0),h(1),...h(N-1),x(n)表示濾波器在n時(shí)刻的輸入,則n時(shí)刻的輸出y(n)為:28*****采用循環(huán)緩沖區(qū)法編寫的FIR數(shù)字濾波器程序*****
.mmregs .global start .def start,_c_int00KS .set 256
;輸入的樣本數(shù)
N .set 17 ;FIR濾波器階數(shù)COEF_FIR
.sect “COEF_FIR”;FIR濾波器系數(shù)表
.word 0,158,264,-290,-1406,-951,3187,9287,12272
.word 9287,3187,-951,-1406,-290,264,158,0
.dataINPUT .copy“firin.inc”
;輸入數(shù)據(jù)在數(shù)據(jù)區(qū)0x2400-24FFOUTPUT .space 1024 ;輸出數(shù)據(jù)在數(shù)據(jù)區(qū)0x2500-25FFCOEFTAB .usect “FIR_COEF”,N;17個(gè)系數(shù)在數(shù)據(jù)區(qū)0x2600DATABUF .usect “FIR_BFR”,N;17個(gè)樣本在數(shù)據(jù)區(qū)0x2611BOS .usect “STACK”,0FhTOS .usect “STACK”,1
.text .asg AR4,DATA_P;樣本數(shù)據(jù)緩沖區(qū)指針 .asg AR5,COEF_P;濾波系數(shù)緩沖區(qū)指針 .asg AR6,INBUF_P;輸入數(shù)據(jù)指針 .asg AR7,OUTBUF_P;輸出數(shù)據(jù)指針匯編源程序:29_c_int00:B startstart: SSBX FRCT ;小數(shù)乘法,F(xiàn)RCT=1 STM #COEFTAB,COEF_P;濾波系數(shù)指針-AR5
RPT #N-1;FIR系數(shù)從程序區(qū)搬移到數(shù)據(jù)區(qū) MVPD COEF_FIR,*COEF_P+
STM #-1,AR0
;地址步進(jìn)-1
STM #DATABUF,DATA_P;樣本數(shù)據(jù)指針-AR4
RPTZA,#N-1;數(shù)據(jù)緩沖區(qū)清0 STL A,*DATA_P+
STM#(DATABUF+N-1),DATA_P
;數(shù)據(jù)緩沖區(qū)指針指向底部
STM#(COEFTAB+N-1),COEF_P
;系數(shù)緩沖區(qū)指針指向底部
STM #INPUT,INBUF_P;輸入數(shù)據(jù)指針-AR6 STM#OUTPUT,OUTBUF_P;輸出數(shù)據(jù)指針-AR7
STM #KS-1,BRC
;塊重復(fù)操作次數(shù)(256)
RPTBDLOOP-1
STM #N,BK
;FIR循環(huán)緩沖區(qū)大小(17)
LD *INBUF_P+,A
;裝載輸入數(shù)據(jù)
STL A,*DATA_P+0%
;用最新樣本值替代最舊樣本值
RPTZ
A,N-1;重復(fù)乘加操作(17)
MAC *DATA_P+0%,*COEF_P+0%,A
;濾波運(yùn)算
STH A,*OUTBUF_P+ ;濾波輸出
LOOP: B LOOP.end30fir.obj-ofir.out-mfir.mapMEMORY{PAGE0:ROM(RIX):origin=0080h,length=100h
ROM1(RIX):origin=180h,length=20hPAGE1:INTRAM1(RW):origin=2400h,length=200h INTRAM2(RW):origin=2600h,length=100h INTRAM3(RW):origin=2700h,length=100h B2B(RW):origin=0070h,length=10h}SECTIONS{ .text:{}>ROMPAGE0
COEF_FIR:{}>ROM1PAGE0.data :{}>INTRAM1PAGE1FIR_COEF:{}>INTRAM2PAGE1FIR_BFR:{}>INTRAM2PAGE1STACK :{}>B2BPAGE1}鏈接命令文件:31當(dāng)樣本數(shù)據(jù)為單位沖擊脈沖時(shí)濾波輸出:
32當(dāng)樣本數(shù)據(jù)為1000Hz方波時(shí)濾波輸出:
33采用線性緩存區(qū)與間接尋址方法,設(shè)計(jì)一個(gè)6級FIR濾波器。1.設(shè)濾波器系數(shù)為:
0.1,-0.3,0.2,0.2,-0.3,0.1;2.設(shè)輸入樣本數(shù)據(jù)已存放在.data段中:7fffH,0,0,0,0,0;3.參考例程寫出匯編程序代碼;4.按下列要求寫出鏈接命令文件:程序存儲器分為兩個(gè)區(qū)域,首地址分別為:0x100H,0x200H,將濾波器系數(shù)/樣本數(shù)據(jù)(.data段)和正文(.text段)分別映射到這兩個(gè)區(qū)域中;數(shù)據(jù)存儲器也分為兩個(gè)區(qū)域,首地址分別為:0x500H,0x800H,將其他數(shù)據(jù)段分別映射其中;5.試在CCS開發(fā)環(huán)境下建立工程、編譯、鏈接、調(diào)試、運(yùn)行并查看程序執(zhí)行結(jié)果。實(shí)驗(yàn)3:FIR濾波器設(shè)計(jì)與實(shí)現(xiàn)-線性緩存區(qū)法一、實(shí)驗(yàn)任務(wù)二、實(shí)驗(yàn)要求34參考程序:.title“fir.asm” .mmregs .def_c_int00 .bssy,10x .usect“x”,6h .usect“h”,6
.dataTabx:.word7fffH
.word0
.word0
.word0
.word0
.word0Tabh: .word1*32768/10 .word-3*32768/10 .word2*32768/10 .word2*32768/10 .word-3*32768/10 .word1*32768/10
.text_c_int00:
STM
#x,AR2 RPT
#11 MVPDTabx,*AR2+ STM#h+5,AR1 STM#x+5,AR2
STM#y,AR3
STM#5,AR0
SSBX
FRCT
FIR: LD*AR2-,TLD#0,A
MPY*AR1-,A
LTD*AR2-
MAC*AR1-,A
LTD*AR2-
MAC*AR1-,A
LTD*AR2-
MAC*AR1-,A
LTD*AR2-
MAC*AR1-,A
LTD*AR2
ST#0,*AR2+0
MAC*AR1+0,A STHA,*AR3+ B
FIR .end35MEMORY{PAGE0:RAM:origin=100h,length=100h RAM1:origin=200h,length=200hPAGE1:DARAM1:origin=0500h,length=200h DARAM2:origin=0800h,length=100h}SECTIONS{.data:>RAMPAGE0.text:>RAM1PAGE0.bss:>DARAM1PAGE1x:>DARAM2PAGE1h:>DARAM2PAGE1}鏈接命令文件:363738
.title "FIR" .global _c_int00 .mmregsDACOUT .set 01hADCIN .set 02hDAC1Addr .set 0f005hADC1Addr .set 0f008h .sect ".vectors"rst: B _c_int00 NOP NOP .data .space 200h*8fir_table .sect “coff_fir” ;201階低通濾波器的沖激相應(yīng)系數(shù)(Hamming窗)
;通帶:<1/20T,衰減<3dB,阻帶:>1/8T,衰減>40dB
實(shí)驗(yàn)4:FIR濾波器設(shè)計(jì)與實(shí)現(xiàn)-循環(huán)緩存區(qū)法39
.word -1,-3,-6,-8,-9,-10,-10,-9,-7,-4,0,3,7,11,14,15,16,14 .word 11,6,-1,-8,-15,-22,-27,-30,-31,-28,-22,-12,0,13,26,38,47 .word 53,53,47,36,20,-1,-23,-45,-66,-81,-89,-89,-80,-61,-34,0 .word 36,72,104,128,141,141,125,95,52,-1,-58,-115,-165,-203 .word -224,-223,-198,-151,-84,0,91,182,263,326,361,361,324,249 .word 138,-1,-157,-317,-465,-585,-661,-678,-625,-495,-286,0,351,755 .word 1192,1639,2074,2470,2807,3062,3222,3276,3222,3062,2807 .word 2470,2074,1639,1192,755,351,0,-286,-495,-625,-678,-661,-585 .word -465,-317,-157,-1,138,249,324,361,361,326,263,182,91,0 .word -84,-151,-198,-223,-224,-203,-165,-115,-58,-1,52,95,125,141 .word 141,128,104,72,36,0,-34,-61,-80,-89,-89,-81,-66,-45,-23,-1 .word 20,36,47,53,53,47,38,26,13,0,-12,-22,-28,-31,-30,-27 .word -22,-15,-8,-1,6,11,14,16,15,14,11,7,3,0,-4,-7,-9,-10 .word -10,-9,-8,-6,-3,-1 .space 55*16 data_buff .usect "buff“,20140
.text_c_int00 LD #020h,DP ;置數(shù)據(jù)頁指針
STM #3000h,SP SSBX INTM RSBX SXM stm #0001h,2Bh ;設(shè)置軟件等待時(shí)間
stm #00a8h,PMST ;改變中斷向量映射到0x0080 NOP NOP stm #201,BK ;循環(huán)尋址緩沖區(qū)大小
stm #fir_table,AR3 ;FIR系數(shù)區(qū)地址指針
stm #data_buff,AR4 ;數(shù)據(jù)緩沖區(qū)地址指針
stm #1,AR041
loop: portr ADC1Addr,ADCIN ;從第一ADC通道讀數(shù)
ld ADCIN,A stl A,*AR4+% ;存入緩沖區(qū)
rptz A,#200 mac *AR4+0%,*AR3+0%,A ;雙尋址乘加運(yùn)算
nop nop nop sfta A,#-15 and #0ffh,A stl A,DACOUT portw DACOUT,DAC1Addr ;結(jié)果從第一DAC通道輸出
b loop .end42MEMORY{ PAGE0: VECS: origin=0x0080, length=0x80 PROG: origin=0x2000, length=0x1000 PAGE1: DATA: origin=0x1000, length=0x1000 STACK: origin=0x3000,length=0x1000}SECTIONS{ .vectors: {} > VECSPAGE0 .text: {} > PROGPAGE0 .data: {} > DATAPAGE1 .stack: {} > STACKPAGE1 .bss: {} > DATAPAGE1 coff_fir: {} > DATAPAGE1 buff: {} > DATAPAGE1}43用泰勒級數(shù)展開式計(jì)算一個(gè)角度的正弦值sinx=x-x^3/3!+x^5/5!-x^7/7!+x^9/9!=x(1-x^2/2x3(1-x^2/4x5(1-x^2/6x7(1-x^2/8x9))))程序中設(shè)x值為45°(π/4)放在sin_vars段的d_x單元;程序執(zhí)行程序結(jié)果為5A81H,放在sin_vars段的d_sinx單元;實(shí)驗(yàn)5:正弦波信號發(fā)生器設(shè)計(jì)AR2AR3AR444
.title "sinx.asm" .mmregs .def _c_int00 .ref sin_start,d_x,d_sinxSTACK .usect "STACK",10_c_int00: STM #STACK+10,SP LD #d_x,DP ST #6487H,@d_x ;x=6487H=45度
CALL sin_startend: B endsin_start: .def sin_startd_coeff .usect "coeff",4
.datatable: .word 01c7H ;c1=1/(8*9)*32768=01c7H .word 030bH ;c2=1/(6*7)*32768=030bH .word 0666H ;c3=1/(4*5)*32768=0666H .word 1556H ;c4=1/(2*3)*32768=1556Hd_x .usect "sin_vars",1d_squr_x .usect "sin_vars",1d_temp .usect "sin_vars",1d_sinx .usect "sin_vars",1c_1 .usect "sin_vars",145
.textSSBX FRCTSTM #d_coeff,AR5RPT #3MVPD #table,*AR5+STM #d_coeff,AR3STM #d_x,AR2STM #c_1,AR4ST #7FFFH,@c_1;c_l=#7fffH=1SQUR *AR2+,A
;A=x^2ST A,*AR2
;(AR2)=x^2d_squr_x||LD *AR4,B
;B=1MASR *AR2+,*AR3+,B,A
;A=1-x^2/72,T=x^2MPYA A
;A=T*A=x^2(1-x^2/72)STH A,*AR2 ;(d_temp)=x^2(1-x^2/72)MASR *AR2-,*AR3+,B,A
;A=1-x^2/42(1-x^2/72),T=x^2(1-x^2/72)MPYA *AR2+
;B=x^2(1-x^2/42(1-x^2/72))ST B,*AR2
;(d_temp)=x^2(1-x^2/42(1-x^2/72))||LD *AR4,B
;B=1MASR *AR2-,*AR3+,B,A
;A=1-x^2/20(1-x^2/42(1-x^2/72))MPYA *AR2+
;B=x^2(1-x^2/20(1-x^2/42(1-x^2/72)))ST B,*AR2
;(d_temp)=B||LD *AR4,B
;B=1MASR *AR2-,*AR3+,B,A
;A=1-x^2/6(1-x^2/20(1-x^2/42(1-x^2/72)))MPYA@d_x
;B=x(1-x^2/6(1-x^2/20(1-x^2/42(1-x^2/72))))STH B,@d_sinx ;sin(theta)RET.endsinx=x-x^2/3!+x^5/5!-x^7/7!+x^9/9!=x(1-x^2/2x3(1-x^2/4x5(1-x^2/6x7(1-x^2/8x9))))AR2AR3AR446MEMORY{ PAGE0: EPROM:org=0E00H len=01000H VECS:org=0FF80H len=0080H PAGE1: SPRAM: org=0500H len=0020H DARAM: org=0080H len=0010H }SECTIONS{ .vectors:>VECSPAGE0 .text:> EPROMPAGE0 .data:>EPROMPAGE0 STACK:>SPRAMPAGE1 sin_vars:>DARAMPAGE1coeff:>DARAM PAGE1 } 47用泰勒級數(shù)展開式計(jì)算一個(gè)角度的余弦值cosx=1-x^2/2!+x^4/4!-x^6/6!+x^8/8!=1-x^2/2(1-x^2/3x4(1-x^2/5x6(1-x^2/7x8)))執(zhí)行程序結(jié)果:48
.mmregs .def _c_int00 .ref cos_start,d_x,d_cosxSTACK .usect "STACK",10_c_int00: STM #STACK+10,SP LD #d_x,DP ST #6487H,@d_x ;x=6487H=45度
CALL cos_startend: B endcos_start: .def cos_startd_coeff .usect "coeff",4 .datatable: .word 0249H ;c1=1/(7*8)*32768=0249H .word 0444H ;c2=1/(5*6)*32768=0444H .word 0aabH ;c3=1/(3*4)*32768=0aabH .word 4000H ;c4=1/(1*2)*32768=4000Hd_x .usect "cos_vars",1d_squr_x .usect "cos_vars",1d_temp .usect "cos_vars",1d_cosx .usect "cos_vars",1c_1 .usect "cos_vars",149.textSSBX FRCTSTM #d_coeff,AR5RPT #3MVPD #table,*AR5+STM #d_coeff,AR3STM #d_x,AR2STM #c_1,AR4ST #7FFFH,@c_1SQUR *AR2+,A ;A=x^2ST A,*AR2 ;(AR2)=x^2||LD *AR4,B ;B=1MASR *AR2+,*AR3+,B,A ;A=1-x^2/56,T=x^2MPYA 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=1MASR *AR2-,*AR3+,B,A ;A=1-x^2/12(1-x^2/30(1-x^2/56))SFTA A,-1,A ;1/2NEG A ;-1/2MPYA *AR2+ ;B=-x^2/2(1-x^2/12(1-x^2/30(1-x^2/56)))MAR *AR2+RETDADD *AR4,16,B ;B=1-x^2(1-x^2/12(1-x^2/30(1-x^2/56)))STH B,*AR2 ;cos(theta)RET.end50產(chǎn)生正弦波程序:先以sin.asm和cos.asm程序計(jì)算0~45(間隔為0.5)的正弦和余弦值,再利用Sin(2x)=2sin(x)cos(x)求出0~90的正弦值(間隔為1)然后通過復(fù)制,獲得0~359的正弦值。重復(fù)向PA0口輸出,便可得到正弦波。51
.title "sinxwave.asm" .mmregs .def _c_int00 .ref d_xs,d_sinx,d_xc,d_cosx,sinx,cosxsin_x: .usect "sin_x",360STACK.usect "STACK",10Hk_theta.set 286
;theta=pi/360(0.5deg)PA0 .set 0_c_int00: .text STM #STACK+10H,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 ;fromsin0(deg.)--sin90(deg.) RPTB loop1-1 LDM AR1,A LD #d_xs,DP
CALL sinx
;d_sinx=sin(x)
CALL cosx
;d_cosx=cos(x)52
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+0loop1: 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 #sinx,AR6 ;generatesinwave STM #1,AR0 STM #360,BKloop4: PORTW*AR6+0%,PA0 B loop453sinx: .def d_xs,d_sinxd_coeff_s .usect "coef_s",4 .datatable_s: .word 01c7H ;c1=1/(8*9)*32768=01c7H .word 030bH ;c2=1/(6*7)*32768=030bH .word 0666H ;c3=1/(4*5)*32768=0666H .word 1556H ;c4=1/(2*3)*32768=1556Hd_xs .usect "sin_vars",1d_squr_xs .usect "sin_vars",1d_temp_
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- GB/T 44639.1-2024軌道交通列車電能測量系統(tǒng)第1部分:總則
- 2024年度云南省高校教師資格證之高等教育心理學(xué)題庫檢測試卷A卷附答案
- 2024年度云南省高校教師資格證之高等教育法規(guī)題庫檢測試卷B卷附答案
- 2024年度云南省高校教師資格證之高等教育學(xué)模擬題庫及答案下載
- 阜陽師范大學(xué)《世界平面設(shè)計(jì)史一》2022-2023學(xué)年第一學(xué)期期末試卷
- 三年級科學(xué)下冊電子教案
- 福建師范大學(xué)協(xié)和學(xué)院《組織行為學(xué)》2022-2023學(xué)年第一學(xué)期期末試卷
- 福建師范大學(xué)《足球》2022-2023學(xué)年第一學(xué)期期末試卷
- 福建師范大學(xué)《遙感概論》2021-2022學(xué)年第一學(xué)期期末試卷
- 福建師范大學(xué)《體育社會學(xué)》2023-2024學(xué)年第一學(xué)期期末試卷
- 社會工作實(shí)務(wù)操作手冊 課件 項(xiàng)目五 兒童社會工作
- 信息化建設(shè)成果總結(jié)
- ICU獲得性衰弱的預(yù)防和護(hù)理課件
- 新生兒窒息的診治教學(xué)設(shè)計(jì)
- 高職院?;旌鲜襟w育課程學(xué)習(xí)效果評價(jià)體系的構(gòu)建
- 糖尿病性酮癥酸中毒護(hù)理查房課件
- 馮姓的研究報(bào)告作文
- 海南經(jīng)貿(mào)職業(yè)技術(shù)學(xué)院輔導(dǎo)員招聘考試行政管理教師崗筆試面試歷年真題庫試卷
- 投資公司防火墻與業(yè)務(wù)隔離制度
- 神經(jīng)內(nèi)科課件
- 鋰電池環(huán)境試驗(yàn)應(yīng)急預(yù)案
評論
0/150
提交評論