From 6c2e631e56ec284148c6f6d82d6132dfffcffd14 Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@mail.ru> Date: Wed, 3 Jul 2024 06:54:47 +0200 Subject: [PATCH] New long_* functions --- Makefile | 4 +++- long_1cpl__.c | 22 ++++++++++++++++++++++ long_addbyte.c | 26 ++++++++++++++++++++++++++ long_addbyte__.c | 23 +++++++++++++++++++++++ long_invert.c | 21 +++++++++++++++++++++ long_invert__.c | 22 ++++++++++++++++++++++ mc8051fun.h | 1 + 7 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 long_1cpl__.c create mode 100644 long_addbyte.c create mode 100644 long_addbyte__.c create mode 100644 long_invert.c create mode 100644 long_invert__.c diff --git a/Makefile b/Makefile index 8d85778..5829d0b 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,9 @@ LIBSRC = uart_init_.c uart_send_chr.c uart_send_str.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 \ - bcd_tolong__.c bcd_tolong.c + bcd_tolong__.c bcd_tolong.c \ + long_addbyte__.c long_addbyte.c \ + long_1cpl__.c long_invert__.c long_invert.c LIBOBJ =$(patsubst %.c,%.rel, $(LIBSRC)) diff --git a/long_1cpl__.c b/long_1cpl__.c new file mode 100644 index 0000000..fc376db --- /dev/null +++ b/long_1cpl__.c @@ -0,0 +1,22 @@ + +#include "mc8051fun.h" + +static void long_1cpl__() __naked +{ + __asm + .globl long_1cpl + +long_1cpl: + + clr c +001$: + mov a,#0xff + subb a,@r0 + mov @r0,a + inc r0 + djnz r7,001$ + ret + + __endasm; +} + diff --git a/long_addbyte.c b/long_addbyte.c new file mode 100644 index 0000000..eca3797 --- /dev/null +++ b/long_addbyte.c @@ -0,0 +1,26 @@ +#include "mc8051fun.h" + +/** + * C wrapper for long_addbyte + */ + +static void long_addbyte(__idata uint8_t * val, uint8_t len, uint8_t b) __reentrant +{ + (void)val; + (void)b; + + __asm + mov a,_bp + add a,#0xfd + mov r0,a + mov a,@r0 ; len + mov r7,a + dec r0 + mov a,@r0 ; b + mov r0,dpl + lcall long_addbyte + + __endasm; + +} + diff --git a/long_addbyte__.c b/long_addbyte__.c new file mode 100644 index 0000000..6868fbc --- /dev/null +++ b/long_addbyte__.c @@ -0,0 +1,23 @@ +/* + * a = byte to add + * @r0 = long val + * r7 = length + * + */ +static void long_addbyte__() __naked +{ + __asm + .globl long_addbyte +long_addbyte: + clr c + ajmp 002$ +001$: + mov a,#0x00 +002$: + addc a,@r0 + mov @r0,a + inc r0 + djnz r7,001$ + ret + __endasm; +} diff --git a/long_invert.c b/long_invert.c new file mode 100644 index 0000000..acc76d7 --- /dev/null +++ b/long_invert.c @@ -0,0 +1,21 @@ +#include "mc8051fun.h" + +void long_invert(__idata uint8_t *val, uint8_t len) __reentrant +{ + (void)val; + (void)len; + + __asm + + mov a,_bp + add a,#0xfd + mov r0,a + mov a,@r0 ; len + mov r7,a + mov r0,dpl + lcall long_invert + __endasm; + + +} + diff --git a/long_invert__.c b/long_invert__.c new file mode 100644 index 0000000..f7f721e --- /dev/null +++ b/long_invert__.c @@ -0,0 +1,22 @@ +#include "mc8051fun.h" + +static void long_invert__() __naked +{ + __asm + + .globl long_invert +long_invert: + push AR0 + push AR7 + + lcall long_1cpl + + pop AR7 + pop AR0 + + mov a,#0x01 + lcall long_addbyte + ret + __endasm; + +} diff --git a/mc8051fun.h b/mc8051fun.h index bb35814..71ac0e2 100644 --- a/mc8051fun.h +++ b/mc8051fun.h @@ -89,6 +89,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; +void long_invert(__idata uint8_t *val, uint8_t len) __reentrant; #endif