From ffeea2dfafd6bd37fce9f1860092d68f3264f8fb Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@mail.ru> Date: Wed, 3 Jul 2024 07:37:01 +0200 Subject: [PATCH] New functions --- Makefile | 4 +++- long_div.c | 34 ++++++++++++++++++++++++++ long_div__.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ long_sub__.c | 25 ++++++++++++++++++++ 4 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 long_div.c create mode 100644 long_div__.c create mode 100644 long_sub__.c diff --git a/Makefile b/Makefile index 0fc454c..fd9194a 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,9 @@ LIBSRC = uart_init_.c uart_send_chr.c uart_send_str.c \ bcd_tolong__.c bcd_tolong.c \ long_addbyte__.c long_addbyte.c \ long_add__.c long_add.c \ - long_1cpl__.c long_invert__.c long_invert.c + long_1cpl__.c long_invert__.c long_invert.c \ + long_sub__.c \ + long_div__.c long_div.c LIBOBJ =$(patsubst %.c,%.rel, $(LIBSRC)) diff --git a/long_div.c b/long_div.c new file mode 100644 index 0000000..893e33b --- /dev/null +++ b/long_div.c @@ -0,0 +1,34 @@ +#include "mc8051fun.h" +#include "bcd.h" + +#pragma disable_warning 59 // Disable "must return a value" warning + + +void long_div(__idata uint8_t *v1, __idata uint8_t *v2, + __idata uint8_t *result, __idata uint8_t *rest, uint8_t len) __reentrant +{ + + (void)v1; (void)v2; (void)len; + (void)result; (void)rest; + + __asm + mov a,_bp + add a,#0xfd + mov r0,a + mov a,@r0 ; *v2 + dec r0 + mov r1,a + mov a,@r0 ; *result + dec r0 + mov r2,a + mov a,@r0 ; *rest + dec r0 + mov r3,a + mov a,@r0 ; len + mov r7,a + mov r0,dpl ; *v1 + lcall long_div + __endasm; + +} + diff --git a/long_div__.c b/long_div__.c new file mode 100644 index 0000000..d51e8b4 --- /dev/null +++ b/long_div__.c @@ -0,0 +1,67 @@ +#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; +} + + diff --git a/long_sub__.c b/long_sub__.c new file mode 100644 index 0000000..097399b --- /dev/null +++ b/long_sub__.c @@ -0,0 +1,25 @@ + +/** + * @r0=@r0-@r1 + * r7=len + */ +static void long_sub() __naked +{ + __asm + .globl long_sub + .globl long_subb +long_sub: + clr c +long_subb: + mov a,@r0 + subb a,@r1 + mov @r0,a + inc r0 + inc r1 + djnz r7,long_xsubb + ret + + __endasm; +} + +