diff --git a/Makefile b/Makefile index fd9194a..98798d2 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,8 @@ LIBSRC = uart_init_.c uart_send_chr.c uart_send_str.c \ long_add__.c long_add.c \ long_1cpl__.c long_invert__.c long_invert.c \ long_sub__.c \ - long_div__.c long_div.c + long_div__.c long_div.c \ + long_fill__.c long_mul__.c long_mul.c LIBOBJ =$(patsubst %.c,%.rel, $(LIBSRC)) diff --git a/long_add__.c b/long_add__.c index 3a64965..b231a52 100644 --- a/long_add__.c +++ b/long_add__.c @@ -6,6 +6,8 @@ static void long_add__() __naked { __asm + .globl long_add + .globl long_addc long_add: clr c long_addc: diff --git a/long_fill__.c b/long_fill__.c new file mode 100644 index 0000000..1dd8275 --- /dev/null +++ b/long_fill__.c @@ -0,0 +1,19 @@ + + +void long_fill() __naked +{ + __asm + .globl long_fill_zero + .globl long_fill + +long_fill_zero: + mov a,#0x00 +long_fill: + mov @r0,a + inc r0 + djnz r7,long_fill + ret + __endasm; +} + + diff --git a/long_mul.c b/long_mul.c new file mode 100644 index 0000000..b144b24 --- /dev/null +++ b/long_mul.c @@ -0,0 +1,28 @@ +#include "mc8051fun.h" + +uint8_t long_mul(__idata uint8_t *v1, __idata uint8_t *v2,uint8_t len, __idata uint8_t *result) __reentrant +{ + (void)v1; (void)v2; (void)len,(void)result; + __asm + mov a,_bp + add a,#0xfd + mov r0,a + mov a,@r0 ; *v2 + dec r0 + mov r1,a + mov a,@r0 ; len + mov r7,a + dec r0 + mov a,@r0 ; result + mov r2,a + mov r0,dpl + lcall long_mul + mov dpl,#0x00 + jnc $002 + inc dpl +$002: + __endasm; +} + + + diff --git a/long_mul__.c b/long_mul__.c new file mode 100644 index 0000000..a2a64b1 --- /dev/null +++ b/long_mul__.c @@ -0,0 +1,55 @@ +#include "mc8051fun.h" + +/* + * val0,val1 = r0,r1 + * r2 = result + * r7 = len of val0,val1 + */ +void long_mul__() __naked +{ + + __asm + .globl long_mul + +long_mul: + push AR0 + push AR7 + mov r0,AR2 + lcall long_fill_zero + pop AR7 + pop AR0 + + mov r6,#8 + mov a,@r1 +000$: + rrc a + jnc 001$ + + push ACC + push AR0 + push AR1 + push AR7 + mov r1,AR0 + mov r0,AR2 + lcall long_add + pop AR7 + pop AR1 + pop AR0 + pop ACC + +001$: + push ACC + push AR7 + push AR0 + clr c + lcall long_rlc + pop AR0 + pop AR7 + pop ACC + + djnz r6,000$ + ret + __endasm; +} + + diff --git a/mc8051fun.h b/mc8051fun.h index a3e8767..bbcd6bb 100644 --- a/mc8051fun.h +++ b/mc8051fun.h @@ -91,6 +91,7 @@ uint8_t multest(uint8_t a, uint8_t b); void bcd_tolong(__idata uint8_t *bcdval, __idata uint8_t *binval, uint8_t bcdlen, uint8_t binlen) __reentrant; void long_invert(__idata uint8_t *val, uint8_t len) __reentrant; uint8_t long_add(__idata uint8_t *v1, __idata uint8_t *v2,uint8_t len) __reentrant; +uint8_t long_mul(__idata uint8_t *v1, __idata uint8_t *v2,uint8_t len, __idata uint8_t *result) __reentrant; #endif