;:::::::::::::::::::::::::::::::::::::::::
;:      Sito:  www.byteman.it  OpenWeb  ::
;:  Raccolta:  Particelle PAS+ASM       ::
;:    Autore:  Salvo Rosta aka byteman  ::
;:    Titolo:  XWORDCNT.ASM             ::
;: Revisione:  07-04-1994               ::
;:::::::::::::::::::::::::::::::::::::::::

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;:        XWordCnt.ASM  -  Versione: 6-9-1992  a cura di Salvo Rosta.       ::
;:                                                                          ::
;: Function  XWordCount(S: String): Word;  ; Conta le parole di una stringa ::
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 

String    EQU     DWORD PTR [BP+6]

CODE      SEGMENT BYTE PUBLIC
          ASSUME  CS:CODE
          PUBLIC  XWordCount

ProcUno   PROC    FAR

XWordCount:
          PUSH    BP
          MOV     BP,SP               ;Set Stack Frame
          LES     DI,String           ;Point Es:Di To String
          SUB     DX,DX               ;Clear Dx As Counter
          MOV     CX,DX               ;Clear Cx
          MOV     CL,ES:[DI]          ;Get String Descriptor
          MOV     AL,32               ;Al Holds Space Char
WordK1:   JCXZ    WordEnd             ;Jump Ahead At Eol
          INC     DI                  ;Forward Pointer
          DEC     CX                  ;Dec Strx Counter
          CMP     ES:[DI],AL          ;Char A Space?
          JE      WordK1              ;Loop If So
          INC     DX                  ;Word Starts -- Inc Ctr
WordK2:   JCXZ    WordEnd             ;Jump Ahead At Eol
          INC     DI                  ;Forward Pointer
          DEC     CX                  ;Dec Strx Counter
          CMP     ES:[DI],AL          ;Char A Space?
          JE      WordK1              ;Back To Spc Loop If So
          JMP     WordK2              ;Else Next Word Char
WordEnd:  MOV     AX,DX               ;Set Return Value
          POP     BP
          RET     4

ProcUno   ENDP
CODE      ENDS
          END