- 51单片机双字节乘法运算原理和除法运算原理
-
- ****************************************************
- ;* 两字节无符号数乘法程序 *
- ;****************************************************
- ; R7R6R5R4 <= R3R2 * R1R0
- ;
- MUL2BY2: CLR A ;清零R4--R7
- MOV R7, A
- MOV R6, A
- MOV R5, A
- MOV R4, A
- MOV 46H, #10H
- MULLOOP1: CLR C ;进位端清零
- MOV A, R4
- RLC A
- MOV R4, A
- MOV A, R5
- RLC A
- MOV R5, A
- MOV A, R6
- RLC A
- MOV R6, A
- MOV A, R7
- RLC A
- MOV R7, A
- MOV A, R0
- RLC A
- MOV R0, A
- MOV A, R1
- RLC A
- MOV R1, A
- JNC MULLOOP2
- MOV A, R4
- ADD A, R2
- MOV R4, A
- MOV A, R5
- ADDC A, R3
- MOV R5, A
- MOV A, R6
- ADDC A, #00H
- MOV R6, A
- MOV A, R7
- ADDC A, #00H
- MOV R7, A
- MULLOOP2: DJNZ 46H, MULLOOP1
- RET
- ;
- ;****************************************************
- ;* 四字节/两字节无符号数除法程序 *
- ;****************************************************
- ;R7R6R5R4/R3R2=R7R6R5R4(商)...R1R0(余数)
- ;
- DIV4BY2: MOV 46H, #20H
- MOV R0, #00H
- MOV R1, #00H
- DIVLOOP1: MOV A, R4
- RLC A
- MOV R4, A
- MOV A, R5
- RLC A
- MOV R5, A
- MOV A, R6
- RLC A
- MOV R6, A
- MOV A, R7
- RLC A
- MOV R7, A
- MOV A, R0
- RLC A
- MOV R0, A
- MOV A, R1
- RLC A
- MOV R1, A
- CLR C
- MOV A, R0
- SUBB A, R2
- MOV B, A
- MOV A, R1
- SUBB A, R3
- JC DIVLOOP2
- MOV R0, B
- MOV R1, A
- DIVLOOP2: CPL C
- DJNZ 46H, DIVLOOP1
- MOV A, R4
- RLC A
- MOV R4, A
- MOV A, R5
- RLC A
- MOV R5, A
- MOV A, R6
- RLC A
- MOV R6, A
- MOV A, R7
- RLC A
- MOV R7, A
- RET
- 这是两个已经编好的程序
复制代码 |