home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / zendisk2.zip / LST13-18.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  2KB  |  73 lines

  1. ;
  2. ; *** Listing 13-18 ***
  3. ;
  4. ; Copies a zero-terminated string to another string,
  5. ; filtering out non-printable characters by means of
  6. ; carefully customized code that performs the test
  7. ; directly in the loop.
  8. ;
  9.     jmp    Skip
  10. ;
  11. SourceString    label    byte
  12.     db    'This is a sample string, consisting of '
  13. X=1
  14.     rept    31
  15.     db    X
  16. X=X+1
  17.     endm
  18.     db    7fh
  19.     db    'both printable and non-printable '
  20.     db    'characters', 0
  21. DestinationString    label    byte
  22.     db    200 dup (?)
  23. ;
  24. ; Copies a zero-terminated string to another string,
  25. ; filtering out non-printable characters.
  26. ;
  27. ; Input:
  28. ;    DS:SI = source string
  29. ;    ES:DI = destination string
  30. ;
  31. ; Output: none
  32. ;
  33. ; Registers altered: AL, SI, DI
  34. ;
  35. ; Direction flag cleared
  36. ;
  37. ; Note: Does not handle strings that are longer than 64K
  38. ;    bytes or cross segment boundaries.
  39. ;
  40. CopyPrintable:
  41.     cld
  42. CopyPrintableLoop:
  43.     lodsb            ;get the next byte to copy
  44.     cmp    al,20h
  45.     jb    NotPrintable    ;not printable
  46.     cmp    al,7eh
  47.     ja    CopyPrintableLoop ;not printable
  48.     stosb            ;put the byte in the
  49.                      ; destination string
  50.     jmp    CopyPrintableLoop ;the character was
  51.                 ; printable, so it couldn't
  52.                 ; possibly have been 0. No
  53.                 ; need to check whether it
  54.                 ; terminated the string
  55. NotPrintable:
  56.     and    al,al        ;was that the
  57.                 ; terminating zero?
  58.     jnz    CopyPrintableLoop ;no, do next byte
  59.     stosb            ;copy the terminating zero
  60.     ret            ;done
  61. ;
  62. Skip:
  63.     call    ZTimerOn
  64.     mov    di,seg DestinationString
  65.     mov    es,di
  66.     mov    di,offset DestinationString
  67.             ;ES:DI points to the destination
  68.     mov    si,offset SourceString
  69.             ;DS:SI points to the source
  70.     call    CopyPrintable    ;copy the printable
  71.                 ; characters
  72.     call    ZTimerOff
  73.