home *** CD-ROM | disk | FTP | other *** search
-
- ;
- ; MSTEXT.ASM
- ; MS 4.0
- ; Copyright (c) 1985, 87 by Borland International, Inc.
- ;
- ; Assembler routines for MSTEXT
- ;
-
- DATA SEGMENT BYTE PUBLIC
-
- DATA ENDS
-
- CODE SEGMENT BYTE PUBLIC
-
- ASSUME CS:CODE,DS:DATA
-
- ;the following routines are called NEAR
- PUBLIC EdWordsInBuffer
-
- ;****************************************************** EdWordsInBuffer
-
- ;function EdWordsInBuffer(var Buffer; Len : Word) : Word;
-
- ;Fast word count for a single line, alphas = ['a'..'z','A'..'Z','-',apostrophe]
-
- ;equates for parameters:
- WBLen EQU WORD PTR [BP+4]
- WBBuffer EQU DWORD PTR [BP+6]
-
- ;constants
- Apostrophe EQU 39
-
- EdWordsInBuffer PROC NEAR
-
- PUSH BP ;Save BP
- MOV BP,SP ;Set up stack frame
- PUSH DS ;Save DS
-
- XOR BX,BX ;BX (word count) = 0
- XOR DX,DX ;DX (in word flag) = 0
- MOV DI,1 ;DI = Ord(True)
- CLD ;go forward
- LDS SI,WBBuffer ;point to Buffer
- MOV CX,WBLen ;CX = Length(Buffer)
- JCXZ WBDone ;done if CX = 0
-
- WBNextChar:
- LODSB ;next char in S into AL
-
- ;Is it an apostrophe?
-
- CMP AL,Apostrophe ;AL = apostrophe?
- JB WBNotAlpha ;<, not alpha
- JE WBAlpha ;=, alpha
-
- ;Is it a lowercase letter?
-
- CMP AL,'z' ;AL = 'z'?
- JA WBNotAlpha ;>, not alpha
- CMP AL,'a' ;AL = 'a'?
- JNB WBAlpha ;>=, alpha
-
- ;Is it an uppercase letter?
-
- CMP AL,'Z' ;AL = 'Z'?
- JA WBNotAlpha ;>, not alpha
- CMP AL,'A' ;AL = 'A'?
- JNB WBAlpha ;>=, alpha
-
- ;Is it a hyphen?
-
- CMP AL,'-' ;AL = '-'?
- JE WBAlpha ;=, alpha
-
- WBNotAlpha: ;See if in word flag was on (i.e., if DX = DI = 1)
-
- CMP DX,DI ;in word previously?
- JNE WBSkipToNext ;no, next char
- INC BX ;increment word count
- XOR DX,DX ;not in word
- JMP WBSkipToNext ;next char
-
- WBAlpha:
- MOV DX,DI ;set the in word flag
-
- WBSkipToNext:
- LOOP WBNextChar ;loop if not at end of buffer
-
- ;End of buffer -- if in word flag still on, increment word count
-
- CMP DX,DI ;last char in Buffer part of word?
- JNE WBDone ;no, done
- INC BX ;increment word count
- WBDone:
- MOV AX,BX ;Word count from BX into AX
- POP DS ;Restore DS
- MOV SP,BP ;Restore SP
- POP BP ;Restore BP
- RET 6 ;Remove parameters and return
-
- EdWordsInBuffer ENDP
-
- CODE ENDS
-
- END