strcmp

Purpose: Alphabetically compare two (2) character strings, both of which are in SRAM.
Assumes: Both strings are NULL terminated ASCII (i.e., "ASCIIz") strings.
Passed: R25:R24  BYTE *   szPtrString1 pointer to the buffer containing the first ASCIIz string
R23:R22 BYTE * szPtrString2   pointer ot the buffer containing the second ASCIIz string
Returns:   R24 CHAR cResult less than 0 when String#1 alphabetically preceeds String#2 OR
equal to 0 when the strings are same length and have identical BYTEs OR
greater than 0 when String#1 alphabetically follows String#2
Alters: R25, R26, R27, R30, R31, and the FLAGs (the "T" FLAG, specifically)
Example: 
CompareStrings:
   ADIW    R26, 0                 ; If 'X' is zero, the command line has nothing
   BREQ    ACompare_Ret           ;  to be checked, so just exit immediately
   MOVW    R24, R26
   LDI     R22, '"'               ; Specify the string starting delimiter BYTE
   CALL    Astrchr                ; Search for the first occurrence of a double
   BREQ    ACompare_Ret           ;  quote character; exit if none found
   ADIW    R24, 1                 ; Advance to the BYTE after the first double
   MOVW    R20, R24               ;  quote and save that SRAM address
   CALL    Astrchr
   BREQ    ACompare_Ret

   MOVW    R26, R24               ; Terminate the first string and point 'X'
   ST      X+, R1                 ;  at the first BYTE of the second one
   MOVW    R24, R20               ; R25:R24 = start of the first string found
   MOVW    R22, R26               ; R23:R22 = start of the second one, in 'X'
   CALL    Astrcmp                ; Do the comparison
   LDI     R19, ' '               ; Output a single space before the hex BYTE
   MOV     R22, R24               ; Move the results BYTE returned to R22
   LDI     R25, ACSZ_Result >> 8
   LDI     R24, ACSZ_Result & 0xFF
   CALL    APrintDescAndHexBYTE   ; Output the string and the result BYTE then
   CALL    APrintNewLine          ;  a Carriage Return and Line Feed

Compare_Ret:
   RET

CSZ_Result:  .STRING  "strcmp() returned"
Test it:
m>@ 0x1000 "String1"String2
strcmp() returned 0xFF
m>@ 0x1000 "String1"String1
strcmp() returned 0x00
m>@ 0x1000 "String 1"String01
strcmp() returned 0xF0
m>@ 0x1000 "String1
m>@ 0x1000 "String1"STRING1
strcmp() returned 0x20
m>@ 0x1000 "STring1"String2
strcmp() returned 0xE0
m>@ 0x1000 "String with spaces"String with spaces
strcmp() returned 0x00
m>@ 0x1000 "String with spaces"String with 3 spaces
strcmp() returned 0x40
m>@ 0x1000 "ABC"abc
strcmp() returned 0xE0
m>@ 0x1000 "abc"abc
strcmp() returned 0x00
m>@ 0x1000 "abc"ABC
strcmp() returned 0x20
m>                                                                              
Notes: Less than zero means that cResult, the signed result returned in R24, is 0x80 through 0xFF (i.e., the most significant bit is set.)            
More than zero means that cResult is 1 through 0x7F (= 127.)
The comparison is case-sensitive.
Dropin: 
(setup
code)
;   Setup for the strcmp() call:
; Passed:  R25:R24 BYTE * szPtrString1 pointer to the buffer with String#1
;          R23:R22 BYTE * szPtrString2 pointer to the buffer with String#2
; Returns:     R24 CHAR   < 0 if String#1 alphabetically preceeds String#2
;                         = 0 if the strings are same length and identical
;                         > 0 if String#1 alphabetically follows String #2
; Alters:  R25, R26, R27, R30, R31, and the FLAGs ("T", specifically)
Also see:  The strcmpPGM, strchr, strcpy, and strlen System Functions.