asm--文件使用--比较两个文件是否内容相同

这是一个用汇编语言编写的程序,用于比较两个文本文件('hello.txt' 和 'world.txt')的内容是否一致。它首先打开文件,获取文件大小,然后逐块读取并比较文件内容,最后关闭文件并输出比较结果:匹配或不匹配。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

s1 segment
fn1 db 'hello.txt',0
fn2 db 'world.txt',0
fh1 dw ?
fh2 dw ?
buf1 db ?
buf2 db ?
test1dx dw ?
test1ax dw ?
strerror db 'error',0dh,0ah,24h
strmatch db 'match',0dh,0ah,24h
strnotmatch db 'not match',0dh,0ah,24h
s1 ends

s3 segment stack
    dw 10 dup(?)
top label word
s3 ends

s2 segment
    assume cs:s2,ds:s1,ss:s3
main proc near
    mov ax,s1
    mov ds,ax
    mov ax,s3
    mov ss,ax
    lea sp,top

    lea dx,fn1
    mov al,0
    mov ah,3dh
    int 21h
    jc error
    mov fh1,ax


    lea dx,fn2
    mov al,0
    mov ah,3dh
    int 21h
    jc error
    mov fh2,ax

    mov bx,fh1
    mov al,2
    mov cx,0
    mov dx,0
    mov ah,42h
    int 21h
    jc error
    mov test1dx,dx
    mov test1ax,ax

    mov bx,fh2
    mov al,2
    mov cx,0
    mov dx,0
    mov ah,42h
    int 21h
    jc error
    cmp dx,test1dx
    jne notmatch
    cmp ax,test1ax
    jne notmatch

    mov bx,fh1
    mov al,0
    mov cx,0
    mov dx,0
    mov ah,42h
    int 21h

    mov bx,fh2
    mov al,0
    mov cx,0
    mov dx,0
    mov ah,42h
    int 21h

circle:
    mov cx,1
    lea dx,buf1
    mov bx,fh1
    mov ah,3fh
    int 21h
    jc error
    cmp ax,0
    je match
    mov cx,1
    lea dx,buf2
    mov bx,fh2
    mov ah,3fh
    int 21h
    jc error
    cmp ax,0
    je finish
    mov al,buf1
    cmp buf1,al
    jne notmatch
    jmp circle
    

    mov bx,fh1
    mov ah,3eh
    int 21h
    jc error
    mov bx,fh2
    mov ah,3eh
    int 21h
    jc error

    jmp match



error:
    lea dx,strerror
    mov ah,09h
    int 21h

    call output
    jmp finish

match:
    lea dx,strmatch
    mov ah,09h
    int 21h
    jmp finish
notmatch:
    lea dx,strnotmatch
    mov ah,09h
    int 21h

finish:
    mov ah,4ch
    int 21h
main endp

output proc near
    push dx
    push bx
    push cx

    test ax,8000h
    jz  start
    push ax
    mov dl,2dh
    mov ah,02h
    int 21h
    pop ax
    neg ax

start:
    xor cx,cx
    mov bx,10
here:
    cwd
    div bx
    push dx
    inc ch
    cmp ax,0
    jne here

    mov cl,8
there:
    pop dx
    and dx,00ffh
    add dl,30h
    mov ah,02h
    int 21h
    dec ch
    cmp ch,0
    ja there

    pop cx
    pop bx
    pop dx

    ret
output endp



s2 ends
    end main


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值