home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 16 / 16.iso / w / w048 / 2.ddi / MSSRC.ARC / MSTEXT.ASM < prev    next >
Encoding:
Assembly Source File  |  1987-12-21  |  3.3 KB  |  107 lines

  1.  
  2. ;
  3. ;       MSTEXT.ASM
  4. ;       MS 4.0
  5. ;       Copyright (c) 1985, 87 by Borland International, Inc.
  6. ;
  7. ;       Assembler routines for MSTEXT
  8. ;
  9.  
  10. DATA    SEGMENT BYTE PUBLIC
  11.  
  12. DATA    ENDS
  13.  
  14. CODE    SEGMENT BYTE PUBLIC
  15.  
  16.         ASSUME  CS:CODE,DS:DATA
  17.  
  18.         ;the following routines are called NEAR
  19.         PUBLIC EdWordsInBuffer
  20.  
  21. ;****************************************************** EdWordsInBuffer
  22.  
  23. ;function EdWordsInBuffer(var Buffer; Len : Word) : Word;
  24.  
  25. ;Fast word count for a single line, alphas = ['a'..'z','A'..'Z','-',apostrophe]
  26.  
  27. ;equates for parameters:
  28. WBLen           EQU     WORD PTR [BP+4]
  29. WBBuffer        EQU     DWORD PTR [BP+6]
  30.  
  31. ;constants
  32. Apostrophe      EQU     39
  33.  
  34. EdWordsInBuffer PROC NEAR
  35.  
  36.         PUSH    BP                      ;Save BP
  37.         MOV     BP,SP                   ;Set up stack frame
  38.         PUSH    DS                      ;Save DS
  39.  
  40.         XOR     BX,BX                   ;BX (word count) = 0
  41.         XOR     DX,DX                   ;DX (in word flag) = 0
  42.         MOV     DI,1                    ;DI = Ord(True)
  43.         CLD                             ;go forward
  44.         LDS     SI,WBBuffer             ;point to Buffer
  45.         MOV     CX,WBLen                ;CX = Length(Buffer)
  46.         JCXZ    WBDone                  ;done if CX = 0
  47.  
  48. WBNextChar:
  49.         LODSB                           ;next char in S into AL
  50.  
  51.         ;Is it an apostrophe?
  52.  
  53.         CMP     AL,Apostrophe           ;AL = apostrophe?
  54.         JB      WBNotAlpha              ;<, not alpha
  55.         JE      WBAlpha                 ;=, alpha
  56.  
  57.         ;Is it a lowercase letter?
  58.  
  59.         CMP     AL,'z'                  ;AL = 'z'?
  60.         JA      WBNotAlpha              ;>, not alpha
  61.         CMP     AL,'a'                  ;AL = 'a'?
  62.         JNB     WBAlpha                 ;>=, alpha
  63.  
  64.         ;Is it an uppercase letter?
  65.  
  66.         CMP     AL,'Z'                  ;AL = 'Z'?
  67.         JA      WBNotAlpha              ;>, not alpha
  68.         CMP     AL,'A'                  ;AL = 'A'?
  69.         JNB     WBAlpha                 ;>=, alpha
  70.  
  71.         ;Is it a hyphen?
  72.  
  73.         CMP     AL,'-'                  ;AL = '-'?
  74.         JE      WBAlpha                 ;=, alpha
  75.  
  76. WBNotAlpha:     ;See if in word flag was on (i.e., if DX = DI = 1)
  77.  
  78.         CMP     DX,DI                   ;in word previously?
  79.         JNE     WBSkipToNext            ;no, next char
  80.         INC     BX                      ;increment word count
  81.         XOR     DX,DX                   ;not in word
  82.         JMP     WBSkipToNext            ;next char
  83.  
  84. WBAlpha:
  85.         MOV     DX,DI                   ;set the in word flag
  86.  
  87. WBSkipToNext:
  88.         LOOP    WBNextChar              ;loop if not at end of buffer
  89.  
  90.         ;End of buffer -- if in word flag still on, increment word count
  91.  
  92.         CMP     DX,DI                   ;last char in Buffer part of word?
  93.         JNE     WBDone                  ;no, done
  94.         INC     BX                      ;increment word count
  95. WBDone:
  96.         MOV     AX,BX                   ;Word count from BX into AX
  97.         POP     DS                      ;Restore DS
  98.         MOV     SP,BP                   ;Restore SP
  99.         POP     BP                      ;Restore BP
  100.         RET     6                       ;Remove parameters and return
  101.  
  102. EdWordsInBuffer ENDP
  103.  
  104. CODE    ENDS
  105.  
  106.         END
  107.