📄 lib_str.lst
字号:
596 if (*p1_str != *p2_str) { /* If strs NOT identical, ... */
\ ??Str_Cmp_5:
\ 00000044 A842 CMP R0,R5
\ 00000046 02D0 BEQ.N ??Str_Cmp_6
597 cmp_val = (CPU_INT16S)(*p1_str) - (CPU_INT16S)(*p2_str); /* ... calc & rtn char diff (see Note #2d1). */
\ 00000048 2946 MOV R1,R5
\ 0000004A 401A SUBS R0,R0,R1
\ 0000004C 0BE0 B.N ??Str_Cmp_7
598
599 } else if (*p1_str == (CPU_CHAR)0) { /* If NULL char(s) found, ... */
\ ??Str_Cmp_6:
\ 0000004E 0020 MOVS R0,#+0
\ 00000050 1178 LDRB R1,[R2, #+0]
\ 00000052 0029 CMP R1,#+0
\ 00000054 07D0 BEQ.N ??Str_Cmp_7
600 cmp_val = 0; /* ... strs identical; rtn 0 (see Note #2e). */
601
602 } else {
603 if (p1_str_next == (CPU_CHAR *)0) {
\ 00000056 002B CMP R3,#+0
\ 00000058 04D1 BNE.N ??Str_Cmp_8
604 if (p2_str_next == (CPU_CHAR *)0) { /* If BOTH next str ptrs NULL, ... */
\ 0000005A 002C CMP R4,#+0
\ 0000005C 03D0 BEQ.N ??Str_Cmp_7
605 cmp_val = (CPU_INT16S)0; /* ... rtn 0 (see Note #2f). */
606 } else { /* If p1_str_next NULL, ... */
607 cmp_val = (CPU_INT16S)0 - (CPU_INT16S)(*p2_str_next); /* ... rtn neg p2_str_next val (see Note #2g). */
\ 0000005E 2178 LDRB R1,[R4, #+0]
\ 00000060 4842 RSBS R0,R1,#+0
\ 00000062 00E0 B.N ??Str_Cmp_7
608 }
609 } else { /* If p2_str_next NULL, ... */
610 cmp_val = (CPU_INT16S)(*p1_str_next); /* ... rtn pos p1_str_next val (see Note #2h). */
\ ??Str_Cmp_8:
\ 00000064 1878 LDRB R0,[R3, #+0]
611 }
612 }
613
614
615 return (cmp_val);
\ ??Str_Cmp_7:
\ 00000066 00B2 SXTH R0,R0
\ 00000068 30BD POP {R4,R5,PC} ;; return
616 }
617
618
619 /*$PAGE*/
620 /*
621 *********************************************************************************************************
622 * Str_Cmp_N()
623 *
624 * Description : Determine if two strings are identical for up to a maximum number of characters.
625 *
626 * Argument(s) : p1_str Pointer to first string (see Note #1).
627 *
628 * p2_str Pointer to second string (see Note #1).
629 *
630 * len_max Maximum number of characters to compare (see Notes #2i & #2j).
631 *
632 * Return(s) : 0, if strings are identical (see Notes #2a, #2e, #2f, #2i, & #2j).
633 *
634 * Negative value, if 'p1_str' is less than 'p2_str' (see Notes #2b, #2g, & #2d).
635 *
636 * Positive value, if 'p1_str' is greater than 'p2_str' (see Notes #2c, #2h, & #2d).
637 *
638 * Caller(s) : Application.
639 *
640 * Note(s) : (1) String buffers NOT modified.
641 *
642 * (2) String comparison terminates when :
643 *
644 * (a) BOTH string pointer(s) are passed NULL pointers.
645 * (1) NULL strings identical; return 0.
646 *
647 * (b) 'p1_str' passed a NULL pointer.
648 * (1) Return negative value of character pointed to by 'p2_str'.
649 *
650 * (c) 'p2_str' passed a NULL pointer.
651 * (1) Return positive value of character pointed to by 'p1_str'.
652 *
653 * (d) Non-matching characters found.
654 * (1) Return signed-integer difference of the character pointed to by 'p2_str'
655 * from the character pointed to by 'p1_str'.
656 *
657 * (e) Terminating NULL character found in both strings.
658 * (1) Strings identical; return 0.
659 * (2) Only one NULL character test required in conditional since previous condition
660 * tested character equality.
661 *
662 * (f) BOTH strings point to NULL.
663 * (1) Strings overlap with NULL address.
664 * (2) Strings identical up to but NOT beyond or including the NULL address; return 0.
665 *
666 * (g) 'p1_str_next' points to NULL.
667 * (1) 'p1_str' overlaps with NULL address.
668 * (2) Strings compared up to but NOT beyond or including the NULL address.
669 * (3) Return negative value of character pointed to by 'p2_str_next'.
670 *
671 * (h) 'p2_str_next' points to NULL.
672 * (1) 'p2_str' overlaps with NULL address.
673 * (2) Strings compared up to but NOT beyond or including the NULL address.
674 * (3) Return positive value of character pointed to by 'p1_str_next'.
675 *
676 * (i) 'len_max' passed a zero length.
677 * (1) Zero-length strings identical; return 0.
678 *
679 * (j) First 'len_max' number of characters identical.
680 * (1) Strings identical; return 0.
681 *
682 * (3) Since 16-bit signed arithmetic is performed to calculate a non-identical comparison
683 * return value, 'CPU_CHAR' native data type size MUST be 8-bit.
684 *********************************************************************************************************
685 */
686 /*$PAGE*/
\ In segment CODE, align 4, keep-with-next
687 CPU_INT16S Str_Cmp_N (CPU_CHAR *p1_str,
688 CPU_CHAR *p2_str,
689 CPU_SIZE_T len_max)
690 {
\ Str_Cmp_N:
\ 00000000 2DE9F041 PUSH {R4-R8,LR}
\ 00000004 9046 MOV R8,R2
\ 00000006 0200 MOVS R2,R0
691 CPU_CHAR *p1_str_next;
692 CPU_CHAR *p2_str_next;
693 CPU_INT16S cmp_val;
694 CPU_SIZE_T cmp_len;
695
696
697 if (len_max == 0) { /* If cmp len equals zero, rtn 0 (see Note #2i). */
\ 00000008 4046 MOV R0,R8
\ 0000000A 0028 CMP R0,#+0
\ 0000000C 3BD0 BEQ.N ??Str_Cmp_N_0
698 return ((CPU_INT16S)0);
699 }
700
701 if (p1_str == (CPU_CHAR *)0) {
\ 0000000E 002A CMP R2,#+0
\ 00000010 07D1 BNE.N ??Str_Cmp_N_1
702 if (p2_str == (CPU_CHAR *)0) {
\ 00000012 0029 CMP R1,#+0
\ 00000014 01D1 BNE.N ??Str_Cmp_N_2
703 return ((CPU_INT16S)0); /* If BOTH str ptrs NULL, rtn 0 (see Note #2a). */
\ 00000016 0020 MOVS R0,#+0
\ 00000018 35E0 B.N ??Str_Cmp_N_0
704 }
705 cmp_val = (CPU_INT16S)0 - (CPU_INT16S)(*p2_str);
706 return (cmp_val); /* If p1_str NULL, rtn neg p2_str val (see Note #2b). */
\ ??Str_Cmp_N_2:
\ 0000001A 0978 LDRB R1,[R1, #+0]
\ 0000001C 4842 RSBS R0,R1,#+0
\ 0000001E 00B2 SXTH R0,R0
\ 00000020 31E0 B.N ??Str_Cmp_N_0
707 }
708 if (p2_str == (CPU_CHAR *)0) {
\ ??Str_Cmp_N_1:
\ 00000022 0029 CMP R1,#+0
\ 00000024 01D1 BNE.N ??Str_Cmp_N_3
709 cmp_val = (CPU_INT16S)(*p1_str);
710 return (cmp_val); /* If p2_str NULL, rtn pos p1_str val (see Note #2c). */
\ 00000026 1078 LDRB R0,[R2, #+0]
\ 00000028 2DE0 B.N ??Str_Cmp_N_0
711 }
712
713
714 p1_str_next = p1_str;
715 p2_str_next = p2_str;
716 p1_str_next++;
\ ??Str_Cmp_N_3:
\ 0000002A 1300 MOVS R3,R2
\ 0000002C 5B1C ADDS R3,R3,#+1
717 p2_str_next++;
\ 0000002E 0C00 MOVS R4,R1
\ 00000030 641C ADDS R4,R4,#+1
718 cmp_len = 0;
\ 00000032 0020 MOVS R0,#+0
\ 00000034 0500 MOVS R5,R0
\ 00000036 04E0 B.N ??Str_Cmp_N_4
719 while ((*p1_str == *p2_str) && /* Cmp strs until non-matching char (see Note #2d) .. */
720 (*p1_str != (CPU_CHAR )0) && /* .. or NULL char(s) (see Note #2e) .. */
721 ( p1_str_next != (CPU_CHAR *)0) && /* .. or NULL ptr(s) found (see Notes #2f, #2g, & #2h); */
722 ( p2_str_next != (CPU_CHAR *)0) &&
723 ( cmp_len < (CPU_SIZE_T)len_max)) { /* .. or len nbr chars cmp'd (see Note #2j). */
724 p1_str_next++;
\ ??Str_Cmp_N_5:
\ 00000038 5B1C ADDS R3,R3,#+1
725 p2_str_next++;
\ 0000003A 641C ADDS R4,R4,#+1
726 p1_str++;
\ 0000003C 521C ADDS R2,R2,#+1
727 p2_str++;
\ 0000003E 491C ADDS R1,R1,#+1
728 cmp_len++;
\ 00000040 6D1C ADDS R5,R5,#+1
729 }
\ ??Str_Cmp_N_4:
\ 00000042 1678 LDRB R6,[R2, #+0]
\ 00000044 0F78 LDRB R7,[R1, #+0]
\ 00000046 BE42 CMP R6,R7
\ 00000048 07D1 BNE.N ??Str_Cmp_N_6
\ 0000004A 002E CMP R6,#+0
\ 0000004C 05D0 BEQ.N ??Str_Cmp_N_6
\ 0000004E 002B CMP R3,#+0
\ 00000050 03D0 BEQ.N ??Str_Cmp_N_6
\ 00000052 002C CMP R4,#+0
\ 00000054 01D0 BEQ.N ??Str_Cmp_N_6
\ 00000056 4545 CMP R5,R8
\ 00000058 EED3 BCC.N ??Str_Cmp_N_5
730
731
732 if (cmp_len == len_max) { /* If strs identical for len nbr of chars, */
\ ??Str_Cmp_N_6:
\ 0000005A 4545 CMP R5,R8
\ 0000005C 13D0 BEQ.N ??Str_Cmp_N_0
733 return ((CPU_INT16S)0); /* ... rtn 0 (see Note #2j). */
734 }
735
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -