home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / tasm / ofilwrit.asm < prev    next >
Assembly Source File  |  1988-08-28  |  2KB  |  92 lines

  1.  
  2. ;    FILENAME: OFILWRIT.ASM
  3. ;    Copyright (c) 1988 by Borland International, Inc.
  4. ;
  5. ;    Description: This module implements the routine FileWrite. FileWrite 
  6. ;    writes to a file. 
  7. ;    ASSEMBLY INSTRUCTIONS:  To assemble this module use the following  
  8. ;    TASM command line.  
  9. ;  
  10. ;        TASM ofilwrit
  11.  
  12. include globals.inc
  13.  
  14. _TEXT   segment
  15.  
  16.     FileWrite proc
  17.  
  18.     ;    Input 
  19.     ;        bx - file record offset
  20.     ;        cx - number of bytes
  21.     ;        si - location of bytes
  22.     ;    Output
  23.     ;        cf - set if error occurred
  24.     ;        ax - error code
  25.     ;        (cf set and ax = 0 if EOF)
  26.     ;            0 - if EOF and 0 bytes are read
  27.     ;    Registers modified
  28.     ;        None
  29.  
  30.  
  31.     pushf
  32.     push    cx
  33.     push    dx
  34.     push    di
  35.     push    si
  36.     cld
  37.     mov     dx, [bx+6]      ;buffer segment
  38.  
  39.     ;--- copy bytes to buffer
  40.  
  41. filwrt1:
  42.     mov     ax, [bx+2]      ;buffer size
  43.     mov     di, [bx+4]      ;data pointer
  44.     sub     ax, di          ;buffer space available
  45.     jz      filwrt3         ;jump if none, must flush first
  46.  
  47.     push    es
  48.     push    cx
  49.     cmp     ax, cx          ;check if all bytes fit
  50.     jae     filwrt2
  51.     mov     cx, ax          ;set to maximum
  52.  
  53. filwrt2:
  54.     push    cx
  55.     mov     es, dx
  56.     rep     movsb
  57.     pop     ax
  58.     pop     cx
  59.     pop     es
  60.     mov     [bx+4], di      ;save data pointer
  61.     sub     cx, ax          ;get bytes not yet written
  62.     jz      filwrt4         ;jump if finished
  63.  
  64.     ;--- write buffer
  65.  
  66. filwrt3:
  67.     call    FileFlush       ;flush buffer first
  68.     jnc     filwrt1         ;loop back if no error
  69.  
  70.     ;--- finished
  71.  
  72. filwrt4:
  73.     pop     si
  74.     pop     di
  75.     pop     dx
  76.     pop     cx
  77.     jc      filwrt5
  78.     popf
  79.     clc
  80.     ret
  81.  
  82. filwrt5:
  83.     popf
  84.     stc
  85.     ret
  86.     FileWrite endp
  87.  
  88. _TEXT    ends
  89.  
  90. end
  91.