home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / dos_ency / 9 / fig9_4.asm < prev    next >
Encoding:
Assembly Source File  |  1988-08-11  |  3.2 KB  |  77 lines

  1.         .
  2.         .
  3.         .
  4.         mov     bx,800h         ; 800H paragraphs = 32 KB
  5.         mov     ah,48h          ; Fxn 48H = allocate block
  6.         int     21h             ; transfer to MS-DOS
  7.         jc      error           ; jump if allocation failed
  8.         mov     bufseg,ax       ; save segment of block
  9.  
  10.                                 ; open working file...
  11.         mov     dx,offset file1 ; DS:DX = filename address
  12.         mov     ax,3d00h        ; Fxn 3DH = open, read only
  13.         int     21h             ; transfer to MS-DOS
  14.         jc      error           ; jump if open failed
  15.         mov     handle1,ax      ; save handle for work file
  16.  
  17.                                 ; create backup file...
  18.         mov     dx,offset file2 ; DS:DX = filename address
  19.         mov     cx,0            ; CX = attribute (normal)
  20.         mov     ah,3ch          ; Fxn 3CH = create file
  21.         int     21h             ; transfer to MS-DOS
  22.         jc      error           ; jump if create failed
  23.         mov     handle2,ax      ; save handle for backup file
  24.  
  25.         push    ds              ; set ES = our data segment
  26.         pop     es
  27.         mov     ds,bufseg       ; set DS:DX = allocated block
  28.         xor     dx,dx
  29.  
  30.         assume  ds:NOTHING,es:_DATA     ; tell assembler
  31.  
  32. next:                           ; read working file...
  33.         mov     bx,handle1      ; handle for work file
  34.         mov     cx,8000h        ; try to read 32 KB
  35.         mov     ah,3fh          ; Fxn 3FH = read
  36.         int     21h             ; transfer to MS-DOS
  37.         jc      error           ; jump if read failed
  38.         or      ax,ax           ; was end of file reached?
  39.         jz      done            ; yes, exit this loop
  40.  
  41.                                 ; now write backup file...
  42.         mov     cx,ax           ; set write length = read length
  43.         mov     bx,handle2      ; handle for backup file
  44.         mov     ah,40h          ; Fxn 40H = write
  45.         int     21h             ; transfer to MS-DOS
  46.         jc      error           ; jump if write failed
  47.         cmp     ax,cx           ; was write complete?
  48.         jne     error           ; no, disk must be full
  49.         jmp     next            ; transfer another record
  50.  
  51. done:   push    es              ; restore DS = data segment
  52.         pop     ds
  53.  
  54.         assume  ds:_DATA,es:NOTHING     ; tell assembler
  55.  
  56.                                 ; release allocated block...
  57.         mov     es,bufseg       ; segment base of block
  58.         mov     ah,49h          ; Fxn 49H = release block
  59.         int     21h             ; transfer to MS-DOS
  60.         jc      error           ; (should never fail)
  61.  
  62.                                 ; now close backup file...
  63.         mov     bx,handle2      ; handle for backup file
  64.         mov     ah,3eh          ; Fxn 3EH = close
  65.         int     21h             ; transfer to MS-DOS
  66.         jc      error           ; jump if close failed
  67.         .
  68.         .
  69.         .
  70.  
  71. file1   db      'MYFILE.DAT',0  ; name of working file
  72. file2   db      'MYFILE.BAK',0  ; name of backup file
  73.  
  74. handle1 dw      ?               ; handle for working file
  75. handle2 dw      ?               ; handle for backup file
  76. bufseg  dw      ?               ; segment of allocated block
  77.