MCS51算術運算程序
雙字節取補程序 /(R3R4)=(R3R4)
;入口??? :R3,R4
;占用資源:ACC
;堆棧需求:2字節
;出口??? :R3,R4
CMPT???? :MOV??? A,R4
????????? CPL??? A
????????? ADD??? A,#01H
????????? MOV??? R4,A
????????? MOV??? A,R3
????????? CPL??? A
????????? ADDC?? A,#00H
????????? MOV??? R3,A
????????? RET
;N節取補程序 /([R0])=([R0])
;入口??? :R0,R7
;占用資源:ACC,B
;堆棧需求:2字節
;出口??? :R0
NCMPTN?? :MOV??? B,R0
????????? SETB?? C
NCPT1??? :MOV??? A,@R0
????????? CPL??? A
????????? ADDC?? A,#00H
????????? MOV??? @R0,A
????????? INC??? R0
????????? DJNZ?? R7,NCPT1
????????? MOV??? R0,B
????????? RET
;雙字節無符號數加法程序 (R3R4+R6R7)=(R3R4)
;入口??? :R3,R4,R6,R7
;占用資源:ACC
;堆棧需求:2字節
;出口??? :R3,R4,CF
NADD???? :MOV??? A,R4
????????? ADD??? A,R7
????????? MOV??? R4,A
????????? MOV??? A,R3
????????? ADDC?? A,R6
????????? MOV??? R3,A
????????? RET
;N字節無符號數加法程序 ([R0]+[R1])=([R0])
;入口??? :R0,R1,R7
;占用資源:ACC,B
;堆棧需求:2字節
;出口??? :R0,CF
NADDN??? :MOV??? B,R0
????????? CLR??? C
NADN1??? :MOV??? A,@R0
????????? ADDC?? A,@R1
????????? MOV??? @R0,A
????????? INC??? R0
????????? INC??? R1
????????? DJNZ?? R7,NADN1
????????? MOV??? R0,B
????????? RET
;雙字節無符號數減法程序 (R3R4-R6R7)=(R3R4)
;入口??? :R3,R4,R6,R7
;占用資源:ACC
;堆棧需求:2字節
;出口??? :R3,R4
NSUB???? :MOV??? A,R4
????????? CLR??? C
????????? SUBB?? A,R7
????????? MOV??? R4,A
????????? MOV??? A,R3
????????? SUBB?? A,R6
????????? MOV??? R3,A
????????? RET
;N字節無符號數減法程序 ([R0]-[R1])=([R0])
;入口??? :R0,R1,R7
;占用資源:ACC,B
;堆棧需求:2字節
;出口??? :R0,CF
NSUBN??? :MOV??? B,R0
????????? MOV??? R7,N
????????? CLR??? C
NSUBN1?? :MOV??? A,@R0
????????? SUBB?? A,@R1
????????? MOV??? @R0,A
????????? INC??? R0
????????? INC??? R1
????????? DJNZ?? R7,NSUBN1
????????? MOV??? R0,B
????????? RET
;單字節無符號數乘法程序 (R3R4*R7)=(R2R3R4)
;入口??? :R3,R4,R7
;占用資源:ACC,B
;堆棧需求:2字節
;出口??? :R2,R3,R4
NMUL21?? :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
????????? MOV??? R2,A
????????? CLR??? OV
????????? RET
;單字節無符號數乘法程序 (R2R3R4*R7)=(R5R2R3R4)
;入口??? :R2,R3,R4,R6,R7
;占用資源:ACC,B
;堆棧需求:2字節
;出口??? :R5,R2,R3,R4
NMUL31?? :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
????????? MOV??? R5,A
????????? CLR??? OV
????????? RET
;單字節無符號數乘法程序 (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
;原碼有符號雙字節減法程序 (R3R4-R6R7)=R3R4
;入口??? :R3,R4,R6,R7
;占用資源:ACC,DADD
;堆棧需求:6字節
;出口??? :R3,R4,OV
DSUB???? :MOV??? A,R6
????????? CPL??? ACC.7
????????? MOV??? R6,A
????????? LCALL? DADD
????????? RET
;原碼有符號雙字節加法程序 (R3R4+R6R7)=R3R4
;入口??? :R3,R4,R6,R7
;占用資源:ACC,SR0,NADD,NSUB,CMPT
;堆棧需求:4字節
;出口??? :R3,R4,OV
DADD???? :MOV??? A,R3
????????? MOV??? C,ACC.7
????????? MOV??? SR0,C
????????? XRL??? A,R6
????????? MOV??? C,ACC.7
????????? MOV??? A,R3
????????? CLR??? ACC.7
????????? MOV??? R3,A
????????? MOV??? A,R6
????????? CLR??? ACC.7
????????? MOV??? R6,A
????????? JC???? DAB2
????????? LCALL? NADD
????????? MOV??? A,R3
????????? JB???? ACC.7,DABE
DAB1???? :MOV??? C,SR0
????????? MOV??? ACC.7,C
????????? MOV??? R3,A
????????? CLR??? OV
????????? RET
DABE???? :SETB?? OV
????????? RET
DAB2???? :LCALL? NSUB
????????? MOV??? A,R3
????????? JNB??? ACC.7,DAB1
????????? LCALL? CMPT
????????? CPL??? SR0
????????? SJMP?? DAB1
;原碼有符號雙字節乘法程序 (R3R4*R6R7)=(R5R2R3R4)
;入口??? :R3,R4,R6,R7
;占用資源:ACC,SR0,NMUL22
;堆棧需求:4字節
;出口??? :R5,R2,R3,R4
IMUL???? :MOV??? A,R3
????????? XRL??? A,R6
????????? MOV??? C,ACC.7
????????? MOV??? SR0,C
????????? MOV??? A,R3
????????? CLR??? ACC.7
????????? MOV??? R3,A
????????? MOV??? A,R6
????????? CLR??? ACC.7
????????? MOV??? R6,A
????????? LCALL? NMUL22
????????? MOV??? A,R5
????????? MOV??? C,SR0
????????? MOV??? ACC.7,C
????????? MOV??? R5,A
????????? RET
;原碼有符號雙字節除法程序 (R5R2R3R4/R6R7)=(R3R4) 余數(R6R7)
;入口??? :R5,R2,R3,R4
;占用資源:ACC,SR0,NDIV42
;堆棧需求:6字節
;出口??? :R3,R4,R6,R7,OV
IDIV???? :MOV??? A,R5
????????? XRL??? A,R6
????????? MOV??? C,ACC.7
????????? MOV??? SR0,C
????????? MOV??? A,R5
????????? CLR??? ACC.7
????????? MOV??? R5,A
????????? MOV??? A,R6
????????? CLR??? ACC.7
????????? MOV??? R6,A
????????? LCALL? NDIV42
????????? MOV??? A,R3
????????? JB???? ACC.7,IDIVE
????????? JB???? OV,IDIVE
????????? MOV??? C,SR0
????????? MOV??? ACC.7,C
????????? MOV??? R3,A
????????? RET
IDIVE??? :SETB?? OV
????????? RET
評論
查看更多