📄 lib_str.lst
字号:
460 if (pstr_cat == (CPU_CHAR *)0) {
\ ??Str_Cat_N_0:
\ 0000000A 0029 CMP R1,#+0
\ 0000000C FBD0 BEQ.N ??Str_Cat_N_1
461 return ((CPU_CHAR *)0);
462 }
463
464 if (len_max == (CPU_SIZE_T)0) { /* Rtn NULL if cat len equals zero (see Note #2e). */
\ 0000000E 002A CMP R2,#+0
\ 00000010 F9D0 BEQ.N ??Str_Cat_N_1
465 return ((CPU_CHAR *)0);
466 }
467
468
469 pstr = pdest;
\ 00000012 0300 MOVS R3,R0
\ 00000014 00E0 B.N ??Str_Cat_N_2
470 while (( pstr != (CPU_CHAR *)0) && /* Adv to end of cur dest str until NULL ptr ... */
471 (*pstr != (CPU_CHAR )0)) { /* ... or NULL char found.. */
472 pstr++;
\ ??Str_Cat_N_3:
\ 00000016 5B1C ADDS R3,R3,#+1
473 }
\ ??Str_Cat_N_2:
\ 00000018 002B CMP R3,#+0
\ 0000001A 02D0 BEQ.N ??Str_Cat_N_4
\ 0000001C 1C78 LDRB R4,[R3, #+0]
\ 0000001E 002C CMP R4,#+0
\ 00000020 F9D1 BNE.N ??Str_Cat_N_3
474 if (pstr == (CPU_CHAR *)0) { /* If NULL str overrun, rtn NULL (see Note #2b). */
\ ??Str_Cat_N_4:
\ 00000022 002B CMP R3,#+0
\ 00000024 EFD0 BEQ.N ??Str_Cat_N_1
475 return ((CPU_CHAR *)0);
476 }
477
478 pstr_next = pstr;
479 pstr_next++;
\ 00000026 1D00 MOVS R5,R3
\ 00000028 6D1C ADDS R5,R5,#+1
480 len_cat = 0;
\ 0000002A 0024 MOVS R4,#+0
\ 0000002C 2600 MOVS R6,R4
\ 0000002E 04E0 B.N ??Str_Cat_N_5
481
482 while (( pstr_next != (CPU_CHAR *)0) && /* Cat str until NULL ptr(s) (see Note #2c) ... */
483 ( pstr_cat != (CPU_CHAR *)0) &&
484 (*pstr_cat != (CPU_CHAR )0) && /* ... or NULL char found (see Note #2d); ... */
485 ( len_cat < (CPU_SIZE_T)len_max)) { /* ... or max nbr chars cat'd (see Note #2d). */
486 *pstr = *pstr_cat;
\ ??Str_Cat_N_6:
\ 00000030 1F70 STRB R7,[R3, #+0]
487 pstr++;
\ 00000032 5B1C ADDS R3,R3,#+1
488 pstr_next++;
\ 00000034 6D1C ADDS R5,R5,#+1
489 pstr_cat++;
\ 00000036 491C ADDS R1,R1,#+1
490 len_cat++;
\ 00000038 761C ADDS R6,R6,#+1
491 }
\ ??Str_Cat_N_5:
\ 0000003A 002D CMP R5,#+0
\ 0000003C 06D0 BEQ.N ??Str_Cat_N_7
\ 0000003E 0029 CMP R1,#+0
\ 00000040 04D0 BEQ.N ??Str_Cat_N_7
\ 00000042 0F78 LDRB R7,[R1, #+0]
\ 00000044 002F CMP R7,#+0
\ 00000046 01D0 BEQ.N ??Str_Cat_N_7
\ 00000048 9642 CMP R6,R2
\ 0000004A F1D3 BCC.N ??Str_Cat_N_6
492
493 *pstr = (CPU_CHAR)0; /* Append NULL char (see Note #2c2). */
\ ??Str_Cat_N_7:
\ 0000004C 1C70 STRB R4,[R3, #+0]
494
495
496 return (pdest);
\ 0000004E F0BD POP {R4-R7,PC} ;; return
497 }
498
499
500 /*$PAGE*/
501 /*
502 *********************************************************************************************************
503 * Str_Cmp()
504 *
505 * Description : Determine if two strings are identical.
506 *
507 * Argument(s) : p1_str Pointer to first string (see Note #1).
508 *
509 * p2_str Pointer to second string (see Note #1).
510 *
511 * Return(s) : 0, if strings are identical (see Notes #2a, #2e, & #2f).
512 *
513 * Negative value, if 'p1_str' is less than 'p2_str' (see Notes #2b, #2g, & #2d).
514 *
515 * Positive value, if 'p1_str' is greater than 'p2_str' (see Notes #2c, #2h, & #2d).
516 *
517 * Caller(s) : Application.
518 *
519 * Note(s) : (1) String buffers NOT modified.
520 *
521 * (2) String comparison terminates when :
522 *
523 * (a) BOTH string pointer(s) are passed NULL pointers.
524 * (1) NULL strings identical; return 0.
525 *
526 * (b) 'p1_str' passed a NULL pointer.
527 * (1) Return negative value of character pointed to by 'p2_str'.
528 *
529 * (c) 'p2_str' passed a NULL pointer.
530 * (1) Return positive value of character pointed to by 'p1_str'.
531 *
532 * (d) Non-matching characters found.
533 * (1) Return signed-integer difference of the character pointed to by 'p2_str'
534 * from the character pointed to by 'p1_str'.
535 *
536 * (e) Terminating NULL character found in both strings.
537 * (1) Strings identical; return 0.
538 * (2) Only one NULL character test required in conditional since previous condition
539 * tested character equality.
540 *
541 * (f) BOTH strings point to NULL.
542 * (1) Strings overlap with NULL address.
543 * (2) Strings identical up to but NOT beyond or including the NULL address; return 0.
544 *
545 * (g) 'p1_str_next' points to NULL.
546 * (1) 'p1_str' overlaps with NULL address.
547 * (2) Strings compared up to but NOT beyond or including the NULL address.
548 * (3) Return negative value of character pointed to by 'p2_str_next'.
549 *
550 * (h) 'p2_str_next' points to NULL.
551 * (1) 'p2_str' overlaps with NULL address.
552 * (2) Strings compared up to but NOT beyond or including the NULL address.
553 * (3) Return positive value of character pointed to by 'p1_str_next'.
554 *
555 * (3) Since 16-bit signed arithmetic is performed to calculate a non-identical comparison
556 * return value, 'CPU_CHAR' native data type size MUST be 8-bit.
557 *********************************************************************************************************
558 */
559 /*$PAGE*/
\ In segment CODE, align 4, keep-with-next
560 CPU_INT16S Str_Cmp (CPU_CHAR *p1_str,
561 CPU_CHAR *p2_str)
562 {
\ Str_Cmp:
\ 00000000 30B5 PUSH {R4,R5,LR}
\ 00000002 0200 MOVS R2,R0
563 CPU_CHAR *p1_str_next;
564 CPU_CHAR *p2_str_next;
565 CPU_INT16S cmp_val;
566
567
568 if (p1_str == (CPU_CHAR *)0) {
\ 00000004 07D1 BNE.N ??Str_Cmp_0
569 if (p2_str == (CPU_CHAR *)0) {
\ 00000006 0029 CMP R1,#+0
\ 00000008 01D1 BNE.N ??Str_Cmp_1
570 return ((CPU_INT16S)0); /* If BOTH str ptrs NULL, rtn 0 (see Note #2a). */
\ 0000000A 0020 MOVS R0,#+0
\ 0000000C 30BD POP {R4,R5,PC}
571 }
572 cmp_val = (CPU_INT16S)0 - (CPU_INT16S)(*p2_str);
573 return (cmp_val); /* If p1_str NULL, rtn neg p2_str val (see Note #2b). */
\ ??Str_Cmp_1:
\ 0000000E 0978 LDRB R1,[R1, #+0]
\ 00000010 4842 RSBS R0,R1,#+0
\ 00000012 00B2 SXTH R0,R0
\ 00000014 30BD POP {R4,R5,PC}
574 }
575 if (p2_str == (CPU_CHAR *)0) {
\ ??Str_Cmp_0:
\ 00000016 0029 CMP R1,#+0
\ 00000018 01D1 BNE.N ??Str_Cmp_2
576 cmp_val = (CPU_INT16S)(*p1_str);
577 return (cmp_val); /* If p2_str NULL, rtn pos p1_str val (see Note #2c). */
\ 0000001A 1078 LDRB R0,[R2, #+0]
\ 0000001C 30BD POP {R4,R5,PC}
578 }
579
580
581 p1_str_next = p1_str;
582 p2_str_next = p2_str;
583 p1_str_next++;
\ ??Str_Cmp_2:
\ 0000001E 1300 MOVS R3,R2
\ 00000020 5B1C ADDS R3,R3,#+1
584 p2_str_next++;
\ 00000022 0C00 MOVS R4,R1
\ 00000024 641C ADDS R4,R4,#+1
\ 00000026 03E0 B.N ??Str_Cmp_3
585 while ((*p1_str == *p2_str) && /* Cmp strs until non-matching char (see Note #2d) .. */
586 (*p1_str != (CPU_CHAR )0) && /* .. or NULL char(s) (see Note #2e) .. */
587 ( p1_str_next != (CPU_CHAR *)0) && /* .. or NULL ptr(s) found (see Notes #2f, #2g, & #2h). */
588 ( p2_str_next != (CPU_CHAR *)0)) {
589 p1_str_next++;
\ ??Str_Cmp_4:
\ 00000028 5B1C ADDS R3,R3,#+1
590 p2_str_next++;
\ 0000002A 641C ADDS R4,R4,#+1
591 p1_str++;
\ 0000002C 521C ADDS R2,R2,#+1
592 p2_str++;
\ 0000002E 491C ADDS R1,R1,#+1
593 }
\ ??Str_Cmp_3:
\ 00000030 1078 LDRB R0,[R2, #+0]
\ 00000032 0D78 LDRB R5,[R1, #+0]
\ 00000034 A842 CMP R0,R5
\ 00000036 05D1 BNE.N ??Str_Cmp_5
\ 00000038 0028 CMP R0,#+0
\ 0000003A 03D0 BEQ.N ??Str_Cmp_5
\ 0000003C 002B CMP R3,#+0
\ 0000003E 01D0 BEQ.N ??Str_Cmp_5
\ 00000040 002C CMP R4,#+0
\ 00000042 F1D1 BNE.N ??Str_Cmp_4
594
595
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -