home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / BPL70N12.ZIP / STRSOURC.ZIP / STCMP.ASM next >
Encoding:
Assembly Source File  |  1993-03-07  |  2.9 KB  |  65 lines

  1.  
  2. ; *******************************************************
  3. ; *                                                     *
  4. ; *     Turbo Pascal Runtime Library Version 7.0        *
  5. ; *     String Compare                                  *
  6. ; *                                                     *
  7. ; *     Copyright (C) 1990-1993 Norbert Juffa           *
  8. ; *                                                     *
  9. ; *******************************************************
  10.  
  11.              TITLE   STCMP
  12.  
  13.  
  14. CODE         SEGMENT BYTE PUBLIC
  15.  
  16.              ASSUME  CS:CODE
  17.  
  18. ; Publics
  19.  
  20.              PUBLIC  SCompare
  21.  
  22. ;-------------------------------------------------------------------------------
  23. ; SCompare compares two strings and sets the zero and carry flag according to
  24. ; the result of the comparison. These flag are set as if two unsigned integers
  25. ; had been compared. The routine compares all the characters of the shorter
  26. ; string to the ones of the longer string, starting at index 1 in each string.
  27. ; The first mismatch determines the result of the comparison. If the characters
  28. ; compared are all equal, the string's length is compared: The longer string is
  29. ; bigger.
  30. ;
  31. ; On entry:  [SP+4]  Address of destination string
  32. ;            [SP+8]  Address of source string
  33. ;
  34. ; On exit:   ZF = 1  if Source = Destination
  35. ;            CF = 1  if Source < Destination
  36. ;-------------------------------------------------------------------------------
  37.  
  38. SCompare     PROC    FAR
  39.              CLD                       ; auto increment for string instructions
  40.              MOV     DX, DS            ; save callers data segment
  41.              MOV     BX, SP            ; make new frame pointer
  42.              LDS     SI, SS:[BX+8]     ; pointer to source
  43.              LES     DI, SS:[BX+4]     ; pointer to destination
  44.              LODSB                     ; source len, SI ptr to 1. char of source
  45.              MOV     AH, ES:[DI]       ; length destination
  46.              INC     DI                ; DI ptr to 1st char of destination
  47.              MOV     CL, AL            ; duplicate length source
  48.              SUB     CL, AH            ; length source - length destination
  49.              SBB     CH, CH            ; CH = FF if length source < length dest.
  50.              AND     CL, CH            ; CL = 0, if length source >= length dest
  51.              ADD     CL, AH            ; CL = Min (length source, length dest)
  52.              XOR     CH, CH            ; zero-extend to word, set ZF = 1
  53.              REPE    CMPSB             ; comp. strings char by char until diff.
  54.              JNE     $str_differ       ; strings differ
  55.              CMP     AL, AH            ; strings equal, compare string length
  56. $str_differ: MOV     DS, DX            ; restore caller's data segment
  57.              RET     8                 ; pop parameters and return
  58. SCompare     ENDP
  59.  
  60.              ALIGN   4
  61.  
  62. CODE         ENDS
  63.  
  64.              END
  65.