bcd_tolong function added.

This commit is contained in:
7u83 2024-07-01 22:31:49 +02:00
parent b24da848ac
commit 11db18ee92
4 changed files with 104 additions and 1 deletions

View File

@ -25,7 +25,9 @@ LIBSRC = uart_init_.c uart_send_chr.c uart_send_str.c \
multest.c \ multest.c \
bcd_add.c bcd_getsig.c bcd_invert.c bcd_9cpl.c bcd_addbyte.c bcd_shr.c \ bcd_add.c bcd_getsig.c bcd_invert.c bcd_9cpl.c bcd_addbyte.c bcd_shr.c \
long_rrc__.c long_rlc__.c \ long_rrc__.c long_rlc__.c \
long_tobcd__.c long_tobcd.c long_tobcd__.c long_tobcd.c \
bcd_tolong__.c bcd_tolong.c
LIBOBJ =$(patsubst %.c,%.rel, $(LIBSRC)) LIBOBJ =$(patsubst %.c,%.rel, $(LIBSRC))
LIBNAME=mc8051fun.lib LIBNAME=mc8051fun.lib

33
bcd_tolong.c Normal file
View File

@ -0,0 +1,33 @@
#include "mc8051fun.h"
/*
* C-Wrapper for bcd_tolong
*/
void bcd_tolong(__idata uint8_t *bcdval, __idata uint8_t *binval, uint8_t bcdlen, uint8_t binlen) __reentrant
{
(void)binval;
(void)bcdval;
(void)binlen;
(void)bcdlen;
__asm
mov a,_bp
add a,#0xfd
mov r0,a
mov a,@r0 ; binval
mov r1,a
dec r0
mov a,@r0 ; bcdlen
mov r7,a
dec r0
mov a,@r0 ; binlen
mov r6,a
mov r0,dpl ; bcdval
lcall bcd_tolong
__endasm;
}

67
bcd_tolong__.c Normal file
View File

@ -0,0 +1,67 @@
#include "usebank0.h"
/*
r0 = bcd
r1 = bin
r7 = len of bcd
r6 = len of bin
reverse double dabble
*/
static void bcd_tolong__() __naked
{
__asm
.globl bcd_tolong
bcd_tolong:
mov a,AR6 ; use r4 as counter
mov b,#0x08
mul ab
mov r4,a
000$:
push AR0
push AR7
clr c
lcall long_rrc
mov r0,AR1
mov r7,AR6
lcall long_rrc
pop AR7
pop AR0
push AR0
push AR7
001$:
mov a,@r0
acall 003$
acall 003$
mov @r0,a
inc r0
djnz r7,001$
pop AR7
pop AR0
djnz r4,000$
ret
003$:
swap a
clr c
subb a,#0x80
jc 002$
subb a,#0x30
002$:
add a,#0x80
ret
__endasm;
}

View File

@ -88,6 +88,7 @@ uint8_t getport(int n);
uint8_t multest(uint8_t a, uint8_t b); 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;
#endif #endif