home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / MURUTIL4.ZIP / PIPE.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-11-22  |  2.2 KB  |  81 lines

  1.     PAGE    57,132
  2.     TITLE    PIPE -- File Pipeline routine.
  3.     NAME    PIPE
  4. ;
  5. ;    Usage examples:
  6. ;            PIPE <INPUT.FIL >OUTPUT.FIL
  7. ;            SORT <DATA.FIL | PIPE >DATA.FIL
  8. ;
  9. ;    This is a pipeline routine which merely copies the input file
  10. ;    to the output file, using a 8192 byte buffer.
  11. ;
  12. ;    Program by Harry M. Murphy,  28 January 1988.
  13. ;
  14. BEL    EQU    07H        ;Bell (beep) code.
  15. BUFLEN    EQU    2000H        ;Buffer length for I/O.
  16. CR    EQU    0DH        ;Carriage Return code.
  17. DOS    EQU    21H        ;DOS interrupt.
  18. LF    EQU    0AH        ;Line Feed code.
  19. STDIN    EQU    0        ;Standard input file handle.
  20. STDOUT    EQU    1        ;Standard output file handle.
  21. ;
  22. PIPE SEGMENT 'CODE'
  23.     ORG    100H        ;This is a "COM" routine.
  24.     ASSUME    CS:PIPE,DS:PIPE
  25. ;
  26. START:    JMP    SHORT READ
  27. ;
  28. NBYTES    DW    ?
  29. RDMSG    DB    CR,LF,'PIPE:  Read error!',CR,LF,BEL,0
  30. WRMSG    DB    CR,LF,'PIPE:  Write error!',CR,LF,BEL,0
  31. WFMSG    DB    CR,LF,'PIPE:  Disk full error!',CR,LF,BEL,0
  32. ;
  33.         EVEN
  34. READ:    MOV    AH,3FH        ;Read up to BUFLEN bytes
  35.     MOV    BX,STDIN    ;  into the buffer from the
  36.     MOV    CX,BUFLEN    ;    standard
  37.     MOV    DX,OFFSET BUFFER ;     input
  38.     INT    DOS        ;     unit.
  39.     MOV    SI,OFFSET RDMSG    ;Point to read-error message
  40.     JC    ABORT        ;  and abort if carry is set.
  41. ;
  42.     MOV    NBYTES,AX    ;No read error.  Save number of bytes
  43.     OR    AX,AX        ;  read in NBYTES and, if it's zero,
  44.     JZ    EXIT        ;    we have read it all, so exit.
  45. ;
  46. WRITE:    MOV    AH,40H        ;Write NBYTES
  47.     MOV    BX,STDOUT    ;  from the buffer to the
  48.     MOV    CX,NBYTES    ;    standard
  49.     MOV    DX,OFFSET BUFFER ;     output
  50.     INT    DOS        ;        unit.
  51.     MOV    SI,OFFSET WRMSG    ;Point to write-error message
  52.     JC    ABORT        ;  and abort if carry is set.
  53. ;
  54.     CMP    AX,NBYTES    ;If we wrote all the bytes,
  55.     JE    READ        ;  loop for the next buffer.
  56. ;
  57.     MOV    SI,OFFSET WFMSG    ;Otherwise, point to "full" message
  58.     JMP    SHORT ABORT    ;  and abort.
  59. ;
  60. EXIT:    MOV    AX,4C00H    ;Exit with
  61.     INT    DOS        ;  ERRORLEVEL = 0.
  62. ;
  63. ABORT:    MOV    AH,0EH        ;Prepare for BIOS output text in
  64.     XOR    BX,BX        ;  teletype mode interrupt and
  65.     CLD            ;    clear the direction flag.
  66. ;
  67. ABRT1:    LODSB            ;Get next byte of the message,
  68.     OR    AL,AL        ;  test for zero and
  69.     JZ    ABRT2        ;    skip out on zero.
  70. ;
  71.     INT    10H        ;Else, display the byte and
  72.     JMP    ABRT1        ;  loop for next byte.
  73. ;
  74. ABRT2:    MOV    AX,4C07H    ;Exit with
  75.     INT    DOS        ;  ERRORLEVEL = 7.
  76. ;
  77.     EVEN
  78. BUFFER    LABEL    BYTE
  79. PIPE    ENDS
  80.     END    START
  81.