home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / WINER.ZIP / COMPARE2.ASM < prev    next >
Assembly Source File  |  1992-05-13  |  2KB  |  64 lines

  1. ;********* COMPARE2.ASM - compares two ranges of memory case-insensitive
  2. ;
  3. ;Copyright (c) 1991 Ethan Winer
  4. ;
  5. ;
  6. ;Usage:
  7. ;
  8. ;   Same = Compare2%(SEG Type1, SEG Type2, NumBytes%)
  9. ;or
  10. ;   Same = Compare2%(BYVAL Seg1%, BYVAL Adr1%, BYVAL Seg2%, BYVAL Adr2%, NumBytes%)
  11. ;
  12. ;Where Same receives -1 if the two type variables or ranges of memory are the
  13. ;same, or 0 if they are not.  NumBytes% tells how many bytes to compare.
  14.  
  15.  
  16. .Model Medium, Basic
  17. .Code
  18.  
  19. Compare2 Proc Uses DS ES DI SI, SegAdr1:DWord, SegAdr2:DWord, NumBytes:Word
  20.  
  21.     Cld                     ;compare in the forward direction
  22.     Mov  BX,-1              ;assume the ranges are the same
  23.  
  24.     Mov  SI,NumBytes        ;get the address for NumBytes%
  25.     Mov  CX,[SI]            ;put it into CX for comparing below
  26.     Jcxz Exit               ;if zero bytes were given, they're the same
  27.  
  28.     Les  DI,SegAdr1         ;load ES:DI with the first segmented address
  29.     Lds  SI,SegAdr2         ;load DS:SI with the second segmented address
  30.  
  31. Do:
  32.     Lodsb                   ;load the current character from DS:SI into AL
  33.     Call Upper              ;capitalize as necessary
  34.     Mov  AH,AL              ;copy the character to AH
  35.     
  36.     Mov  AL,ES:[DI]         ;load the current character from ES;DI into AL
  37.     Inc  DI                 ;point at the next character for later
  38.     Call Upper              ;capitalize as necessary
  39.  
  40.     Cmp  AL,AH              ;now, are they the same?
  41.     Jne  False              ;no, exit now and show that
  42.     Loop Do                 ;yes, continue
  43.     Jmp  Short Exit         ;if we get this far, the bytes are all the same
  44.  
  45. False:
  46.     Inc  BX                 ;increment BX up to zero to return False
  47.     
  48. Exit:
  49.     Mov  AX,BX              ;assign the function output
  50.     Ret                     ;return to BASIC
  51.  
  52. Upper:
  53.     Cmp  AL,"a"             ;is the character below an "a"?
  54.     Jb   Done               ;yes, so we can skip it
  55.     Cmp  AL,"z"             ;is the character above a "z"?
  56.     Ja   Done               ;yes, so we can skip that too
  57.     Sub  AL,32              ;convert to upper case
  58.  
  59. Done:
  60.     Retn                    ;do a near return to the caller
  61.  
  62. Compare2 Endp
  63. End
  64.