home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / hamradio / wattcp.zip / STRINGS.ASM < prev    next >
Assembly Source File  |  1992-02-03  |  2KB  |  80 lines

  1. PAGE    66,132
  2. ;
  3. ;
  4. ;
  5. ;
  6. ;
  7. ;  net_string - find a network string from a buffer
  8. ;
  9. ;
  10. ;  (c) 1992 University of Waterloo,
  11. ;           Faculty of Engineering,
  12. ;           Engineering Microcomputer Network Development Office
  13. ;
  14. ;
  15. ;
  16.     include masmdefs.hsm
  17.     include    model.hsm
  18.  
  19. codedef net_string
  20. datadef
  21.  
  22. cstart  net_string
  23.  
  24. ;*************************************************************************
  25. ;  USAGE:  int net_string( byte *buf, int buflen, byte *strbuf, int strbuflen )
  26. ;  ALL POINTERS ASSUMED FAR
  27. ;*************************************************************************
  28. cpublic net_string
  29.         push    DS
  30.         push    ES
  31.         cld
  32.  
  33.         lds     SI, +@AB + 0  [BP]
  34.         mov     BX, +@AB + 4  [BP]
  35.         les     DI, +@AB + 6  [BP]
  36.         mov     CX, +@AB + 10 [BP]
  37.  
  38.         cmp     CX, BX          ; find the lesser, ie. max string len
  39.         ja      .0
  40.         mov     CX, BX
  41.  
  42. .0:     sub     CX, 2           ; must leave room for the '\0'
  43.         mov     BX, CX          ; need later
  44.  
  45. .1:     lodsb                   ; check each character to see if
  46.         cmp     AL, 0eh         ; it is the string terminator
  47.         jb      .3              ; a likely suspect is investigated
  48. .2:     stosb
  49.         loop    .1
  50.         jcxz    .4              ; quite done
  51.                                 ; (MS-ASM generates phase error if we use JMP
  52.                                 ; phase-error? Get a life Microsoft, figuring
  53.                                 ; out the distance is pretty darn trivial,
  54.                                 ; even DEBUG can do it!)
  55.  
  56. .3:     cmp     AL, 0ah         ; <lf>
  57.         je      .4
  58.         cmp     AL, 0dh         ; <cr>
  59.         jne     .2              ; no, so continue
  60.  
  61.         ; this is still for <cr>, we erase the next character
  62.         jcxz    .5              ; no more characters - line incomplete
  63.         dec     CX
  64.         jmp     .4
  65.  
  66.         ; here we handle case when we didn't find a string
  67. .5:
  68.  
  69. .4:     xor     AL, AL
  70.         stosb
  71.  
  72.         ; now must return length of string to remove
  73.         mov     AX, BX
  74.         sub     AX, CX
  75. .6:     pop     ES
  76.         pop     DS
  77. creturn net_string
  78. cend    net_string
  79.         end
  80.