home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / sampler / 02 / zd_etc / cmpstr.asm next >
Encoding:
Assembly Source File  |  1988-01-21  |  1.7 KB  |  62 lines

  1.      title   CMPSTR
  2. CODE segment byte public
  3.      assume  cs:code
  4.      public  CMPSTR
  5.  
  6. ; function CmpStr(var S1, S2) : integer;
  7. CMPSTR proc far
  8.      Str1      equ dword ptr [bp+10]
  9.      Str2      equ dword ptr [bp+06]
  10.      StackSize equ 8
  11.  
  12.      push bp            ;save bp & ds
  13.      mov  bp,sp
  14.      push bp
  15.      push ds
  16.  
  17.      lds si, Str1       ;ds:si is ptr to S1
  18.      les di, Str2       ;es:di is ptr to S2
  19.      xor ax,ax          ;clear ax
  20.      mov al,[si]        ;len(S1)
  21.      mov cx,ax          ;cx = len(S1)
  22.      mov bx,ax          ;bx = len(S1)
  23.      mov al,es:[di]        ;len(S2)
  24.      mov dx, ax         ;dx = len(S2)
  25.      cmp bx,dx          ; if len(S1) > len(S2)
  26.      jle j1             ;   skip
  27.      mov cx, dx         ; else cx = len(S2)
  28. j1:      ;cx now has smaller of the two lengths
  29.          ;ds:si pts to s1[0]
  30.          ;es:di pts to s2[0]
  31.      xor  ax,ax         ;default answer is equal
  32.      jcxz ZeroLen       ;one of them is null string
  33.      inc  si            ;pt to char 1
  34.      inc  di
  35.      cld
  36.      repz cmpsb         ;compare max cx bytes starting [si] to [di] till
  37.                         ; al = [si] - [di] becomes non zero
  38.      jl   Str1Lt
  39.      jg   Str1Gt
  40.  
  41. MayBeEqual: ;situation here is same as case of null strs.
  42. ZeroLen:    ;iff bx = dx they are equal.
  43.      cmp bx, dx         ; len(S1) ? len(S2)
  44.      je  Exit
  45.      jg  Str1Gt   ;S1 > S2
  46. Str1Lt:
  47.      dec ax             ; return -1
  48.      jmp Exit
  49. Str1Gt:
  50.      inc ax             ; return 1
  51.  
  52. Exit:
  53.      pop ds             ;restore ds & bp
  54.      pop bp
  55.      mov sp, bp
  56.      pop bp
  57.      ret StackSize      ;clean stack for parms
  58.  
  59. CMPSTR endp
  60. CODE   ends
  61.        end
  62.