单片机多字节乘除法程序怎么编?
2个回答
展开全部
多字节无符号数乘法:
DOMUL:
MOV A,R1
MOV R6,A
MOV A,R0
MOV R5,A
MOV A,R2
ADD A,R2
MOV 26H,A
MOV R7,A
MOV A,R4
MOV R0,A
CLEAR:
MOV @R0,#00H
INC R0
DJNZ R7,CLEAR
MOV A,R4
MOV R7,A
MOV 27H,R7
MOV 20H,R2
LP0:
MOV A,R5
MOV R0,A
MOV A,@R0
MOV B,@R1
MUL AB
ACALL ADDM
INC R1
DJNZ R2,LP0
MOV R2,20H
MOV A,R6
MOV R1,A
MOV A,R7
INC A
MOV R7,A
MOV R4,A
INC R5
DJNZ R3,LP0
MOV R4,27H
MOV R5,26H
RET
ADDM:
MOV 21H,A
MOV A,R4
MOV R0,A
MOV A,21H
ADD A,@R0
MOV @R0,A
MOV A,B
INC R0
ADDC A,@R0
MOV @R0,A
INC R0
MOV A,@R0
ADDC A,#00H
MOV @R0,A
DEC R0
MOV A,R0
MOV R4,A
RET
多字节无符号数除法:
DODIV:
MOV A,R0
MOV R4, A
MOV A, R1
MOV R5, A
MOV A, R3
MOV R7, A
MOV A, R0
ADD A, R3
MOV R6,A
MOV R1, A
LP0:
MOV @R1,#00H
INC R1
DJNZ R3, LP0
MOV A,R7
ADD A, R7
MOV R2, A
MOV B, #04H
MUL AB
LP1:
PUSH A
MOV A, R2
MOV R3, A
MOV A, R4
MOV R1, A
CLR C
LP2:
MOV A,@R1
RLC A
MOV @R1, A
INC R1
DJNZ R3, LP2
NEXT:
MOV A, R6
MOV R0, A
MOV A, R5
MOV R1, A
MOV A, R7
MOV R3, A
CLR C
LP3:
MOV A,@R0
SUBB A,@R1
PUSH A
INC R0
INC R1
DJNZ R3, LP3
MOV A, R7
MOV R3, A
JC SMALL
MOV A, R4
MOV R0, A
INC @R0
MOV A, R6
ADD A, R7
DEC A
MOV R0, A
LP4:
POP A
MOV @R0, A
DEC R0
DJNZ R3, LP4
SJMP NEXT
SMALL:
POP A
DJNZ R3, SMALL
POP A
DEC A
JNZ LP1
I504:
MOV A,R6
ADD A, R7
DEC A
MOV R0, A
MOV R2, A
MOV A,@R0
JB E7H, ADD1
MOV A, R6
MOV R1, A
MOV A, R7
MOV R3, A
CLR C
LP5:
MOV A,@R1
RLC A
MOV @R1, A
INC R1
DJNZ R3, LP5
MOV A, R2
MOV R0, A
MOV A, R7
MOV R3, A
ADD A, R5
DEC A
MOV R1, A
LP6:
CLR C
MOV A,@R0
SUBB A,@R1
JC RETURN
JNZ ADD1
DEC R0
DEC
DJNZ R3, LP6
ADD1:
MOV A,R4
MOV R1, A
MOV A, R7
MOV R3, A
SETB C
LP7l:
MOV A,@R1
ADDC A, #00H
MOV @R1, A
DJNZ R3, LP7
RETURN:
MOV A,R4
MOV R0, A
MOV A, R7
MOV R3, A
RET
DOMUL:
MOV A,R1
MOV R6,A
MOV A,R0
MOV R5,A
MOV A,R2
ADD A,R2
MOV 26H,A
MOV R7,A
MOV A,R4
MOV R0,A
CLEAR:
MOV @R0,#00H
INC R0
DJNZ R7,CLEAR
MOV A,R4
MOV R7,A
MOV 27H,R7
MOV 20H,R2
LP0:
MOV A,R5
MOV R0,A
MOV A,@R0
MOV B,@R1
MUL AB
ACALL ADDM
INC R1
DJNZ R2,LP0
MOV R2,20H
MOV A,R6
MOV R1,A
MOV A,R7
INC A
MOV R7,A
MOV R4,A
INC R5
DJNZ R3,LP0
MOV R4,27H
MOV R5,26H
RET
ADDM:
MOV 21H,A
MOV A,R4
MOV R0,A
MOV A,21H
ADD A,@R0
MOV @R0,A
MOV A,B
INC R0
ADDC A,@R0
MOV @R0,A
INC R0
MOV A,@R0
ADDC A,#00H
MOV @R0,A
DEC R0
MOV A,R0
MOV R4,A
RET
多字节无符号数除法:
DODIV:
MOV A,R0
MOV R4, A
MOV A, R1
MOV R5, A
MOV A, R3
MOV R7, A
MOV A, R0
ADD A, R3
MOV R6,A
MOV R1, A
LP0:
MOV @R1,#00H
INC R1
DJNZ R3, LP0
MOV A,R7
ADD A, R7
MOV R2, A
MOV B, #04H
MUL AB
LP1:
PUSH A
MOV A, R2
MOV R3, A
MOV A, R4
MOV R1, A
CLR C
LP2:
MOV A,@R1
RLC A
MOV @R1, A
INC R1
DJNZ R3, LP2
NEXT:
MOV A, R6
MOV R0, A
MOV A, R5
MOV R1, A
MOV A, R7
MOV R3, A
CLR C
LP3:
MOV A,@R0
SUBB A,@R1
PUSH A
INC R0
INC R1
DJNZ R3, LP3
MOV A, R7
MOV R3, A
JC SMALL
MOV A, R4
MOV R0, A
INC @R0
MOV A, R6
ADD A, R7
DEC A
MOV R0, A
LP4:
POP A
MOV @R0, A
DEC R0
DJNZ R3, LP4
SJMP NEXT
SMALL:
POP A
DJNZ R3, SMALL
POP A
DEC A
JNZ LP1
I504:
MOV A,R6
ADD A, R7
DEC A
MOV R0, A
MOV R2, A
MOV A,@R0
JB E7H, ADD1
MOV A, R6
MOV R1, A
MOV A, R7
MOV R3, A
CLR C
LP5:
MOV A,@R1
RLC A
MOV @R1, A
INC R1
DJNZ R3, LP5
MOV A, R2
MOV R0, A
MOV A, R7
MOV R3, A
ADD A, R5
DEC A
MOV R1, A
LP6:
CLR C
MOV A,@R0
SUBB A,@R1
JC RETURN
JNZ ADD1
DEC R0
DEC
DJNZ R3, LP6
ADD1:
MOV A,R4
MOV R1, A
MOV A, R7
MOV R3, A
SETB C
LP7l:
MOV A,@R1
ADDC A, #00H
MOV @R1, A
DJNZ R3, LP7
RETURN:
MOV A,R4
MOV R0, A
MOV A, R7
MOV R3, A
RET
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询