DSP算术运算程序及程序说明.doc_第1页
DSP算术运算程序及程序说明.doc_第2页
DSP算术运算程序及程序说明.doc_第3页
DSP算术运算程序及程序说明.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

DSP算术运算程序及程序说明 .title for test ADD,SUB,MPY. program . .mmregs .global _c_int00 VAL1 .set 012h ; 18VAL2 .set 034h ; 52VAL3 .set 04000h ; 0.5VAL4 .set 02000h ; 0.25(fraction) & 8192 (integer)VAL5 .set 04ab8h ; 0.58374VAL6 .set 0ffeeh ; -18VAL7 .set 0b548h ; -0.58374 .bss temp,1 ; address of 0x080 .bss temp1,1 ; address of 0x081 .bss temp2,1 ; address of 0x082 .bss temp3,1 ; address of 0x083 .bss temp4,1 ; address of 0x084 .bss temp5,1 ; address of 0x085 .bss temp6,1 ; address of 0x086 .bss temp7,1 ; address of 0x087;result register .bss add_result,1 ; address of 0x088 .bss sub_result,1 ; address of 0x089 .bss mpy_i_h,1 ; address of 0x08a .bss mpy_i_l,1 ; address of 0x08b .bss mpy_f,1 ; address of 0x08c .bss quot_i,1 ; address of 0x08d .bss remain_i,1 ; address of 0x08e .bss quot_f,1 ; address of 0x08f .text _c_int00: ld #temp,DP ; load DP of temp1 st #VAL1,temp1 st #VAL2,temp2 ; init temp1 & temp2 ,18+52=70(0x46);- test ADD - 加法 ld temp1,a ; load temp1 - a /把变量temp1加载给寄存器A add temp2,a ; a+temp2 - a /将变量temp2与寄存器A相加,结果放入A中 stl a,add_result ; save a(low 16 bits) - add_result /将结果(低16位)存入变量add_result中。 nop ; set breakpoint /设置断点 st #VAL6,temp3 /将#VLA6赋值temp3 st #VAL1,temp4 / 将#VLA6赋值temp3 init temp3 & temp4,(-18)-18=-36(0x0ffdc);- test SUB - 减法 stm #temp3,ar2 ; address of temp3 - ar2 / 将变量temp3的地址装入ar2寄存器 stm #temp4,ar3 ; address of temp4 - ar3 / 将变量temp4的地址装入ar3寄存器 sub *ar2+,*ar3,b ; (temp316)-(temp4 b,ar2+ / 变量temp3和变量temp4分别同时左移16位,再相减,结果存到b寄存器中,寄存器ar2的地址加1 sth b,sub_result ; result in sub_result /将相减的结果(高16 位)存入变量sub_result nop ; set breakpoint /设置断点 st #VAL1,temp1 /将#VAL1赋值temp1 st #VAL2,temp2 /将#V2LA赋值temp2 init temp1 & temp2,18*52=936(0x3a8);- test MPY (integer) - 整数乘法 rsbx FRCT ; prepare for integer mpy /清FRCT标志,准备整数乘 ld temp1,T ; temp1 - T /将变量temp1装入T寄存器 mpy temp2,a ; temp1*temp2 - A (result is 32 bit) /变量temp1与temp2相乘,结果装入A寄存器(结果是32位) sth a,mpy_i_h ; the high 16bit in mpy_i_h /将寄存器A的高16位(结果)放入变量mpy_i_h中 stl a,mpy_i_l ; the low 16bit in mpy_i_l / 将寄存器A的低16位(结果)放入变量mpy_i_l中 nop ; set breakpoint /设置断点 st #VAL3,temp3 /将#VAL3赋值temp3 st #VAL7,temp4 /将#VAL7赋值temp4 init temp3 & temp4,0.5*(-0.58374)=-0.29187(0x0daa4);- test MPY (fraction) - 浮点数乘法 ssbx FRCT ; prepare for fraction mpy /清FRCT标志,准备浮点数数乘 ld temp3,16,a ; load temp3 into A (high 16 bits) /将变量temp3装入寄存器A的高16位 mpya temp4 ; temp3*temp4 - B, and temp4 - T /将temp3与temp4相乘后的结果装入B寄存器,并将temp4装入T寄存器 sth b,mpy_f ; result in mpy_f /把结果装入变量mpy_f中 nop ; set breakpoint st #VAL2,temp1 /将#VAL2赋值temp1 st #VAL6,temp2 /将#VAL6赋值temp2init temp1 & temp2,52/-18= -2(0xfffe) mod 16(0x10);- test DIV (integer) - 整数除 ld temp1,T ; load temp1 - T /将变量temp1装入T寄存器 mpy temp2,A ; temp1*temp2 - A /将变量temp1与temp2相乘的结果装入寄存器A ld temp2,B ; load temp2 - B (low 16 bits) /将变量temp2装入寄存器B的低16位 abs B ; |B| - B /将寄存器B中的内容取绝对值并装入寄存器B stl B,temp2 ; save B low 16 bits - temp2 / 将寄存器B的低16位装入变量temp2 ld temp1,B ; load temp1 - B (low 16 bits) /将变量temp1装入寄存器B的低16位 abs B ; |B| - B /将寄存器B中的内容取绝对值并装入寄存器B(即将变量temp1取绝对值并装入寄存器B) rpt #15 ; repeat SUBC 16 times /重复SUBC指令16次 subc temp2,b ; use SUBC done div /使用SUBC指令完成除法运算 bcd idiv_end,agt ; delay jump, run the following two instruction,then / 延时跳转,先执行接下的两条指令 ; if A0,then jump to label idiv_end,end div /如果A0,就跳转到标号idiv_end,结束除法运算 stl B,quot_i ; save low 16 bits of B - quot_i - quotient /将寄存器B的低16位(商)装入到变量quot_i sth B,remain_i ; save high 16 bits of B - remain_i - remainder /将寄存器B的高16位(余数)装入到变量remain_i xor B ; if result if negative, then 0 - B /如果相乘的结果为负,则商也为负,并将B寄存器清零 sub quot_i,B ; put minus to quotient /将商取反 stl B,quot_i ; save low 16 bits of B - quot_i - quotient /将寄存器B的低16位装入quot_iidiv_end: / 除法结束 nop ; set breakpoint st #VAL3,temp1 st #VAL5,temp2 ; init temp1 & temp2,0.5/0.58374=0.8565457(0x6da3);- test DIV (fraction) - 浮点数除法 ld temp1,T ; load temp1 - T /将变量temp1装入寄存器T mpy temp2,A ; temp1*temp2 - A /除数与被除数相乘,结果放入A寄存器 ld temp2,B ; load temp2 - B (low 16 bits) /将变量temp2装入到寄存器B的低16位 abs B ; |B| - B / 取绝对值(变量temp2的),并存回寄存器B stl B,temp2 ; save B low 16 bits - temp2 /B的低16位装入变量temp2 ld temp1,16,B ; load temp1 - B (high 16 bits) / 将变量temp1装入寄存器B的低16位 abs B ; |B| - B /取绝对值(变量temp1的),并存回寄存器B rpt #15 ; repeat SUBC 16 times /重复SUBC指令16次 subc temp2,b ; use SUBC done div /使用SUBC指令完成除法运算 and #0ffffh,B ; 0 - high 16 bits of B /将B寄存器的高16位清为0。这时余数被丢弃,仅保留商 bcd fdiv_end,agt ; delay jump, run the following two instruction,then /延时跳转,先执行接下的两条指令 ; if A0,then jump to label fdiv_end,end div / 如果A0,就跳转到标号idiv_end,结束除法运算 stl B,-1,quot_f ; right shift 1 bit then save to quot_f - quotient /将B寄存器内的值右移一位并存入到变量quot_f x

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论