使用 Int 21h ah=4eh/4fh:程序找到第一个文件但没有找到其他文件

Using Int 21h ah=4eh/4fh: Program finds first file but not others

我的程序在给定目录中找不到下一个文件。如果它们可能是问题的一部分,我会包括我的所有程序。我的程序成功找到了目录中的第一个文件,但未能尝试找到另一个文件。 (是的,这个程序没有输出,它只是找到文件并打开它,但是在调试器上可以看到错误)

这是我的代码:

.model small
skaitymodydis   EQU 20          ;reading buffer size
.stack 1000h    
.data
zodis   db "hello", 0           ;searched word
dir db "P:\test\kazkas3", 0     ;directory path
fname db "index.html", 0        ;index file name
fhand dw ?                      ;index file handler
dhand dw ?                      ;other files handler
duom db "*.*", 0                ;searched file name
DTA db 128 (0)              
skbuf   db skaitymodydis dup (?);reading buffer
wrongg db "mistake"
eilutesnr dw 0001h              ;row number
naujaeilute db 13,10            ;new line
.code
start:
mov dx, @data
mov ds, dx

mov dx, offset DTA
mov ah, 1Ah
int 21h

mov dx, offset dir           ;DS:DX path-name
mov ah, 3Bh
int 21h
call kurtindex              ;creating index file procedure

call findfirst              ;finding first file procedure
call atidaryti              ;opening that first file
jmp skaityk                 ;start reading from file and working with its symbols
kitasfailas:
xor ax, ax
xor bx, bx
xor cx, cx
xor dx, dx
xor si, si 
xor di, di 

call findnext               ;finding next file; ERROR Place
call atidaryti              ;opening next files
skaityk:
mov bx, dhand               
call skaityti               ;reading symbols from file
call pilindex               ;filling index file procedure
call duomend                ;closing file procedure(not index)
jmp kitasfailas             ;trying to find another file
call indexend               ;closing index file
pabaiga:    
mov ah, 4ch
mov al, 0
int 21h

;***********************
;index failo pildymas
;***********************
proc pilindex
xor si, si
xor bx, bx
xor cx, cx
mov bx, fhand
mov cx, 7
mov dx, offset DTA+30  
mov ah, 40h
int 21h
mov bx, fhand
mov cx, 5
mov dx, offset zodis
mov ah, 40h
int 21h


mov cx, 2
mov bx, fhand
mov dx, offset naujaeilute
mov ah, 40h
int 21h
ret
pilindex endp
;***********************
;index failo sukurimo PROCEDURA
;***********************
proc kurtindex
mov cx, 0h
mov dx, offset fname
xor ax, ax
mov ah, 3Ch
int 21h
mov fhand, ax
ret
kurtindex endp

;***********************
;duomenu failo atidarymo PROCEDURA
;***********************
proc atidaryti
mov ah, 3Dh
mov al, 0
mov dx, offset DTA+30
int 21h
;jc wrong
mov dhand, ax
ret 
atidaryti endp
;***********************
;PROCEDURA nuskaitanti is failo
;***********************
proc skaityti
push cx
push dx
push bx 
mov bx, dhand
mov ah, 3Fh
mov cx, skaitymodydis
mov dx, offset skbuf
int 21h
jc skaitymoklaida

skaitytipab:
pop bx
pop dx
pop cx
ret

skaitymoklaida:
mov ax, 0
jmp skaitytipab
skaityti endp   

;***********************
;PROCEDURA find first
;***********************
proc findfirst

mov dx, offset duom
xor cx, cx
mov ah, 4Eh
int 21h
ret 
findfirst endp
;***********************
;PROCEDURA find next
;***********************
proc findnext
mov dx, offset duom
xor cx, cx
mov ah, 4Fh
int 21h
ret
findnext endp
;***********************
;duomenu failo uzdarymo PROCEDURA
;***********************
proc duomend
mov ah, 3Eh
mov bx, dhand
int 21h
ret
duomend endp
;***********************
;index failo uzdarymo PROCEDURA
;***********************
proc indexend
mov ah, 3Eh
mov bx, fhand
int 21h
 ret
indexend endp
end start

我认为最明显的问题与您如何定义 DTA 区域有关:

DTA db 128 (0)  

这似乎创建了一个用 128+(0)=128 初始化的单字节。我认为您打算创建一个零填充的 128 字节缓冲区。你应该用过:

DTA db 128 DUP(0) 

这可能会导致使用 DTA 的中断例程破坏您的数据区,从而导致无法正常工作。