home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / asmlib.lbr / CMPSTR.AZM / CMPSTR.ASM
Encoding:
Assembly Source File  |  1991-06-25  |  1.8 KB  |  65 lines

  1. ;----------------------------------------------------------------
  2. ;     This is a module in the ASMLIB library.
  3. ;
  4. ; This module will compare two strings and return flags to indicate
  5. ; equality or size difference. This routine was taken from the book
  6. ; Z-80 Subroutines By Saville and Leventhal. Modifications have been
  7. ; done for TDL opcodes and to change parameter passing so that 
  8. ; string 1 is pointed to by DE and string 2 by HL.
  9. ; A string is up to 255 bytes long and is preceded by its length.
  10. ;
  11. ; Returned flage are.        Carry    Zero
  12. ;   string 1 = string 2         0       1
  13. ;   string 1 > string 2          0       0
  14. ;   string 1 < string 2           1       0
  15. ;
  16. ;             Written        R.C.H.         1/10/83
  17. ;            Last Update    R.C.H.         1/10/83
  18. ;----------------------------------------------------------------
  19. ;
  20.     name    'cmpstr'
  21.     public    cmpstr
  22.     maclib    z80
  23. ;
  24. cmpstr:
  25.     push    b            ; Save
  26.     xchg                ; Put into order
  27.     mov    a,m            ; Length string 1
  28.     sta    lens1
  29.     ldax    d            ; Length string 2
  30.     sta    lens2
  31.     cmp    m            ; compare lengths
  32.     jrc    begcmp            ; jump if string 1 is shorter
  33.     mov    a,m            ; string 1 is shorter
  34. ;
  35. begcmp:
  36.     ora    a            ; Test if shorter length is zero
  37.     jrz    cmplen            ; Compare lengths then
  38.     mov    b,a            ; Load a counter
  39.     xchg                ; swap string pointers
  40. cmplp:    ; Loop here to check characters
  41.     inx    h
  42.     inx    d            ; Bump character pointers
  43.     ldax    d
  44.     cmp    m            ; Compare string bytes
  45.     jrnz    strend
  46.     djnz    cmplp            ; Keep on till all characters done
  47. ; Here, all characters are equal so we test the lengths and use this for the
  48. ; flags.
  49. cmplen:    ; Compare lengths of the strings
  50.     lda    lens1
  51.     lxi    h,lens2            ; Point to second length
  52.     cmp    m            ; Do the compare
  53. strend:
  54.     pop    b            ; Restore
  55.     ret
  56. ;
  57.     dseg
  58. lens1:    db    00
  59. lens2:    db    00
  60.     
  61.     end
  62.  
  63.  
  64.  
  65.