From: frief Date: Sun, 22 Apr 2007 22:05:39 +0000 (+0000) Subject: * device/lib/_memset.c: assembler version for mcs51 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=9db17ae9b4c57aabf9df08d5aee7654592500296;hp=62ef71465876383f7217fcfa4675e552e9d9fbe4;p=fw%2Fsdcc * device/lib/_memset.c: assembler version for mcs51 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4766 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 67eb9964..086630bf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2007-04-23 Frieder Ferlemann + + * device/lib/_memset.c: assembler version for mcs51 + 2007-04-22 Borut Razem * support/scripts/listerr.c: program to create the list of errors and diff --git a/device/lib/_memset.c b/device/lib/_memset.c index 9bd603ed..5b9202e7 100644 --- a/device/lib/_memset.c +++ b/device/lib/_memset.c @@ -2,6 +2,7 @@ _memset.c - part of string library functions Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999) + mcs51 assembler by Frieder Ferlemann (2007) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the @@ -23,18 +24,151 @@ -------------------------------------------------------------------------*/ #include "string.h" -void * memset ( - void * buf, - unsigned char ch , - size_t count) -{ - register unsigned char * ret = buf; +#if defined (_SDCC_NO_ASM_LIB_FUNCS) || !defined (SDCC_mcs51) || \ + (!defined (SDCC_MODEL_SMALL) && !defined (SDCC_MODEL_LARGE)) || \ + (defined (SDCC_STACK_AUTO) || defined (SDCC_PARMS_IN_BANK1) ) - while (count--) { - *(unsigned char *) ret = ch; - ret = ((unsigned char *) ret) + 1; - } + void * memset ( + void * buf, + unsigned char ch , + size_t count) + { + register unsigned char * ret = buf; - return buf ; -} + while (count--) { + *(unsigned char *) ret = ch; + ret = ((unsigned char *) ret) + 1; + } + return buf ; + } + +#else + + /* assembler implementation for mcs51 */ + static void dummy(void) __naked + { + __asm + + /* assigning function parameters to registers. + SDCC_PARMS_IN_BANK1 or SDCC_STACK_AUTO not yet implemented. */ + #if defined (SDCC_MODEL_SMALL) + + #if defined(SDCC_NOOVERLAY) + .area DSEG (DATA) + #else + .area OSEG (OVR,DATA) + #endif + _memset_PARM_2:: + .ds 1 + _memset_PARM_3:: + .ds 2 + + .area CSEG (CODE) + + _memset:: + + ; Assign buf (b holds memspace, no need to touch) + mov r4,dpl + mov r5,dph + ; + ; Assign count + mov r6,_memset_PARM_3 + mov r7,(_memset_PARM_3 + 1) + ; + ; if (!count) return buf; + ; check for count != 0 intermangled with gymnastic + ; preparing djnz instructions + cjne r6,#0x00,COUNT_LSB_NOT_ZERO + mov a,r7 + jz MEMSET_END + dec r7 + COUNT_LSB_NOT_ZERO: + inc r7 + ; + ; This was 8 byte overhead for preparing + ; the count argument for an integer loop with two + ; djnz instructions - it might make sense to + ; let SDCC automatically generate this when + ; it encounters a loop like: + ; for(i=0;i