51程序集
;片内RAM初始化子程序
IBCLR:MOVA,R0
MOVR1,A
CLRA
IBC1:MOV@R1,A
INCR1
DJNZR7,IBC1
RET
;片外RAM初始化子程序
EBCLR1:MOVA,ADDPL
MOVDPL,A
MOVA,ADDPH
MOVDPH,A
CLRC
EBC11:MOVX@DPTR,A
INCDPTR
DJNZR7,EBC11
RET
;片外RAM初始化子程序(双字节个单元)
EBCLR2:MOVA,ADDPL
MOVDPL,A
MOVA,ADDPH
MOVDPH,A
MOVA,R7
JZEBC21
INCR6
EBC21:CLRA
MOVX@DPTR,A
INCDPTR
DJNZR7,EBC21
DJNZR6,EBC21
RET
;内部RAM数据复制程序
;入口:R0,R7
;占用资源:A
;堆栈需求:2字节
;出口:R1
IBMOV:MOVA,R0
ADDA,R7
MOVR0,A
MOVA,R1
ADDA,R7
MOVR1,A
IBM1:DECR0
DECR1
MOVA,@R0
MOV@R1,A
DJNZR7,IBM1
RET
;外部RAM数据复制程序
;入口:ADDPH,ADDPL,R7
;占用资源:ACC
;堆栈需求:2字节
;出口:R0,R1
EBMOV1:MOVA,ADDPL
ADDA,R7
MOVDPL,A
CLRA
ADDCA,ADDPH
MOVDPH,A
MOVA,R7
ADDA,R1
XCHA,R0
ADDCA,#00H
MOVP2,A
EBM11:DECR0
CJNER0,#0FFH,EBM12
DECP2
EBM12:DECDPL
MOVA,DPL
CJNEA,#0FFH,EBM13
DECDPH
EBM13:MOVXA,@R0
MOVX@DPTR,A
DJNZR7,EBM11
RET
;外部RAM数据复制程序
;入口:ADDPH,ADDPL,R6,R7
;占用资源:ACC
;堆栈需求:2字节
;出口:R0,R1
EBMOV2:MOVA,ADDPL
ADDA,R7
MOVDPL,A
MOVA,R6
ADDCA,ADDPH
MOVDPH,A
MOVA,R7
ADDA,R1
XCHA,R0
ADDCA,R6
MOVP2,A
MOVA,R7
JZEBM21
INCR6
EBM21:DECR0
CJNER0,#0FFH,EBM22
DECP2
EBM22:DECDPL
MOVA,DPL
CJNEA,#0FFH,EBM23
DECDPH
EBM23:MOVXA,@R0
MOVX@DPTR,A
DJNZR7,EBM21
DJNZR6,EBM21
RET
;外部RAM数据复制到内部RAM程序
;入口:ADDPH,ADDPL,R7
;占用资源:ACC
;堆栈需求:2字节
;出口:R0
ITEMOV:MOVA,ADDPL
ADDA,R7
MOVDPL,A
MOVA,ADDPH
ADDCA,#00H
MOVDPH,A
MOVA,R0
ADDA,R7
MOVR0,A
ITEM1:DECR0
DECDPL
MOVA,DPL
CJNEA,#0FFH,ITEM2
DECDPH
ITEM2:MOVXA,@DPTR
MOV@R0,A
DJNZR7,ITEM1
RET
;限幅滤波程序
;入口:A,SDAT,DELTY
;占用资源:B
;堆栈需求:2字节
;出口:A
JUGFILT:MOVB,A
CLRC
SUBBA,SDAT
JNCJUGFT1
CPLA
INCA
JUGFT1:SETBA
SUBBA,#DELTY
JNCJUGFT3
MOVA,SDAT
RET
JUGFT3:MOVA,B
MOVSDAT,A
RET
;中位值滤波程序
;入口:ADDPH,ADDPL,N
;占用资源:ESELSORT
;堆栈需求:4字节
;出口:A
MEDFILT:LCALLESELSORT
MOVA,N
CLRC
RRCA
ADDA,ADDPL
MOVDPL,A
MOVA,ADDPH
MOVDPH,A
JNCMEDFT1
INCDPH
MEDFT1:MOVXA,@DPTR
RET
;N点算术平均滤波
;入口:ADDPH,ADDPL,N
;占用资源:B,R3,R4
;堆栈需求:2字节
;出口:A
AVFILT:MOVA,ADDPL
MOVDPL,A
MOVA,ADDPH
MOVDPH,A
CLRA
MOVR3,A
MOVR4,A
MOVR7,N
AVFT1:MOVXA,@DPTR
INCDPTR
ADDA,R4
MOVR4,A
JNCAVFT2
INCR3
AVFT2:DJNZR7,AVFT1
MOVR7,N
MOVR2,#00H
LCALLNDIV31
MOVA,R4
RET
;N点加权平均滤波
;入口:ADDPH,ADDPL,N
;占用资源:B,R3,R4
;堆栈需求:2字节
;出口:A
QAVFILT:CLRA
MOVR3,A
MOVR4,A
MOVR7,N
MOVP2,ADDPH
MOVR1,ADDPL
MOVDPTR,#QAVTAB
QAVFT1:MOVCA,@A+DPTR
MOVB,A
MOVXA,@R1
INCDPTR
INCR1
MULAB
ADDA,R4
MOVR4,A
MOVA,B
ADDCA,R3
MOVR3,A
DJNZR7,QAVFT1
MOVA,R4
JNBACC.7,QAVFT2
INCR3
QAVFT2:MOVA,R3
RET
QAVTAB:DB
;一阶加权滞后滤波程序
;入口:A,DELTY
;占用资源:B,R3,R4
;堆栈需求:2字节
;出口:A
BQFILT:MOVB,A
CLRA
MOVDPTR,#ABTAB
MOVCA,@A+DPTR
MULAB
MOVR4,A
MOVR3,B
MOVA,#01H
MOVCA,@A+DPTR
MOVB,DELTY
MULAB
ADDA,R4
MOVR4,A
MOVA,B
ADDCA,R3
MOVR3,A
MOVA,R4
JNBACC.7,FT1
INCR3
FT1:MOVA,R3
MOVDELTY,A
RET
BQTAB:DB80H,80H
;双字节取补程序 /(R3R4)=(R3R4)
;入口:R3,R4
;占用资源:ACC
;堆栈需求:2字节
;出口:R3,R4
CMPT:MOVA,R4
CPLA
ADDA,#01H
MOVR4,A
MOVA,R3
CPLA
ADDCA,#00H
MOVR3,A
RET
;N节取补程序 /([R0])=([R0])
;入口:R0,R7
;占用资源:ACC,B
;堆栈需求:2字节
;出口:R0
NCMPTN:MOVB,R0
SETBC
NCPT1:MOVA,@R0
CPLA
ADDCA,#00H
MOV@R0,A
INCR0
DJNZR7,NCPT1
MOVR0,B
RET
;双字节无符号数加法程序 (R3R4+R6R7)=(R3R4)
;入口:R3,R4,R6,R7
;占用资源:ACC
;堆栈需求:2字节
;出口:R3,R4,CF
NADD:MOVA,R4
ADDA,R7
MOVR4,A
MOVA,R3
ADDCA,R6
MOVR3,A
RET
;N字节无符号数加法程序 ([R0]+[R1])=([R0])
;入口:R0,R1,R7
;占用资源:ACC,B
;堆栈需求:2字节
;出口:R0,CF
NADDN:MOVB,R0
CLRC
NADN1:MOVA,@R0
ADDCA,@R1
MOV@R0,A
INCR0
INCR1
DJNZR7,NADN1
MOVR0,B
RET
;双字节无符号数减法程序 (R3R4-R6R7)=(R3R4)
;入口:R3,R4,R6,R7
;占用资源:ACC
;堆栈需求:2字节
;出口:R3,R4
NSUB:MOVA,R4
CLRC
SUBBA,R7
MOVR4,A
MOVA,R3
SUBBA,R6
MOVR3,A
RET
;N字节无符号数减法程序 ([R0]-[R1])=([R0])
;入口:R0,R1,R7
;占用资源:ACC,B
;堆栈需求:2字节
;出口:R0,CF
NSUBN:MOVB,R0
MOVR7,N
CLRC
NSUBN1:MOVA,@R0
SUBBA,@R1
MOV@R0,A
INCR0
INCR1
DJNZR7,NSUBN1
MOVR0,B
RET
;单字节无符号数乘法程序 (R3R4*R7)=(R2R3R4)
;入口:R3,R4,R7
;占用资源:ACC,B
;堆栈需求:2字节
;出口:R2,R3,R4
NMUL21:MOVA,R4
MOVB,R7
MULAB
MOVR4,A
MOVA,B
XCHA,R3
MOVB,R7
MULAB
ADDA,R3
MOVR3,A
CLRA
ADDCA,B
MOVR2,A
CLROV
RET
;单字节无符号数乘法程序 (R2R3R4*R7)=(R5R2R3R4)
;入口:R2,R3,R4,R6,R7
;占用资源:ACC,B
;堆栈需求:2字节
;出口:R5,R2,R3,R4
NMUL31:MOVA,R4
MOVB,R7
MULAB
MOVR4,A
MOVA,B
XCHA,R3
MOVB,R7
MULAB
ADDA,R3
MOVR3,A
CLRA
ADDCA,B
XCHA,R2
MOVB,R7
MULAB
ADDA,R2
MOVR2,A
CLRA
ADDCA,B
MOVR5,A
CLROV
RET
;单字节无符号数乘法程序 (R5R2R3R4*R7)=(R7R5R2R3R4)
;入口:R5,R2,R3,R4,R7
;占用资源:ACC,B
;堆栈需求:2字节
;出口:R7,R5,R2,R3,R4
NMUL41:MOVA,R4
MOVB,R7
MULAB
MOVR4,A
MOVA,B
XCHA,R3
MOVB,R7
MULAB
ADDA,R3
MOVR3,A
CLRA
ADDCA,B
XCHA,R2
MOVB,R7
MULAB
ADDA,R2
MOVR2,A
CLRA
ADDCA,B
XCHA,R5
MOVB,R7
MULAB
ADDA,R5
MOVR5,A
CLRA
ADDCA,B
MOVR7,A
CLROV
RET
;双字节无符号数乘法程序 (R3R4*R6R7)=(R5R2R3R4)
;入口:R3,R4,R6,R7
;占用资源:ACC,B
;堆栈需求:2字节
;出口:R5,R2,R3,R4
NMUL22:MOVA,R4
MOVB,R7
MULAB
XCHA,R4
MOVR5,B
MOVB,R6
MULAB
ADDA,R5
MOVR5,A
CLRA
ADDCA,B
MOVR2,A
MOVA,R3
MOVB,R7
MULAB
ADDA,R5
MOVR5,A
MOVA,B
ADDCA,R2
MOVR2,A
CLRA
ADDCA,#00H
XCHA,R3
MOVB,R6
MULAB
ADDA,R2
MOVR2,A
MOVA,B
ADDCA,R3
XCHA,R5
MOVR3,A
CLROV
RET
;双字节无符号数乘法程序 (R2R3R4*R6R7)=(R1R5R2R3R4)
;入口:R2,R3,R4,R6,R7
;占用资源:ACC,B
;堆栈需求:2字节
;出口:R1,R5,R2,R3,R4
NMUL32:MOVA,R4
MOVB,R7
MULAB
XCHA,R4
MOVR5,B
MOVB,R6
MULAB
ADDA,R5
MOVR5,A
CLRA
ADDCA,B
MOVR1,A
MOVA,R3
MOVB,R7
MULAB
ADDA,R5
MOVR5,A
MOVA,B
ADDCA,R1
MOVR1,A
CLRA
ADDCA,#00H
XCHA,R3
MOVB,R6
MULAB
ADDA,R1
MOVR1,A
MOVA,B
ADDCA,R3
XCHA,R5
MOVR3,A
MOVA,R2
MOVB,R7
MULAB
ADDA,R1
MOVR1,A
MOVA,B
ADDCA,R5
MOVR5,A
CLRA
ADDCA,#00H
XCHA,R2
MOVB,R6
MULAB
ADDA,R5
MOVR5,A
MOVA,B
ADDCA,R2
XCHA,R1
MOVR2,A
CLROV
RET
;N字节无符号数乘法程序 ([R0]*[R1])=([R0])
;入口:R0,R1,M,N
;占用资源:ACC,B,R2,R5,R6,R7,NCNT
;堆栈需求:2字节
;出口:R0
NMULMN:MOVA,M
ADDA,R0
MOVR5,A
XCHA,R1
XCHA,R5
ADDA,N
XCHA,R0
MOVR6,A
MOVB,M
MOVNCNT,B
NMLMN1:DECR0
DECR1
CLRA
XCHA,@R1
MOV@R0,A
DJNZNCNT,NMLMN1
MOVNCNT,B
NMLMN2:CLRA
XCHA,@R0
MOVR2,A
MOVA,R6
MOVR0,A
MOVA,R5
MOVR1,A
MOVR7,N
CLRC
NMLMN3:MOVA,R2
MOVB,@R1
INCR1
MULAB
ADDCA,@R0
MOV@R0,A
INCR0
MOVA,B
ADDCA,@R0
MOV@R0,A
DJNZR7,NMLMN3
INCR0
INCR6
DJNZNCNT,NMLMN2
MOVA,R0
CLRC
SUBBA,M
SUBBA,N
MOVR0,A
RET
;单字节无符号除法程序 (R2R3R4/R7)=(R2)R3R4 余数R7
;入口:R2,R3,R4,R7
;占用资源:ACC,B,F0
;堆栈需求:3字节
;出口:(R2),R3,R4,R7,OV
NDIV31:MOVA,R2
MOVB,R7
DIVAB
PUSHA
MOVR2,B
MOVB,#10H
NDV311:CLRC
MOVA,R4
RLCA
MOVR4,A
MOVA,R3
RLCA
MOVR3,A
MOVA,R2
RLCA
MOVR2,A
MOVF0,C
CLRC
SUBBA,R7
JBF0,NDV312
JCNDV313
NDV312:MOVR2,A
INCR4
NDV313:DJNZB,NDV311
POPA
CLROV
JZNDV314
SETBOV
NDV314:XCHA,R2
MOVR7,A
RET
;单字节无符号除法程序 (R5R2R3R4/R7)=(R5)R2R3R4 余数R7
;入口:R2,R3,R4,R7
;占用资源:ACC,B,F0
;堆栈需求:3字节
;出口:(R5),R2,R3,R4,R7,OV
NDIV41:MOVA,R5
MOVB,R7
DIVAB
PUSHA
MOVR5,B
MOVB,#18H
NDV411:CLRC
MOVA,R4
RLCA
MOVR4,A
MOVA,R3
RLCA
MOVR3,A
MOVA,R2
RLCA
MOVR2,A
MOVA,R5
RLCA
MOVR5,A
MOVF0,C
CLRC
SUBBA,R7
JBF0,NDV412
JCNDV413
NDV412:MOVR5,A
INCR4
NDV413:DJNZB,NDV411
POPA
CLROV
JZNDV414
SETBOV
NDV414:XCHA,R5
MOVR7,A
RET
;双字节无符号除法程序 (R5R2R3R4/R6R7)=(R2)R3R4 余数R6R7
;入口:R5,R2,R3,R4,R6,R7
;占用资源:ACC,B,F0
;堆栈需求:4字节
;出口:(R2),R3,R4,R6,R7,OV
NDIV42:MOVA,R1
PUSHA
MOVB,#00H
NDV421:MOVA,R2
&, nbsp;CLRC
SUBBA,R7
MOVR1,A
MOVA,R5
SUBBA,R6
JCNDV422
MOVR5,A
MOVA,R1
MOVR2,A