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

  1. ;
  2. ; *** Listing 14-5 ***
  3. ;
  4. ; Copies the standard input to the standard output,
  5. ; converting all characters to uppercase. Does so in
  6. ; blocks of 256 characters.
  7. ;
  8.     jmp    Skip
  9. ; Storage for the characters we're processing.
  10. CHARACTER_BLOCK_SIZE    equ    256
  11. CharacterBlock    db    CHARACTER_BLOCK_SIZE dup (?)
  12. ErrorMsg    db    'An error occurred', 0dh, 0ah
  13. ERROR_MSG_LENGTH equ    $-ErrorMsg
  14. ;
  15. Skip:
  16.     call    ZTimerOn
  17. CopyLoop:
  18.     mov    ah,3fh    ;DOS read fn
  19.     sub    bx,bx    ;handle 0 is the standard input
  20.     mov    cx,CHARACTER_BLOCK_SIZE
  21.             ;we want to get a block
  22.     mov    dx,offset CharacterBlock
  23.             ;the characters go here
  24.     int    21h    ;get the characters
  25.     jc    Error    ;check for an error
  26.     mov    cx,ax    ;get the count where it does us the
  27.             ; most good
  28.     jcxz    Done    ;if we didn't read anything, we've
  29.             ; hit the end of the file
  30.     mov    dx,cx    ;remember how many characters we read
  31.     mov    bx,offset CharacterBlock
  32.             ;point to the first character to
  33.             ; convert
  34. ConvertLoop:
  35.     mov    al,[bx]        ;get the next character and
  36.     cmp    al,'a'        ; convert it to uppercase
  37.     jb    ConvertLoopBottom ; if it's lowercase
  38.     cmp    al,'z'
  39.     ja    ConvertLoopBottom
  40.     and    al,not 20h    ;it's uppercase-convert to
  41.     mov    [bx],al        ; uppercase and save
  42. ConvertLoopBottom:
  43.     inc    bx        ;point to the next character
  44.     loop    ConvertLoop
  45.     mov    cx,dx    ;get back the character count in
  46.             ; this block, to serve as a count of
  47.             ; bytes for DOS to write
  48.     mov    ah,40h    ;DOS write fn
  49.     mov    bx,1    ;handle 1 is the standard output
  50.     mov    dx,offset CharacterBlock
  51.             ;point to the characters to write
  52.     push    cx    ;remember # of characters read
  53.     int    21h    ;write the character
  54.     pop    ax    ;get back the # of characters in
  55.             ; this block
  56.     jc    Error    ;check for an error
  57.     cmp    ax,CHARACTER_BLOCK_SIZE
  58.             ;was it a partial block?
  59.     jz    CopyLoop ;no, so we're not done yet
  60.     jmp    short Done ;it was a partial block, so that
  61.                ; was the end of the file
  62. Error:
  63.     mov    ah,40h    ;DOS write fn
  64.     mov    bx,2    ;handle 2 is standard error
  65.     mov    cx,ERROR_MSG_LENGTH ;# of chars to display
  66.     mov    dx,offset ErrorMsg ;error msg to display
  67.     int    21h    ;notify of error
  68. Done:
  69.     call    ZTimerOff
  70.