新聞中心

單片機的乘除例子

作者: 時間:2016-11-17 來源:網(wǎng)絡(luò) 收藏
/*

-----------------------------------------------------------------------
雙字節(jié)的乘法
(R22:R23)*(R24:R25)-->(R20:R21:R22:R23)
counter : r26
-----------------------------------------------------------------------
*/

本文引用地址:http://butianyuan.cn/article/201611/315479.htm

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

/*
------------------------------------------------------------------------
多字節(jié)除法子程序
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



關(guān)鍵詞: 單片機乘

評論


技術(shù)專區(qū)

關(guān)閉