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

  1. ;
  2. ; *** Listing 14-1 ***
  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. The subroutine is
  7. ; called with a far call and returns with a far return.
  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. ; Determines whether a character is printable (in the range
  25. ; 20h through 7Eh).
  26. ;
  27. ; Input:
  28. ;    AL = character to check
  29. ;
  30. ; Output:
  31. ;    Zero flag set to 1 if character is printable,
  32. ;        set to 0 otherwise
  33. ;
  34. ; Registers altered: none
  35. ;
  36. IsPrintable    proc    far
  37.     cmp    al,20h
  38.     jb    IsPrintableDone    ;not printable
  39.     cmp    al,7eh
  40.     ja    IsPrintableDone    ;not printable
  41.     cmp    al,al    ;set the Zero flag to 1, since the
  42.             ; character is printable
  43. IsPrintableDone:
  44.     ret
  45. IsPrintable    endp
  46. ;
  47. ; Copies a zero-terminated string to another string,
  48. ; filtering out non-printable characters.
  49. ;
  50. ; Input:
  51. ;    DS:SI = source string
  52. ;    ES:DI = destination string
  53. ;
  54. ; Output: none
  55. ;
  56. ; Registers altered: AL, SI, DI
  57. ;
  58. ; Direction flag cleared
  59. ;
  60. ; Note: Does not handle strings that are longer than 64K
  61. ;    bytes or cross segment boundaries.
  62. ;
  63. CopyPrintable:
  64.     cld
  65. CopyPrintableLoop:
  66.     lodsb            ;get the next byte to copy
  67.     call    IsPrintable    ;is it printable?
  68.     jnz    NotPrintable    ;nope, don't copy it
  69.     stosb            ;put the byte in the
  70.                      ; destination string
  71.     jmp    CopyPrintableLoop ;the character was
  72.                 ; printable, so it couldn't
  73.                 ; possibly have been 0. No
  74.                 ; need to check whether it
  75.                 ; terminated the string
  76. NotPrintable:
  77.     and    al,al        ;was that the
  78.                 ; terminating zero?
  79.     jnz    CopyPrintableLoop ;no, do next byte
  80.     stosb            ;copy the terminating zero
  81.     ret            ;done
  82. ;
  83. Skip:
  84.     call    ZTimerOn
  85.     mov    di,seg DestinationString
  86.     mov    es,di
  87.     mov    di,offset DestinationString
  88.             ;ES:DI points to the destination
  89.     mov    si,offset SourceString
  90.             ;DS:SI points to the source
  91.     call    CopyPrintable    ;copy the printable
  92.                 ; characters
  93.     call    ZTimerOff
  94.