首 页文档资料下载资料维修视频包年699元
请登录  |  免费注册
当前位置:精通维修下载 > 文档资料 > 家电技术 > 单元电路介绍 > 其它电路
51单片机汇编程序集(3)
来源:本站整理  作者:佚名  2011-02-05 21:35:49




      21、单字节无符号数乘法程序
      22、双字节无符号数乘法程序
      23、双字节无符号数乘法程序
      24、N字节无符号数乘法程序
      25、单字节无符号除法程序
      26、单字节无符号除法程序
      27、双字节无符号除法程序
      28、N字节无符号除法程序(组合)
      29、N字节无符号除法程序
      30、N字节数据左移程序
      ;单字节无符号数乘法程序 (R5R2R3R4*R7)=(R7R5R2R3R4)
      ;入口    :R5,R2,R3,R4,R7
      ;占用资源:ACC,B
      ;堆栈需求:2字节
      ;出口    :R7,R5,R2,R3,R4
      NMUL41   : MOV     A,R4
                 MOV     B,R7
                MUL    AB
                 MOV     R4,A
                 MOV     A,B
                XCH    A,R3
                 MOV     B,R7
                MUL    AB
                ADD    A,R3
                 MOV     R3,A
                CLR    A
                ADDC   A,B
                XCH    A,R2
                 MOV     B,R7
                MUL    AB
                ADD    A,R2
                 MOV     R2,A
                CLR    A
                ADDC   A,B
                XCH    A,R5
                 MOV     B,R7
                MUL    AB
                ADD    A,R5
                 MOV     R5,A
                CLR    A
                ADDC   A,B
                 MOV     R7,A
                CLR    OV
                RET

      ;双字节无符号数乘法程序 (R3R4*R6R7)=(R5R2R3R4)
      ;入口    :R3,R4,R6,R7
      ;占用资源:ACC,B
      ;堆栈需求:2字节
      ;出口    :R5,R2,R3,R4
      NMUL22   : MOV     A,R4
                 MOV     B,R7
                MUL    AB
                XCH    A,R4
                 MOV     R5,B
                 MOV     B,R6
                MUL    AB
                ADD    A,R5
                 MOV     R5,A
                CLR    A
                ADDC   A,B
                 MOV     R2,A
                 MOV     A,R3
                 MOV     B,R7
                MUL    AB
                ADD    A,R5
                 MOV     R5,A
                 MOV     A,B
                ADDC   A,R2
                 MOV     R2,A
                CLR    A
                ADDC   A,#00H
                XCH    A,R3
                 MOV     B,R6
                MUL    AB
                ADD    A,R2
                 MOV     R2,A
                 MOV     A,B
                ADDC   A,R3
                XCH    A,R5
                 MOV     R3,A
                CLR    OV
                RET
      ;双字节无符号数乘法程序 (R2R3R4*R6R7)=(R1R5R2R3R4)
      ;入口    :R2,R3,R4,R6,R7
      ;占用资源:ACC,B
      ;堆栈需求:2字节
      ;出口    :R1,R5,R2,R3,R4
      NMUL32   : MOV     A,R4
                 MOV     B,R7
                MUL    AB
                XCH    A,R4
                 MOV     R5,B
                 MOV     B,R6
                MUL    AB
                ADD    A,R5
                 MOV     R5,A
                CLR    A
                ADDC   A,B
                 MOV     R1,A
                 MOV     A,R3
                 MOV     B,R7
                MUL    AB
                ADD    A,R5
                 MOV     R5,A
                 MOV     A,B
                ADDC   A,R1
                 MOV     R1,A
                CLR    A
                ADDC   A,#00H
                XCH    A,R3
                 MOV     B,R6
                MUL    AB
                ADD    A,R1
                 MOV     R1,A
                 MOV     A,B
                ADDC   A,R3
                XCH    A,R5
                 MOV     R3,A
                 MOV     A,R2
                 MOV     B,R7
                MUL    AB
                ADD    A,R1
                 MOV     R1,A
                 MOV     A,B
                ADDC   A,R5
                 MOV     R5,A
                CLR    A
                ADDC   A,#00H
                XCH    A,R2
                 MOV     B,R6
                MUL    AB
                ADD    A,R5
                 MOV     R5,A
                 MOV     A,B
                ADDC   A,R2
                XCH    A,R1
                 MOV     R2,A
                CLR    OV
                RET
      ;N字节无符号数乘法程序 ([R0]*[R1])=([R0])
      ;入口    :R0,R1,M,N
      ;占用资源:ACC,B,R2,R5,R6,R7,NCNT
      ;堆栈需求:2字节
      ;出口    :R0
      NMULMN   : MOV     A,M
                ADD    A,R0
                 MOV     R5,A
                XCH    A,R1
                XCH    A,R5
                ADD    A,N
                XCH    A,R0
                 MOV     R6,A
                 MOV     B,M
                 MOV     NCNT,B
      NMLMN1   :DEC    R0
                DEC    R1
                CLR    A
                XCH    A,@R1
                 MOV     @R0,A
                DJNZ   NCNT,NMLMN1
                 MOV     NCNT,B
      NMLMN2   :CLR    A
                XCH    A,@R0
                 MOV     R2,A
                 MOV     A,R6
                 MOV     R0,A
                 MOV     A,R5
                 MOV     R1,A
                 MOV     R7,N
                CLR    C
      NMLMN3   : MOV     A,R2
                 MOV     B,@R1
                INC    R1
                MUL    AB
                ADDC   A,@R0
                 MOV     @R0,A
                INC    R0
                 MOV     A,B
                ADDC   A,@R0
                 MOV     @R0,A
                DJNZ   R7,NMLMN3
                INC    R0
                INC    R6
                DJNZ   NCNT,NMLMN2
                 MOV     A,R0
                CLR    C
                SUBB   A,M
                SUBB   A,N
                 MOV     R0,A
                RET
      ;单字节无符号除法程序 (R2R3R4/R7)=(R2)R3R4 余数R7
      ;入口    :R2,R3,R4,R7
      ;占用资源:ACC,B,F0
      ;堆栈需求:3字节
      ;出口    :(R2),R3,R4,R7,OV
      NDIV31   : MOV     A,R2
                 MOV     B,R7
                DIV    AB
                PUSH   A
                 MOV     R2,B
                 MOV     B,#10H
      NDV311   :CLR    C
                 MOV     A,R4
                RLC    A
                 MOV     R4,A
                 MOV     A,R3
                RLC    A
                 MOV     R3,A
                 MOV     A,R2
                RLC    A
                 MOV     R2,A
                 MOV     F0,C
                CLR    C
                SUBB   A,R7
                JB     F0,NDV312
                JC     NDV313
      NDV312   : MOV     R2,A
                INC    R4
      NDV313   :DJNZ   B,NDV311
                POP    A
                CLR    OV
                JZ     NDV314
                SETB   OV
      NDV314   :XCH    A,R2
                 MOV     R7,A
                RET
      ;单字节无符号除法程序 (R5R2R3R4/R7)=(R5)R2R3R4 余数R7
      ;入口    :R2,R3,R4,R7
      ;占用资源:ACC,B,F0
      ;堆栈需求:3字节
      ;出口    :(R5),R2,R3,R4,R7,OV
      NDIV41   : MOV     A,R5
                 MOV     B,R7
                DIV    AB
                PUSH   A
                 MOV     R5,B
                 MOV     B,#18H
      NDV411   :CLR    C
                 MOV     A,R4
                RLC    A
                 MOV     R4,A
                 MOV     A,R3
                RLC    A
                 MOV     R3,A
                 MOV     A,R2
                RLC    A
                 MOV     R2,A
                 MOV     A,R5
                RLC    A
                 MOV     R5,A
                 MOV     F0,C
                CLR    C
                SUBB   A,R7
                JB     F0,NDV412
                JC     NDV413
      NDV412   : MOV     R5,A
                INC    R4
      NDV413   :DJNZ   B,NDV411
                POP    A
                CLR    OV
                JZ     NDV414
                SETB   OV
      NDV414   :XCH    A,R5
                 MOV     R7,A
                RET
      ;双字节无符号除法程序 (R5R2R3R4/R6R7)=(R2)R3R4 余数R6R7
      ;入口    :R5,R2,R3,R4,R6,R7
      ;占用资源:ACC,B,F0
      ;堆栈需求:4字节
      ;出口    :(R2),R3,R4,R6,R7,OV
      NDIV42   : MOV     A,R1
                PUSH   A
                 MOV     B,#00H
      NDV421   : MOV     A,R2
                CLR    C
                SUBB   A,R7
                 MOV     R1,A
                 MOV     A,R5
                SUBB   A,R6
                JC     NDV422
                 MOV     R5,A
                 MOV     A,R1
                 MOV     R2,A
                INC    B
                SJMP   NDV421
      NDV422   :PUSH   B
                 MOV     B,#10H
      NDV423   :CLR    C
                 MOV     A,R4
                RLC    A
                 MOV     R4,A
                 MOV     A,R3
                RLC    A
                 MOV     R3,A
                 MOV     A,R2
                RLC    A
                 MOV     R2,A
                XCH    A,R5
                RLC    A
                XCH    A,R5
                 MOV     F0,C
                CLR    C
                SUBB   A,R7
                 MOV     R1,A
                 MOV     A,R5
                SUBB   A,R6
                JB     F0,NCV424
                JC     NDV425
      NCV424   : MOV     R5,A
                 MOV     A,R1
                 MOV     R2,A
                INC    R4
      NDV425   :DJNZ   B,NDV423
                POP    A
                CLR    OV
                JNZ    NDV426
                SETB   OV
      NDV426   :XCH    A,R2
                 MOV     R7,A
                 MOV     A,R5
                 MOV     R6,A
                POP    A
                 MOV     R1,A
                RET
      ;N字节无符号除法程序(组合) ([R0]/[R1])=([R0])
      ;入口    :R0,R1,M,N
      ;占用资源:ACC,R2,R3,R4,R5,R7,NCNT,F0,NADDN,NSUBBN,NRLCN
      ;堆栈需求:4字节
      ;出口    :R0
      ;NDIVMN   : MOV     A,M
                CLR    C
                SUBB   A,N
                 MOV     NCNT,A
                ADD    A,R0
                 MOV     R4,A
                XCH    A,R0
                 MOV     R3,A
                 MOV     A,R1
                 MOV     R5,A
                 MOV     R2,#00H
      NDVMN1   : MOV     R7,N
                LCALL  NSUBN
                 MOV     A,R5
                 MOV     R1,A
                JC     NDVMN2
                INC    R2
                SJMP   NDVMN1
      NDVMN2   : MOV     R7,N
                LCALL  NADDN
                 MOV     A,NCNT
                SWAP   A
                RR     A
                 MOV     NCNT,A
      NDVMN3   : MOV     A,R3
                 MOV     R0,A
                 MOV     R7,M
                LCALL  NRLCN
                 MOV     F0,C
                 MOV     A,R4
                 MOV     R0,A
                 MOV     A,R5
                 MOV     R1,A
                 MOV     R7,N
                LCALL  NSUBN
                JB     F0,NDVMN4
                JC     NDVMN5
      NDVMN4   : MOV     A,R3
                 MOV     R0,A
                INC    @R0
                SJMP   NDVMN6
      NDVMN5   : MOV     A,R5
                 MOV     R1,A
                 MOV     R7,N
                LCALL  NADDN
      NDVMN6   :DJNZ   NCNT,NDVMN3
                 MOV     A,R4
                 MOV     R1,A
                 MOV     A,R2
                 MOV     @R1,A
                 MOV     A,R3
                 MOV     R0,A
                RET
      ;N字节无符号除法程序(集成) ([R0]/R[1])=([R0])
      ;入口    :R0,R1,M,N
      ;占用资源:ACC,R2,R3,R4,R5,R7,F0
      ;堆栈需求:2字节
      ;出口    :R0
      NDIVMN   : MOV     A,M
                CLR    C
                SUBB   A,N
                 MOV     B,A
                ADD    A,R0
                 MOV     R4,A
                XCH    A,R0
                 MOV     R3,A
                 MOV     A,R1
                 MOV     R5,A
                 MOV     R2,#00H
      NDVMN1   : MOV     R7,N
                CLR    C
      NDVMN2   : MOV     A,@R0
                SUBB   A,@R1
                 MOV     @R0,A
                INC    R0
                INC    R1
                DJNZ   R7,NDVMN2
                 MOV     A,R4
                 MOV     R0,A
                 MOV     A,R5
                 MOV     R1,A
                JC     NDVMN3
                INC    R2
                SJMP   NDVMN1
      NDVMN3   : MOV     R7,N
                CLR    C
      NDVMN4   : MOV     A,@R0
                ADDC   A,@R1
                 MOV     @R0,A
                INC    R0
                INC    R1
                DJNZ   R7,NDVMN4
                 MOV     A,#08H
                MUL    AB
                 MOV     B,A
      NDVMN5   : MOV     A,R3
                 MOV     R0,A
                 MOV     R7,M
                CLR    C
      NDVMN6   : MOV     A,@R0
                RLC    A
                 MOV     @R0,A
                INC    R0
                DJNZ   R7,NDVMN6
                 MOV     F0,C
                 MOV     A,R4
                 MOV     R0,A
                 MOV     A,R5
                 MOV     R1,A
                 MOV     R7,N
                CLR    C
      NDVMN7   : MOV     A,@R0
                SUBB   A,@R1
                 MOV     @R0,A
                INC    R0
                INC    R1
                DJNZ   R7,NDVMN7
                JB     F0,NDVMNB
                JC     NDVMN8
      NDVMNB   : MOV     A,R3
                 MOV     R0,A
                INC    @R0
                SJMP   NDVMNA
      NDVMN8   : MOV     R7,N
                 MOV     A,R4
                 MOV     R0,A
                 MOV     A,R5
                 MOV     R1,A
                CLR    C
      NDVMN9   : MOV     A,@R0
                ADDC   A,@R1
                 MOV     @R0,A
                INC    R0
                INC    R1
                DJNZ   R7,NDVMN9
      NDVMNA   :DJNZ   B,NDVMN5
                 MOV     A,M
                CLR    C
                SUBB   A,N
                ADD    A,R3
                 MOV     R1,A
                 MOV     A,R2
                 MOV     @R1,A
                 MOV     A,R3
                 MOV     R0,A
                RET
      ;N字节数据左移程序 RLC([R0])=(CF[R0])
      ;入口    :R0,R7
      ;占用资源:ACC,B
      ;堆栈需求:2字节
      ;出口    :R0,CF
      NRLCN    : MOV     B,R0
                CLR    C
      NRLN1    : MOV     A,@R0
                RLC    A
                 MOV     @R0,A
                INC    R0
                DJNZ   R7,NRLN1
                 MOV     R0,B
                RET

关键词:

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分)
Copyright © 2007-2017 down.gzweix.Com. All Rights Reserved .
页面执行时间:233,824.20000 毫秒