mc8051fun/long_div__.c

68 lines
772 B
C
Raw Normal View History

2024-07-03 07:37:01 +02:00
#include "mc8051fun.h"
/*
* r0 = numerator
* r1 = denominator
* r2 = quotient (result)
* r3 = rest
* r7 = length in bytes
*/
static void long_div__() __naked
{
__asm
.globl long_div
long_div:
mov r5,AR7 ;#0x01
push AR0
mov r0,AR3
; lcall long_xset_zero
pop AR0
mov r4,AR1
mov a,r0
add a,r5 ;#DIGITS-1
mov r0,a
003$:
mov a,@r0
mov r6,#8
002$:
rlc a
push ACC
push AR0
mov r0,AR3 ;#_rest
mov r7,AR5 ;#DIGITS
lcall long_rlc
mov r0,AR3 ;#_rest
mov r7,AR5 ;#DIGITS
push AR1
lcall long_sub
pop AR1
jnc 001$
mov r0,AR3 ;#_rest
mov r7,AR5 ;#DIGITS
push AR1
lcall long_add
pop AR1
setb c
001$:
cpl c
mov r0,AR2 ; #_result
mov r7,AR5 ;#DIGITS
lcall long_rlc
pop AR0
pop ACC
djnz r6,002$
djnz r0,003$
ret
__endasm;
}