📄 lib_str.lst
字号:
173 *
174 * (a) Destination buffer size MUST be large enough to accomodate the entire source
175 * string size including the terminating NULL character.
176 *
177 * (2) String copy terminates when :
178 *
179 * (a) Destination/Source string pointer(s) are passed NULL pointers.
180 * (1) No string copy performed; NULL pointer returned.
181 *
182 * (b) Destination/Source string pointer(s) points to NULL.
183 * (1) String buffer(s) overlap with NULL address.
184 * (2) Source string copied into destination string buffer up to but NOT beyond or
185 * including the NULL address; destination string buffer properly terminated
186 * with NULL character.
187 *
188 * (c) Source string's terminating NULL character found.
189 * (1) Entire source string copied into destination string buffer.
190 *********************************************************************************************************
191 */
192
\ In segment CODE, align 4, keep-with-next
193 CPU_CHAR *Str_Copy (CPU_CHAR *pdest,
194 CPU_CHAR *psrc)
195 {
\ Str_Copy:
\ 00000000 0020B0E1 MOVS R2,R0
196 CPU_CHAR *pstr;
197 CPU_CHAR *pstr_next;
198
199 /* Rtn NULL if str ptr(s) NULL (see Note #2a). */
200 if (pdest == (CPU_CHAR *)0) {
\ 00000004 000052E3 CMP R2,#+0
\ 00000008 0100001A BNE ??Str_Copy_0
201 return ((CPU_CHAR *)0);
\ 0000000C 0000A0E3 MOV R0,#+0
\ 00000010 160000EA B ??Str_Copy_1
202 }
203 if (psrc == (CPU_CHAR *)0) {
\ ??Str_Copy_0:
\ 00000014 000051E3 CMP R1,#+0
\ 00000018 0100001A BNE ??Str_Copy_2
204 return ((CPU_CHAR *)0);
\ 0000001C 0000A0E3 MOV R0,#+0
\ 00000020 120000EA B ??Str_Copy_1
205 }
206
207
208 pstr = pdest;
\ ??Str_Copy_2:
\ 00000024 0230B0E1 MOVS R3,R2
209 pstr_next = pstr;
\ 00000028 03C0B0E1 MOVS R12,R3
210 pstr_next++;
\ 0000002C 01C09CE2 ADDS R12,R12,#+1
211 while (( pstr_next != (CPU_CHAR *)0) && /* Copy str until NULL ptr(s) (see Note #2b) ... */
212 ( psrc != (CPU_CHAR *)0) &&
213 (*psrc != (CPU_CHAR )0)) { /* ... or NULL char found (see Note #2c). */
\ ??Str_Copy_3:
\ 00000030 00005CE3 CMP R12,#+0
\ 00000034 0A00000A BEQ ??Str_Copy_4
\ 00000038 000051E3 CMP R1,#+0
\ 0000003C 0800000A BEQ ??Str_Copy_4
\ 00000040 0000D1E5 LDRB R0,[R1, #+0]
\ 00000044 000050E3 CMP R0,#+0
\ 00000048 0500000A BEQ ??Str_Copy_4
214 *pstr = *psrc;
\ 0000004C 0000D1E5 LDRB R0,[R1, #+0]
\ 00000050 0000C3E5 STRB R0,[R3, #+0]
215 pstr++;
\ 00000054 013093E2 ADDS R3,R3,#+1
216 pstr_next++;
\ 00000058 01C09CE2 ADDS R12,R12,#+1
217 psrc++;
\ 0000005C 011091E2 ADDS R1,R1,#+1
\ 00000060 F2FFFFEA B ??Str_Copy_3
218 }
219
220 *pstr = (CPU_CHAR)0; /* Append NULL char (see Note #2b2). */
\ ??Str_Copy_4:
\ 00000064 0000A0E3 MOV R0,#+0
\ 00000068 0000C3E5 STRB R0,[R3, #+0]
221
222
223 return (pdest);
\ 0000006C 0200B0E1 MOVS R0,R2
\ ??Str_Copy_1:
\ 00000070 0EF0A0E1 MOV PC,LR ;; return
224 }
225
226
227 /*$PAGE*/
228 /*
229 *********************************************************************************************************
230 * Str_Copy_N()
231 *
232 * Description : Copy source string to destination string buffer, up to a maximum number of characters.
233 *
234 * Argument(s) : pdest Pointer to destination string buffer to receive source string copy (see Note #1).
235 *
236 * psrc Pointer to source string to copy into destination string buffer.
237 *
238 * len_max Maximum number of characters to copy (see Note #2d).
239 *
240 * Return(s) : Pointer to destination string, if NO errors (see Note #2).
241 *
242 * Pointer to NULL, otherwise.
243 *
244 * Caller(s) : various.
245 *
246 * Note(s) : (1) Destination buffer size NOT validated; buffer overruns MUST be prevented by caller.
247 *
248 * (a) Destination buffer size MUST be large enough to accomodate the entire source
249 * string size including the terminating NULL character.
250 *
251 * (2) String copy terminates when :
252 *
253 * (a) Destination/Source string pointer(s) are passed NULL pointers.
254 * (1) No string copy performed; NULL pointer returned.
255 *
256 * (b) Destination/Source string pointer(s) points to NULL.
257 * (1) String buffer(s) overlap with NULL address.
258 * (2) Source string copied into destination string buffer up to but NOT beyond or
259 * including the NULL address; destination string buffer properly terminated
260 * with NULL character.
261 *
262 * (c) Source string's terminating NULL character found.
263 * (1) Entire source string copied into destination string buffer.
264 *
265 * (d) 'len_max' number of characters copied.
266 * (1) 'len_max' number of characters does NOT include the terminating NULL character.
267 *
268 * See also Note #1a.
269 *********************************************************************************************************
270 */
271
\ In segment CODE, align 4, keep-with-next
272 CPU_CHAR *Str_Copy_N (CPU_CHAR *pdest,
273 CPU_CHAR *psrc,
274 CPU_SIZE_T len_max)
275 {
\ Str_Copy_N:
\ 00000000 30002DE9 PUSH {R4,R5}
\ 00000004 0030B0E1 MOVS R3,R0
276 CPU_CHAR *pstr;
277 CPU_CHAR *pstr_next;
278 CPU_SIZE_T len_copy;
279
280 /* Rtn NULL if str ptr(s) NULL (see Note #2a). */
281 if (pdest == (CPU_CHAR *)0) {
\ 00000008 000053E3 CMP R3,#+0
\ 0000000C 0100001A BNE ??Str_Copy_N_0
282 return ((CPU_CHAR *)0);
\ 00000010 0000A0E3 MOV R0,#+0
\ 00000014 1F0000EA B ??Str_Copy_N_1
283 }
284 if (psrc == (CPU_CHAR *)0) {
\ ??Str_Copy_N_0:
\ 00000018 000051E3 CMP R1,#+0
\ 0000001C 0100001A BNE ??Str_Copy_N_2
285 return ((CPU_CHAR *)0);
\ 00000020 0000A0E3 MOV R0,#+0
\ 00000024 1B0000EA B ??Str_Copy_N_1
286 }
287
288 if (len_max == (CPU_SIZE_T)0) { /* Rtn NULL if copy len equals zero (see Note #2d). */
\ ??Str_Copy_N_2:
\ 00000028 000052E3 CMP R2,#+0
\ 0000002C 0100001A BNE ??Str_Copy_N_3
289 return ((CPU_CHAR *)0);
\ 00000030 0000A0E3 MOV R0,#+0
\ 00000034 170000EA B ??Str_Copy_N_1
290 }
291
292
293 pstr = pdest;
\ ??Str_Copy_N_3:
\ 00000038 03C0B0E1 MOVS R12,R3
294 pstr_next = pstr;
\ 0000003C 0C40B0E1 MOVS R4,R12
295 pstr_next++;
\ 00000040 014094E2 ADDS R4,R4,#+1
296 len_copy = 0;
\ 00000044 0000A0E3 MOV R0,#+0
\ 00000048 0050B0E1 MOVS R5,R0
297
298 while (( pstr_next != (CPU_CHAR *)0) && /* Copy str until NULL ptr(s) (see Note #2b) ... */
299 ( psrc != (CPU_CHAR *)0) &&
300 (*psrc != (CPU_CHAR )0) && /* ... or NULL char found (see Note #2c); ... */
301 ( len_copy < (CPU_SIZE_T)len_max)) { /* ... or max nbr chars copied (see Note #2d). */
\ ??Str_Copy_N_4:
\ 0000004C 000054E3 CMP R4,#+0
\ 00000050 0D00000A BEQ ??Str_Copy_N_5
\ 00000054 000051E3 CMP R1,#+0
\ 00000058 0B00000A BEQ ??Str_Copy_N_5
\ 0000005C 0000D1E5 LDRB R0,[R1, #+0]
\ 00000060 000050E3 CMP R0,#+0
\ 00000064 0800000A BEQ ??Str_Copy_N_5
\ 00000068 020055E1 CMP R5,R2
\ 0000006C 0600002A BCS ??Str_Copy_N_5
302 *pstr = *psrc;
\ 00000070 0000D1E5 LDRB R0,[R1, #+0]
\ 00000074 0000CCE5 STRB R0,[R12, #+0]
303 pstr++;
\ 00000078 01C09CE2 ADDS R12,R12,#+1
304 pstr_next++;
\ 0000007C 014094E2 ADDS R4,R4,#+1
305 psrc++;
\ 00000080 011091E2 ADDS R1,R1,#+1
306 len_copy++;
\ 00000084 015095E2 ADDS R5,R5,#+1
\ 00000088 EFFFFFEA B ??Str_Copy_N_4
307 }
308
309 *pstr = (CPU_CHAR)0; /* Append NULL char (see Note #2b2). */
\ ??Str_Copy_N_5:
\ 0000008C 0000A0E3 MOV R0,#+0
\ 00000090 0000CCE5 STRB R0,[R12, #+0]
310
311
312 return (pdest);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -