📄 lib_str.lst
字号:
150
151 return (len);
\ ??Str_Len_2:
\ 00000024 0100B0E1 MOVS R0,R1
\ 00000028 0EF0A0E1 MOV PC,LR ;; return
152 }
153
154
155 /*$PAGE*/
156 /*
157 *********************************************************************************************************
158 * Str_Copy()
159 *
160 * Description : Copy source string to destination string buffer.
161 *
162 * Argument(s) : pdest Pointer to destination string buffer to receive source string copy (see Note #1).
163 *
164 * psrc Pointer to source string to copy into destination string buffer.
165 *
166 * Return(s) : Pointer to destination string, if NO errors (see Note #2).
167 *
168 * Pointer to NULL, otherwise.
169 *
170 * Caller(s) : various.
171 *
172 * Note(s) : (1) Destination buffer size NOT validated; buffer overruns MUST be prevented by caller.
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 {
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) {
\ Str_Copy:
\ 00000000 000050E3 CMP R0,#+0
\ 00000004 0100001A BNE ??Str_Copy_0
201 return ((CPU_CHAR *)0);
\ 00000008 0000A0E3 MOV R0,#+0
\ 0000000C 150000EA B ??Str_Copy_1
202 }
203 if (psrc == (CPU_CHAR *)0) {
\ ??Str_Copy_0:
\ 00000010 000051E3 CMP R1,#+0
\ 00000014 0100001A BNE ??Str_Copy_2
204 return ((CPU_CHAR *)0);
\ 00000018 0000A0E3 MOV R0,#+0
\ 0000001C 110000EA B ??Str_Copy_1
205 }
206
207
208 pstr = pdest;
\ ??Str_Copy_2:
\ 00000020 0020B0E1 MOVS R2,R0
209 pstr_next = pstr;
\ 00000024 0230B0E1 MOVS R3,R2
210 pstr_next++;
\ 00000028 013093E2 ADDS R3,R3,#+1
\ 0000002C 040000EA B ??Str_Copy_3
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). */
214 *pstr = *psrc;
\ ??Str_Copy_4:
\ 00000030 00C0D1E5 LDRB R12,[R1, #+0]
\ 00000034 00C0C2E5 STRB R12,[R2, #+0]
215 pstr++;
\ 00000038 012092E2 ADDS R2,R2,#+1
216 pstr_next++;
\ 0000003C 013093E2 ADDS R3,R3,#+1
217 psrc++;
\ 00000040 011091E2 ADDS R1,R1,#+1
218 }
\ ??Str_Copy_3:
\ 00000044 000053E3 CMP R3,#+0
\ 00000048 0400000A BEQ ??Str_Copy_5
\ 0000004C 000051E3 CMP R1,#+0
\ 00000050 0200000A BEQ ??Str_Copy_5
\ 00000054 00C0D1E5 LDRB R12,[R1, #+0]
\ 00000058 00005CE3 CMP R12,#+0
\ 0000005C F3FFFF1A BNE ??Str_Copy_4
219
220 *pstr = (CPU_CHAR)0; /* Append NULL char (see Note #2b2). */
\ ??Str_Copy_5:
\ 00000060 0010A0E3 MOV R1,#+0
\ 00000064 0010C2E5 STRB R1,[R2, #+0]
221
222
223 return (pdest);
\ ??Str_Copy_1:
\ 00000068 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}
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) {
\ 00000004 000050E3 CMP R0,#+0
\ 00000008 0100001A BNE ??Str_Copy_N_0
282 return ((CPU_CHAR *)0);
\ 0000000C 0000A0E3 MOV R0,#+0
\ 00000010 1D0000EA B ??Str_Copy_N_1
283 }
284 if (psrc == (CPU_CHAR *)0) {
\ ??Str_Copy_N_0:
\ 00000014 000051E3 CMP R1,#+0
\ 00000018 0100001A BNE ??Str_Copy_N_2
285 return ((CPU_CHAR *)0);
\ 0000001C 0000A0E3 MOV R0,#+0
\ 00000020 190000EA 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:
\ 00000024 000052E3 CMP R2,#+0
\ 00000028 0100001A BNE ??Str_Copy_N_3
289 return ((CPU_CHAR *)0);
\ 0000002C 0000A0E3 MOV R0,#+0
\ 00000030 150000EA B ??Str_Copy_N_1
290 }
291
292
293 pstr = pdest;
\ ??Str_Copy_N_3:
\ 00000034 0030B0E1 MOVS R3,R0
294 pstr_next = pstr;
\ 00000038 03C0B0E1 MOVS R12,R3
295 pstr_next++;
\ 0000003C 01C09CE2 ADDS R12,R12,#+1
296 len_copy = 0;
\ 00000040 0040A0E3 MOV R4,#+0
\ 00000044 050000EA B ??Str_Copy_N_4
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). */
302 *pstr = *psrc;
\ ??Str_Copy_N_5:
\ 00000048 0050D1E5 LDRB R5,[R1, #+0]
\ 0000004C 0050C3E5 STRB R5,[R3, #+0]
303 pstr++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -