1 /*-------------------------------------------------------------------------
2 _memset.c - part of string library functions
4 Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net
5 Copyright (C) 2020, Sergey Belyashov sergey.belyashov@gmail.com
6 Copyright (C) 2022, Sebastian 'basxto' Riedel
7 mcs51 assembler by Frieder Ferlemann (2007)
9 This library is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published by the
11 Free Software Foundation; either version 2, or (at your option) any
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this library; see the file COPYING. If not, write to the
21 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
24 As a special exception, if you link this library with other files,
25 some of which are compiled with SDCC, to produce an executable,
26 this library does not by itself cause the resulting executable to
27 be covered by the GNU General Public License. This exception does
28 not however invalidate any other reasons why the executable file
29 might be covered by the GNU General Public License.
30 -------------------------------------------------------------------------*/
35 #undef memset /* Avoid conflict with builtin memset() in Z80 and some related ports */
37 #if defined (_SDCC_NO_ASM_LIB_FUNCS) || !defined (__SDCC_mcs51) || \
38 (!defined (__SDCC_MODEL_SMALL) && !defined (__SDCC_MODEL_LARGE)) || \
39 (defined (__SDCC_STACK_AUTO) || defined (__SDCC_PARMS_IN_BANK1) )
41 #ifdef __SDCC_BROKEN_STRING_FUNCTIONS
42 void *memset (void *s
, unsigned char c
, size_t n
)
44 void *memset (void *s
, int c
, size_t n
)
47 #if !defined (_SDCC_NO_ASM_LIB_FUNCS) && (\
48 defined (__SDCC_z80) ||\
49 defined (__SDCC_z180) ||\
50 defined (__SDCC_z80n) ||\
51 defined (__SDCC_r800))
52 #ifdef __SDCC_BROKEN_STRING_FUNCTIONS
53 #error Unimplemented broken string function
81 #elif !defined (_SDCC_NO_ASM_LIB_FUNCS) && defined(__SDCC_sm83)
85 (void)c
;//bc or for broken string function in a
86 (void)n
;//stack+2, stack+3
88 ; Algorithm is Duff`s device
91 #ifdef __SDCC_BROKEN_STRING_FUNCTIONS
115 ;shift second LSB to carry
144 register size_t sz
= n
;
147 register char *dst
= s
;
148 register char data
= (char)c
;
158 /* assembler implementation for mcs51 */
159 static void dummy(void) __naked
163 /* assigning function parameters to registers.
164 __SDCC_PARMS_IN_BANK1 or __SDCC_STACK_AUTO not yet implemented. */
165 #if defined (__SDCC_MODEL_SMALL)
167 #if defined(__SDCC_NOOVERLAY)
170 .area
OSEG (OVR
,DATA
)
181 ; Assign
buf (b holds memspace
, no need to touch
)
186 mov r6
,_memset_PARM_3
187 mov r7
,(_memset_PARM_3
+ 1)
189 ; if (!count
) return buf
;
190 ; check
for count
!= 0 intermangled with gymnastic
191 ; preparing djnz instructions
192 cjne r6
,#0x00,COUNT_LSB_NOT_ZERO
199 ; This was
8 byte overhead
for preparing
200 ; the count argument
for an integer loop with two
201 ; djnz instructions
- it might make sense to
202 ; let SDCC automatically generate
this when
203 ; it encounters a loop like
:
204 ; for(i
=0;i
<j
;i
++){...}
205 ; (at least
for option
--opt
-code
-speed
)
224 ; Assign
buf (b holds memspace
, no need to touch
)
229 mov dptr
,#_memset_PARM_3
236 ; if (!count
) return buf
;
237 ; check
for count
!= 0 intermangled with gymnastic
238 ; preparing djnz instructions
239 cjne r6
,#0x00,COUNT_LSB_NOT_ZERO
247 mov dptr
,#_memset_PARM_2
249 ; acc is precious now
257 /* now independent of the parameter passing everything
258 should be in registers by now and the loop may start */
268 ; _memset
.c
} while(--count
) ;
274 ; _memset
.c
return buf
;