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

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