diff --git a/Makefile b/Makefile index 5829d0b..0fc454c 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,7 @@ LIBSRC = uart_init_.c uart_send_chr.c uart_send_str.c \ long_tobcd__.c long_tobcd.c \ bcd_tolong__.c bcd_tolong.c \ long_addbyte__.c long_addbyte.c \ + long_add__.c long_add.c \ long_1cpl__.c long_invert__.c long_invert.c diff --git a/long_add.c b/long_add.c index b80ebd6..739c157 100644 --- a/long_add.c +++ b/long_add.c @@ -9,23 +9,17 @@ uint8_t long_add(__idata uint8_t *v1, __idata uint8_t *v2,uint8_t len) __reentra __asm mov a,_bp add a,#0xfd - mov sp,a - pop ar1 - pop ar7 - mov ar0,dpl - clr c -001$: - mov a,@r0 - addc a,@r1 - mov @r0,a - inc r0 - inc r1 - djnz r7,001$ + mov r0,a + mov a,@r0 ; *v2 + mov r1,a + mov a,@r0 ; len + mov r7,a + mov r0,dpl + lcall long_invert mov dpl,#0x00 jnc $002 inc dpl $002: - mov sp,_bp __endasm; } diff --git a/long_add__.c b/long_add__.c new file mode 100644 index 0000000..3a64965 --- /dev/null +++ b/long_add__.c @@ -0,0 +1,25 @@ +/* + * @r0 = @r0+@r1 + * r7=len + */ + +static void long_add__() __naked +{ + __asm +long_add: + clr c +long_addc: +001$: + mov a,@r0 + addc a,@r1 + mov @r0,a + inc r0 + inc r1 + djnz r7,001$ + ret + + __endasm; +} + + + diff --git a/mc8051fun.h b/mc8051fun.h index 71ac0e2..a3e8767 100644 --- a/mc8051fun.h +++ b/mc8051fun.h @@ -90,6 +90,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 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; #endif