home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / COMPAR9.ASM < prev    next >
Assembly Source File  |  1994-10-27  |  2KB  |  78 lines

  1.     page    66,132
  2. ;******************************* COMPAR9.ASM ********************************
  3.  
  4. LIBSEG           segment byte public "LIB"
  5.         assume cs:LIBSEG , ds:nothing
  6.  
  7. ;----------------------------------------------------------------------------
  8. .xlist
  9.     include  mac.inc
  10.     include  common.inc
  11. .list
  12. comment 
  13. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( COMPARE )
  14. ;COMPARE9 - compares two characters, either case matches
  15. ;
  16. ; inputs:   ah = character 1
  17. ;           al = character 2
  18. ;  output:    flag registers set for "je" "jne"
  19. ;             al = case of character may be changed.
  20. ;
  21. ;* * * * * * * * * * * * * *
  22. 
  23.     PUBLIC    COMPARE9
  24. COMPARE9    PROC    FAR
  25.     push    dx
  26.     mov    dl,20h            ;case flag
  27.     call    compare
  28.     pop    dx
  29.     retf
  30. COMPARE9    ENDP
  31. ;------------------------------------------------------------------------
  32. ; compare characters ignoring case
  33. ;  inputs:    al = character 1
  34. ;             ah = character 2
  35. ;             dl = 20h
  36. ;
  37. ;  output:    flag registers set for "je" "jne"
  38. ;             al = case of character may be changed.
  39. ;             dx = changed.
  40. ;
  41.     public    compare
  42. compare:   cmp       al, ah        ;match?
  43.        je       c_exit        ;jmp if match
  44.        mov       dh, al        ;try matching other
  45.        or       dh, dl        ;  case if char
  46.            sub     dh, 'a'        ;     is an alpha
  47.            cmp     dh, 'z' - 'a' + 1
  48.        jnc       not_alpha
  49.        xor       al,dl
  50. not_alpha: cmp     al, ah
  51. c_exit:       ret
  52. ;------------------------------------------------------------------------
  53. ; compare_strings - compare strings ignoring case
  54. ;  inputs: ds:si = string 1 (zero terminated string recognized)
  55. ;          es:di = string 1
  56. ;             cx = max string length
  57. ;  output: si,di,cx updated
  58. ;          ax changed
  59. ;          flags set for "je" or "jne"
  60. ;
  61.     public    compare_strings
  62. compare_strings:
  63.     jcxz    cs_exit        ;exit if out of data
  64.     cld
  65.     lodsb
  66.     test    al,al
  67.     je    cs_exit
  68.     mov    ah,es:[di]
  69.     inc    di
  70.     call    compare
  71.     je    compare_strings    ;jmp if strings match
  72. cs_exit:ret    
  73. ;------------------------------------------------------------------------
  74.  
  75. LIBSEG    ENDS
  76.     end
  77.