From 11db18ee923c5da0d019c3311ef4178d9d5c565a Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@mail.ru> Date: Mon, 1 Jul 2024 22:31:49 +0200 Subject: [PATCH] bcd_tolong function added. --- Makefile | 4 ++- bcd_tolong.c | 33 +++++++++++++++++++++++++ bcd_tolong__.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ mc8051fun.h | 1 + 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 bcd_tolong.c create mode 100644 bcd_tolong__.c diff --git a/Makefile b/Makefile index 3d27725..8d85778 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,9 @@ LIBSRC = uart_init_.c uart_send_chr.c uart_send_str.c \ multest.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_tobcd__.c long_tobcd.c + long_tobcd__.c long_tobcd.c \ + bcd_tolong__.c bcd_tolong.c + LIBOBJ =$(patsubst %.c,%.rel, $(LIBSRC)) LIBNAME=mc8051fun.lib diff --git a/bcd_tolong.c b/bcd_tolong.c new file mode 100644 index 0000000..2fe6cfd --- /dev/null +++ b/bcd_tolong.c @@ -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; +} + + + diff --git a/bcd_tolong__.c b/bcd_tolong__.c new file mode 100644 index 0000000..f6a12b8 --- /dev/null +++ b/bcd_tolong__.c @@ -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; + +} + + + diff --git a/mc8051fun.h b/mc8051fun.h index ef94b70..bb35814 100644 --- a/mc8051fun.h +++ b/mc8051fun.h @@ -88,6 +88,7 @@ uint8_t getport(int n); 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