New functions

This commit is contained in:
7u83 2024-07-03 07:37:01 +02:00
parent 6153bb3fb4
commit ffeea2dfaf
4 changed files with 129 additions and 1 deletions

View File

@ -29,7 +29,9 @@ LIBSRC = uart_init_.c uart_send_chr.c uart_send_str.c \
bcd_tolong__.c bcd_tolong.c \ bcd_tolong__.c bcd_tolong.c \
long_addbyte__.c long_addbyte.c \ long_addbyte__.c long_addbyte.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_div__.c long_div.c
LIBOBJ =$(patsubst %.c,%.rel, $(LIBSRC)) LIBOBJ =$(patsubst %.c,%.rel, $(LIBSRC))

34
long_div.c Normal file
View File

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

67
long_div__.c Normal file
View File

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

25
long_sub__.c Normal file
View File

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