汇编语言程序设计 实例详解
;地址 0405h
.bss z3_h,1
;地址 0406h
.bss z3_l,1
;地址 0407h
.bss z4,1
;地址 0408h
v1
.set 014H
;20---x1
v2
.set 036H
;54---y1
v1
.set 04000H
;0.5---x2
v2
.set 0b548H
;-> z1
LD
x1,A
;x1->A
SUB
y1,A
;A+y1 ->A
STL
A,z2
;保存 AL -> z1
;********text MPY(整数)*******
RSBX
FRCT
;FRCT=0 整数乘法
LD
x1,T
;x1 ->T
MPY
y1,A
;x1*y1 ->A (结果32位)
STH
A,z3_h
RPT #39
;x[20]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
MVPD TBL,*AR1+
STM #x,AR2
;将数据存储器x[20]到y[20]
STM #y,AR3
RPT #19
MVDD *AR2+,*AR3+
STM #a,AR1
;数据存储器a[20]写入程序存储器PROM
Z-1 h(2)
Z-1 h(N-2)
图7-10 横截型FIR数字滤波器的结构图
h(N-1) y(n)
图7-12 FIR滤波器循环缓冲区存储器图
*****采用循环缓冲区法编写的FIR数字滤波器程序*****
.mmrege
.global
start
.def
start, _c_int00
KS
.set
256
FRCT #h,AR2 #4 table,*AR2+ #y,AR5 #x+4,AR1 #h+4,AR2 #4,AR0 #x1,AR3 #x,AR4 #5,BRC loop-1 PA0,*AR3 *AR3,*AR4 *AR1-,T *AR2-,A *AR1*AR2-,A *AR1*AR2-,A *AR1*AR2-,A *AR1+0 *AR2+0,A A,*AR5 *AR5,PA1
MVPD COEF_FIR,*COEF_P+
STM #-1,AR0
;地址步进-1
STM
#DATABUF,DATA_P ;数据缓冲区清0
RPTZ A,#N-1
STL
;乘法结果高16位在z3_h
STL
A,z3_l;乘法结果低16位在z3_l
**************test MPY(小数)*********
****** 0.5x(-0.58374)=-0.29187(0xdaa4)
ST
#v3,x2
ST
#v4,y2
SSBX
FRCT
;准备小数乘法,FRCT=1
LD
a1=0.1,a2=0.2,a3=-0.3,a4=0.4,x1=0.8,x2=0.6,x3=-0.4,x4=-0.2
Table:
.title “chef.asm” .mmregs .def start,_c_int00 .bss x,4 .bss a,4 .bss y,1 .data .word 1*32768/10 .word 2*32768/10 .word -3*32768/10 .word 4*32768/10 .word 8*32768/10 .word 6*32768/10 .word -4*32768/10 .word -2*32768/10
;该指令为单字指令
WAIT: NOP
B
WAIT
.end
建立链接命令文件
MEMORY
{ PAGE 0: RAM: origin = 1000h,length = 800h
RAM1: origin = 2000h,length = 300h
PAGE 1: DARAM1: origin = 0100h,length = 100h
;输入的样本数
N
.set
17
;FIR滤波器阶数
COEF
.sect
“COEF_FIR” ;FIR滤波器系数
.word 1,158,264,-290,-1406,-951,3187,9287,12272
.word 9287,3187,-951,-1406,-290,264,158,0
.data
INPUT
.text
.asg
AR4,DATA_P
.asg
AR5,COEF_P
.asg
AR6,INBUF_P
.asg
AR7,OUTBUF_P
_c_int00: B
start
start:
SSBX FRCT
;小数乘法,FRCT=1
STM
#COEFTAB,COEF_P ;FIR系数从程序区搬移到数据区
RPT #N-1
.copy
“firin.inc”
;输入数据在数据区0x2400
OUTPUT .space
1024
;输入数据在数据区0x2500
COEFTAB .usect
“FIR_COEF”,N
DATABUF .usect
“FIR_BFR”,N
BOS
.usect
“STACK”,0Fh
TOS
.usect
“STACK”,1
RPT #4
;重复执行的次数为5
STL A,*AR1+
****对数组x[5]中的元素加1****
LD #1,16,B
STM #4,BRC
STM #x,AR4
RPTB next-1
ADD *AR4,16,B,A
STH A,*AR4+
next:
LD #0,B
.end
[例7-3] 1.实现数组
a[20]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}
0213H)
.def _c_int00 .data
TBL:
.word 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
PROM
.word 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 .usect “PROM”,20
PAGE 1: OTHER: origin = 0100h,length = 100h
}
SECYIONS
{
.text :> ROM
PAGE 0
.data :> ROM
PAGE 0
.bss :> OTHER PAGE 1
.stack :> OTHER PAGE 1
}
4
[例7-5]用双操作数编程计算 y ai xi i 1
LD
#PROM,A
STM #19,AR3
LOOPP: WRITA *AR1+
ADD #1,A,A
BANZ LOOPP,*AR3-
LD
#PROM-1,A ;程序存储器PROM存入数据存储器DATA
STM #DATA,AR1
STM #19,BRC
RPTB LOOP2
ADD #1,A,A
LOOP2: READA *AR1+
.word
4*32768/10
.word
-3*32768/10
.word
2*32768/10
_c_int00: FIR1: loop:
.text SSBX STM RPT MVPD STM STM STM STM STM STM STM RPTB PORTR MVDD LD MPY LTD MAC LTD MAC LTD MAC LTD MAC STH PORTW NOP .end
.bss a,20
.bss x,20
DATA
.bss y,20 .usect “DATA”,20
.text
_c_int00: B start
NOP
NOP
start: 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}
数据 存储器
x(n) x(n-1)
x(n-2) x(n-3)
数据 存储器
数据 存储器
x(n+1) PORTR x(n) x(n-1)
x(n-2)
x(n+2) x(n+1)
x(n) x(n-1)
x(n-4)
x(n-3)
x(n-2)
*Arx-
x(n-5) *Arx- x(n-4) *Arx- x(n-3)
.title "FIR.ASM"
;用线性缓冲区和间接寻址方法实现FIR滤波器
.mmregs
.def
_c_int00
x
.usect
"x",5
h
.usect
"h",5
.bss
x1,1
.bss
y,1
PA0
.set
0
PA1
.set
1
.data
table:
.word
2*32768/10
.word
-3*32768/10
.text
_c_int00: B