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
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