我在Stack Overflow中进行了深入搜索,但是找不到类似我的问题。我的问题如下:我正在TASM Assembly中编写一个程序,查找扩展名为.fly的文件,最后程序会写一条消息说:'布什在这里'。
我已经检查了打开和写入文件的例程,如果我单独测试它们,它们可以正常工作。但是,当我在int 21h使用Find first / Find next时,我无法获取文件。我相信问题位于查找第一个/查找下一个函数,但我不知道错误是什么。源代码编译得很好。请帮我!!这是我的来源:
.model tiny
.code
start:
call delta ;Now We get the delta offset
delta:
pop bp
sub bp, offset delta
mov ax, @code ;Get the address of code segment and store it in ax
mov ds, ax ;Put that value in Data segment pointer.
;Now, we can reference any data stored in the code segment
;without fail.
lea dx,[bp+newDTA] ;DS:DX points to DTA
mov ah,1ah ;function 1Ah - set DTA
int 21h ;call DOS service
mov cx,7 ; attribute mask - all files
lea dx,[bp+file_extension]; DS:DX points ASCIZ filename
mov ah,4eh ; function 4Eh - find first
;check this
file_remainder:
int 21h ; ;call DOS service
jc exit ;If carry flag is set, jumps to exit
;That means that if no there are more files to write
;exits.
call open ;Open
call move_pointer_to_end
call concatenate_sign
call close
mov ah,4Fh ; function 4fh - find next
jmp file_remainder
;Subroutines
open:
mov ax, 3D02H ;Opens a file
lea dx, [bp+newDTA+30h];Filename
int 21h ;Call DOS interrupt
mov [bp+handle], ax ;Save the handle in variable
ret
move_pointer_to_end:
mov bx, [bp+handle]
mov ax,4202h ; Move file pointer
xor cx,cx ; to end of file
cwd ; xor dx,dx
int 21h
ret
concatenate_sign:
mov ax, 4000H ;Write function
mov bx, [bp+handle] ;Put in bx, the handle
lea dx, [bp+sign]
mov cx, 16
int 21H
ret
close:
mov ah,3eh ;Close file function
int 21h
ret
exit:
mov ah,4Ch ;Terminate process
mov al,0 ;Return code
int 21h
datazone:
handle dw ?
sign db 'Bush was here!! ', 0
newDTA db 128 dup (?)
file_extension db '*.fly', 0
end_of_file:
end start
请帮帮我。如果我在打开文件中使用它们,则查找第一个/查找下一个函数,正确显示其路径。