From 4eae6e7023bcfefa3630f87503a34c3b3c34bcb2 Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@mail.ru> Date: Wed, 5 Jun 2024 08:19:50 +0200 Subject: [PATCH] Initial commit --- long_xadd.c | 24 +++++++++++++++++++ long_xdiv.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ long_xrlc.c | 21 ++++++++++++++++ long_xset.c | 17 +++++++++++++ long_xsub.c | 28 ++++++++++++++++++++++ 5 files changed, 159 insertions(+) create mode 100644 long_xadd.c create mode 100644 long_xdiv.c create mode 100644 long_xrlc.c create mode 100644 long_xset.c create mode 100644 long_xsub.c diff --git a/long_xadd.c b/long_xadd.c new file mode 100644 index 0000000..c5579c5 --- /dev/null +++ b/long_xadd.c @@ -0,0 +1,24 @@ + + + +void long_xadd() __naked +{ + __asm + .globl long_xadd + .globl long_xaddc +long_xadd: + clr c +long_xaddc: + movx a,@r1 + mov b,a + movx a,@r0 + addc a,b + movx @r0,a + inc r0 + inc r1 + djnz r7,long_xaddc + ret + __endasm; +} + + diff --git a/long_xdiv.c b/long_xdiv.c new file mode 100644 index 0000000..e2f1515 --- /dev/null +++ b/long_xdiv.c @@ -0,0 +1,69 @@ +#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; +} + + diff --git a/long_xrlc.c b/long_xrlc.c new file mode 100644 index 0000000..dd61224 --- /dev/null +++ b/long_xrlc.c @@ -0,0 +1,21 @@ + +/* + * + */ +void long_xrlc() __naked +{ + __asm + .globl long_xrlc + +long_xrlc: + movx a,@r0 + rlc a + movx @r0,a + inc r0 + djnz r7,long_xrlc + ret + + __endasm; +} + + diff --git a/long_xset.c b/long_xset.c new file mode 100644 index 0000000..b1d4736 --- /dev/null +++ b/long_xset.c @@ -0,0 +1,17 @@ + + +void long_xset() __naked +{ + __asm + .globl long_xset_zero + .globl long_xset + +long_xset_zero: + mov a,#0x00 +long_xset: + movx @r0,a + djnz r7,long_xset + __endasm; +} + + diff --git a/long_xsub.c b/long_xsub.c new file mode 100644 index 0000000..a0fa8a6 --- /dev/null +++ b/long_xsub.c @@ -0,0 +1,28 @@ + + +/** + * @r0=@r0-@r1 + * r7=len + */ +void long_xsub() __naked +{ + __asm + .globl long_xsub + .globl long_xsubb +long_xsub: + clr c +long_xsubb: + movx a,@r1 + mov b,a + movx a,@r0 + subb a,b + movx @r0,a + inc r0 + inc r1 + djnz r7,long_xsubb + ret + + __endasm; +} + +