Added long_mul function

This commit is contained in:
7u83 2024-07-14 23:43:05 +02:00
parent 71a551d028
commit 5761d5c513
6 changed files with 107 additions and 1 deletions

View File

@ -31,7 +31,8 @@ LIBSRC = uart_init_.c uart_send_chr.c uart_send_str.c \
long_add__.c long_add.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_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)) LIBOBJ =$(patsubst %.c,%.rel, $(LIBSRC))

View File

@ -6,6 +6,8 @@
static void long_add__() __naked static void long_add__() __naked
{ {
__asm __asm
.globl long_add
.globl long_addc
long_add: long_add:
clr c clr c
long_addc: long_addc:

19
long_fill__.c Normal file
View File

@ -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;
}

28
long_mul.c Normal file
View File

@ -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;
}

55
long_mul__.c Normal file
View File

@ -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;
}

View File

@ -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 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; 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_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 #endif