/*
———————————————————————–
双字节的乘法
(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