;(r3r2r1r0) = (r7r6) * (r5r4), r4-r7 unchanged
mul_word:mov b,r6
mov a,r4
mul ab
mov r0,a
mov r1,b
mov r2,#0
mov r3,#0
mov a,r7
mov b,r4
mul ab
add a,r1
mov r1,a
mov a,r2
addc a,b
mov r2,a
clr a
addc a,r3
mov r3,a
mov a,r6
mov b,r5
mul ab
add a,r1
mov r1,a
mov a,r2
addc a,b
mov r2,a
clr a
addc a,r3
mov r3,a
mov a,r7
mov b,r5
mul ab
add a,r2
mov r2,a
mov a,r3
addc a,b
mov r3,a
ret
;(r3r2r1r0) = (r3r2r1r0)/(r5r4), (r7r6), r4-r5 unchanged
div_4b: mov r7,#0
mov r6,#0
push count
mov count,#32
clr c
div_4b_loop: mov a,r0 ;(r7r6r3r2r1r0) shift left one bit
rlc a
mov r0,a
mov a,r1
rlc a
mov r1,a
mov a,r2
rlc a
mov r2,a
mov a,r3
rlc a
mov r3,a
mov a,r6
rlc a
mov r6,a
mov a,r7
rlc a
mov r7,a
clr c ;if (r7r6)>=(r5r4),(r7r6)-=(r5r4)
mov a,r6
subb a,r4
mov b,a
mov a,r7
subb a,r5
jc div_4b_1
mov r6,b
mov r7,a
div_4b_1: cpl c
djnz count,div_4b_loop
mov a,r0
rlc a
mov r0,a
mov a,r1
rlc a
mov r1,a
mov a,r2
rlc a
mov r2,a
mov a,r3
rlc a
mov r3,a
pop count
ret