DSP

DSP ccs2 C5000编译SUBC指令实现除法

2019-07-13 10:41发布

通过编程求解y=(ax^2-bx+c)/(dx+e),将商和余数分别放在数
据存储器1000H和1001H单元。
(1)已知a=8,b=6,c=10,d=7,e=9,x=5,求y。
(2)已知a=0.9,b=0.1,c=0.5,d=0.4,e=0.2,x=0.8,求y。 .title "division.asm" .mmregs Y .usect "Y",10H ;若程序中要使用堆栈,必须先进行设置 X .usect "X",1 .data ; 使用伪指令.sect,.text或.data改变段 table: .word 8,6,10,7,9;分别将a,b,c,d,e放入堆栈 tal: .word 5;独立开辟空间放X的值 .def start start: STM #Y,AR2 RPT #4 MVPD table,*AR2+ ;先开辟一个较大的堆栈区,用已知数充填 STM #X,AR3 MVPD tal,*AR3 ; 从程序存储器到数据存储器 LD #0,A LD #0,B;累加器清0 STM #Y,AR3;将数据段的首地址给ARx STM #X,AR2 SQURA *AR2,A ;A=(*AR2)^2 STL A,*AR4 ;将累加器的低字节赋值给AR4指向的空间 MAC *AR4,*AR3+,B ;B=aX^2计算后AR3指向下一个地址 STL B,*(0201H) LD #0,A ;累加器初始化 MAC *AR2,*AR3+,A ;A = A+bX STL A,*AR4 SUB *AR4,B ;B=B-*AR4 => B=aX^2-bX ADD *AR3+,B ;B=aX^2-bX+c STL B,*(0201H) LD #0,A MAC *AR2,*AR3+,A ADD *AR3,A;A=dX+e STM #0203h,AR4 STM #0204h,AR5 STL A,*AR4 STL B,*AR5 ;验证答案 RPT #15 SUBC *AR4,B ;除法 STL B,*(1000H) ;商 STH B,*(1001H) ;余 end: B end .end .title "vectors.asm" .ref start .sect ".vectors" B start .end division.obj vectors.obj -o division.out -m division.map -estart MEMORY { PAGE 0: EPROM: org=0e000h len = 0100h VECT: org=0ff80h len = 0004h PAGE 1: SPRAM: org=0060h len = 0020h DARAM1: org=0100h len = 0010h DARAM2: org=0080h len = 0002h } SECTIONS { .text :>EPROM PAGE 0 .data :>EPROM PAGE 0 X :>DARAM1 PAGE 1 Y :>DARAM2 PAGE 1 .vectors:>VECT PAGE 0 } ;cmd脚本文件,定义空间位置 .title "division.asm" .mmregs ;将寄存器符号设置为全局可用 .bss a,6 .bss b,1 .data table1: .word 8*32768/10,9*32768/10,1*32768/10,5*32768/10,4*32768/10,2*32768/10 table2: .word 8*32768/10 .def start ;.def表示某符号在本文件定义,可为其他文件引用 .text start: SSBX FRCT STM #a,AR2 RPT #6 MVPD table1,*AR2+ STM #b,AR3 MVPD table2,*AR3 LD #0,A LD #0,B STM #a,AR2 STM #b,AR3 MPY *AR3,*AR2+,A ;乘法 等同SQURA *AR3,A 得出值 假如为005F7A**** ;即00 0101 1111 0111 1010*****=2^(-1)+2^(-3)+…… 如果不是特别要求可以省略低字节数据 STH A,*AR4 STH A,*(0200H) ; A=X^2的值存储在0200H MAC *AR4,*AR2+,B STH B,*(0201H) ;B=aX^2将值存储在0201H LD #0,A MAC *AR3,*AR2+,A STH A,*AR4 SUB *AR4,16,B ADD *AR2+,16,B STH B,*(0202H) ;B=aX^2-bX+c的值存储在0202H LD #0,A MAC *AR3,*AR2+,A ADD *AR2,16,A ;A=dX+e STM #0203H,AR4 STH A,*AR4 ;*AR4=dX+e ;A=dX+e的值存储在0203H STM #0204h,AR5 STH B,*AR5 ;B=aX^2-bX+c LD #0,B LD *AR5,B RPT #15 SUBC *AR4,B ;XC 1,BLT ;NEG A STL B,*(1000H) STH B,*(1001H) end: B end .end .title "vectors.asm" .ref start .sect ".vectors" B start .end division.obj vectors.obj -o division.out -m division.map -estart MEMORY { PAGE 0: EPROM: org=0e000h len = 0100h VECT: org=0ff80h len = 0004h PAGE 1: SPRAM: org=0060h len = 0020h DARAM1: org=0100h len = 0010h DARAM2: org=0080h len = 0002h } SECTIONS { .text :>EPROM PAGE 0 .data :>EPROM PAGE 0 .bss :>SPRAM PAGE 1 .vectors:>VECT PAGE 0 }