70 lines
812 B
C
70 lines
812 B
C
#include "mc8051fun.h"
|
|
|
|
/*
|
|
* r0 = numerator
|
|
* r1 = denominator
|
|
* r2 = quotient (result)
|
|
* r3 = rest
|
|
* r7 = length in bytes
|
|
*/
|
|
void long_xdiv() __naked
|
|
{
|
|
__asm
|
|
.globl long_xdiv
|
|
long_xdiv:
|
|
|
|
mov r5,AR7 ;#0x01
|
|
push AR0
|
|
mov r0,AR3
|
|
lcall long_xset_zero
|
|
pop AR0
|
|
|
|
mov r4,AR1
|
|
clr c
|
|
mov a,r0
|
|
addc a,r5 ;#DIGITS-1
|
|
mov r0,a
|
|
003$:
|
|
movx a,@r0
|
|
mov r6,#8
|
|
002$:
|
|
rlc a
|
|
push ACC
|
|
push AR0
|
|
|
|
mov r0,AR3 ;#_rest
|
|
mov r7,AR5 ;#DIGITS
|
|
lcall long_xrlc
|
|
|
|
mov r0,AR3 ;#_rest
|
|
; mov r1,#_val1
|
|
mov r7,AR5 ;#DIGITS
|
|
push AR1
|
|
lcall long_xsub
|
|
pop AR1
|
|
|
|
jnc 001$
|
|
mov r0,AR3 ;#_rest
|
|
; mov r1,#_val1
|
|
mov r7,AR5 ;#DIGITS
|
|
push AR1
|
|
lcall long_xadd
|
|
pop AR1
|
|
setb c
|
|
001$:
|
|
cpl c
|
|
mov r0,AR2 ; #_result
|
|
mov r7,AR5 ;#DIGITS
|
|
lcall long_xrlc
|
|
|
|
pop AR0
|
|
pop ACC
|
|
djnz r6,002$
|
|
djnz r0,003$
|
|
ret
|
|
|
|
__endasm;
|
|
}
|
|
|
|
|