您的位置 首页 主动

单片机的乘除比如

/*———————————————————————–双字节的乘法(R22:R23)*(R24:R25)–

/*

———————————————————————–
双字节的乘法
(R22:R23)*(R24:R25)–>(R20:R21:R22:R23)
counter : r26
———————————————————————–
*/

mul_sub:
clr r20
clr r21
mov a,@16
mov r26,a
bc psw,c
rrc r22
rrc r23
mul_r1:
jbs psw,c
jmp mul_r2
mov a,r25
add r21,a
jbc psw,c
inc r20
jbc psw,c
jmp mul_r0
mov a,r24
add r20,a
jmp mul_r2
mul_r0:
mov a,r24
add r20,a
bs psw,c
mul_r2:
rrc r20
rrc r21
rrc r22
rrc r23
djz r26
jmp mul_r1
ret

/*
————————————————————————
多字节除法子程序
R20R21R22R23 / R24R25 =R22R23 …R20R21
counter : r26
————————————————————————
*/
div_sub:
mov a,r24
sub a,r20
jbs psw,c
jmp div_begin
jbs psw,z
jmp div_overflow
mov a,r25
sub a,r21
jbs psw,c
jmp div_begin
div_overflow:
bs flag_cal,div_flow
ret
div_begin:
mov a,@16
mov r26,a
div_loop:
bc psw,c
rlc r23
rlc r22
rlc r21
rlc r20
jbc psw,c
jmp div_r3
mov a,r24
sub a,r20
jbs psw,z
jmp div_r2
div_r1:
mov a,r25
sub a,r21
jbc psw,z
jmp div_r3
div_r2:
jbs psw,c
jmp div_end
div_r3:
bs r23,0
mov a,r24
sub r20,a
mov a,r25
sub r21,a
jbs psw,c
dec r20

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/ziliao/zhudong/268361.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部