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

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