单片机 三字节除法子程序
时间:11-23
来源:互联网
点击:
ORG 0000H
AJMP MAIN
ORG 0030H
MAIN:
MOV 77H,#0FH
MOV 78H,#42H
MOV 79H,#40H
MOV 7AH,#00H
MOV 7BH,#03H
MOV 7CH,#0E8H
LCALL div_MB
SJMP MAIN
;=================================================
; divISION FOR THREE-BYTE DATA
; divIDEND FROM 77H&78H&79H
; divISOR FROM 7AH&7BH&7CH
; QUOTIENT TO 77H&78H&79H
;ARITHMETICAL COMPLIMENT TO 7DH&7EH&7FH
; 2008_05_08 BY SZCKIC
;=================================================
div_MB: MOV 7DH,#00H
MOV 7EH,#00H
MOV 7FH,#00H
MOV R7,#18H
NEXTBIT:
CLR C
MOV A,79H
RLC A
MOV 79H,A
MOV A,78H
RLC A
MOV 78H,A
MOV A,77H
RLC A
MOV 77H,A
;Arithmetical compliment
MOV A,7FH
RLC A
MOV 7FH,A
MOV A,7EH
RLC A
MOV 7EH,A
MOV A,7DH
RLC A
MOV 7DH,A
MOV 5AH,7DH
MOV 5BH,7EH
MOV 5CH,7FH
MOV 5DH,7AH
MOV 5EH,7BH
MOV 5FH,7CH
LCALL TDEC
JNC UPDATE
DJNZ R7,NEXTBITTMP
RET
UPDATE: INC 79H
MOV 7FH,5CH
MOV 7EH,5BH
MOV 7DH,5AH
AJMP MAIN
ORG 0030H
MAIN:
MOV 77H,#0FH
MOV 78H,#42H
MOV 79H,#40H
MOV 7AH,#00H
MOV 7BH,#03H
MOV 7CH,#0E8H
LCALL div_MB
SJMP MAIN
;=================================================
; divISION FOR THREE-BYTE DATA
; divIDEND FROM 77H&78H&79H
; divISOR FROM 7AH&7BH&7CH
; QUOTIENT TO
;ARITHMETICAL COMPLIMENT TO 7DH&7EH&7FH
; 2008_05_08 BY SZCKIC
;=================================================
div_MB: MOV 7DH,#00H
MOV 7EH,#00H
MOV 7FH,#00H
MOV R7,#18H
NEXTBIT:
CLR C
MOV A,79H
RLC A
MOV 79H,A
MOV A,78H
RLC A
MOV 78H,A
MOV A,77H
RLC A
MOV 77H,A
;Arithmetical compliment
MOV A,7FH
RLC A
MOV 7FH,A
MOV A,7EH
RLC A
MOV 7EH,A
MOV A,7DH
RLC A
MOV 7DH,A
MOV 5AH,7DH
MOV 5BH,7EH
MOV 5CH,7FH
MOV 5DH,7AH
MOV 5EH,7BH
MOV 5FH,7CH
LCALL TDEC
JNC UPDATE
DJNZ R7,NEXTBITTMP
RET
UPDATE: INC 79H
MOV 7FH,5CH
MOV 7EH,5BH
MOV 7DH,5AH
DJNZ R7,NEXTBITTMP
RET
NEXTBITTMP:LJMP NEXTBIT
;=================================================
; Subtracter for three-byte data
;=================================================
TDEC: CLR C
MOV A,5CH
SUBB A,5FH
MOV 5CH,A
MOV A,5BH
SUBB A,5EH
MOV 5BH,A
MOV A,5AH
SUBB A,5DH
MOV 5AH,A
RET
除法程序写成了子程序形式,很方便调用,除法中要频繁用到三字节数据大小的比较,所以也写成了一个小子程序。
思路很简单,抛开我们习惯了的乘法口诀,以一个小学二年级学生的思路去做就简单了,一步一步的比较、移位,只不过这里是二进制而不是习惯了的十进制,当然二进制也有一个优点那就是:
假设A,B是两个同样位数的二进制数据(首位不为0),且A>B,则A肯定小于2倍的B,所以对于每次移位只用比较一次。
单片机三字节除法子程 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)