home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / COMPARF.ASM < prev    next >
Assembly Source File  |  1994-10-27  |  2KB  |  111 lines

  1.     page    66,132
  2. ;******************************* COMPARF.ASM ********************************
  3.  
  4. LIBSEG           segment byte public "LIB"
  5.         assume cs:LIBSEG , ds:nothing
  6.  
  7. ;----------------------------------------------------------------------------
  8. .xlist
  9.     include  mac.inc
  10.     include  common.inc
  11.  
  12.     extrn    dos_mem_allocate:far
  13.     extrn    dos_mem_release:far
  14. .list
  15. comment 
  16. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( COMPARE )
  17. ;COMPARE_FILES - compares two files
  18. ;
  19. ; inputs:   DS:[SI] = address of file1 asciiz
  20. ;           DS:[DI] = address of file2 asciiz
  21. ; output:  AX = 0 if successful compare
  22. ;* * * * * * * * * * * * * *
  23. 
  24.  
  25. file1_handle    dw    0
  26. file2_handle    dw    0
  27.  
  28. read_amount1    dw    0
  29.  
  30. file1_name    db    30 dup (0)
  31. file2_name    db    30 dup (0)
  32.  
  33. buffer_length    equ    4000h
  34. file1_buf    equ    0        ;
  35. file2_buf    equ    4000h        ;
  36.  
  37.     public    compare_files
  38. compare_files    proc    far
  39.    apush   bx,cx,dx,si,di,ds,es
  40.    mov       dx,0
  41.    mov     ax,8000h
  42.    call    dos_mem_allocate
  43.    
  44.    cld    
  45.    MOV     DX,si
  46.    MOV       AX,3D00h            ;open file
  47.    INT     21h
  48.    JB      error
  49.    mov       cs:file1_handle,ax
  50.  
  51.    mov       dx,di
  52.    MOV       AX,3D00h            ;open file
  53.    INT     21h
  54.    JB      error
  55.    mov       cs:file2_handle,ax
  56.  
  57.    push    es
  58.    pop     ds                ;point at buffers
  59.  
  60. cmp_loop:   
  61.    MOV       AH,3Fh            ;read file
  62.    MOV     BX,cs:file1_handle
  63.    mov       dx,file1_buf
  64.    mov       cx,buffer_length
  65.    int       21h
  66.    mov     cs:read_amount1,ax
  67.    OR      AX,AX
  68.    JZ      done_ok
  69.  
  70.    MOV       AH,3Fh            ;read file
  71.    MOV     BX,cs:file2_handle
  72.    mov       dx,file2_buf
  73.    mov       cx,buffer_length
  74.    INT     21h
  75.    cmp       cs:read_amount1,ax
  76.    jne     error            ;jmp if different length files
  77.    OR      AX,AX
  78.    JZ      done_ok
  79.  
  80.     mov    si,offset file1_buf
  81.     mov    di,offset file2_buf
  82.     mov    cx,ax
  83.     cld
  84.     rep    cmpsb
  85.     jne    error
  86.     jmp    cmp_loop
  87.     
  88. done_ok:
  89.     mov    ax,0
  90.     jmp    exit
  91. error:
  92.     mov    ax,1    
  93. exit:
  94.     push    ax            ;save error code (al)
  95.         MOV     BX,file1_handle
  96.         MOV    AH,3Eh            ;close file
  97.         INT     21h
  98.         MOV     BX,file2_handle
  99.         MOV    AH,3Eh            ;close file
  100.         INT     21h
  101.         call    dos_mem_release
  102.     pop    ax
  103.     apop    es,ds,di,si,dx,cx,bx
  104.     retf
  105. compare_files    ENDP
  106. ;------------------------------------------------------------------------
  107.  
  108. LIBSEG    ENDS
  109.     end
  110.