我有一个程序可以找到目录中最旧的文件 但我无法保存文件的名称,即显示它。 我无法理解它可以保存的地方。我可以在dw中保存日期,但是如何保存文件名。 这是整个代码:
.model small
.stack 64
.data
path db '*.*',0
dta db 256 DUP(?)
er1 db ""
Str db 'Successfully$',0
fdate dw 0FFFFH
ftime dw 0FFFFH
.code
start:
mov ax,@data
mov ds,ax
xor ax,ax
mov ah,0
mov al,2
int 10h
lea dx,dta
mov ah,1AH
int 21h
mov ah,4EH
lea dx,path
mov cx,0
int 21h
lea bx,dta
add bx,18h
mov dx,[bx]
mov [fdate],dx
lea bx,dta
add bx,16h
mov dx,[bx]
mov [ftime],dx
NEXT_LINE:
lea bx,dta
add bx,18h
mov dx,[bx]
lea bx,dta
add bx,16h
mov cx,[bx]
cmp dx,[fdate] ; if dx < [fdate]
jc CompareDate
cmp dx,[fdate] if dx = [fdate]
je CompareTime
back:
lea dx,path
mov ah,4FH
int 21h
jc FINISHED
jmp SHORT NEXT_LINE
CompareDate:
mov fdate,dx ; Save date
mov ftime,cx ; Save time
jmp back
CompareTime:
cmp cx,[ftime]
jc Swap ;if cx < [ftime] : swap
jmp back
Swap:
mov ftime,cx
lea bx,dta
add bx,16h
mov dx,[bx]
jmp back
FINISHED:
;Here I want to display a file name
int 21h
mov dx,offset Str
mov ah,09h
int 21h
mov dx,[fdate] ; For a debugger
mov cx,[ftime] ; For a debugger
mov ax,4c00h
int 21h
end start
答案 0 :(得分:1)
如果要保存多个值,则必须使用循环。 8086
有一个用于复制一堆字节/单词的简短形式:rep movsb
(字节)&amp; rep movsw
(字)。我建议你将整个当前最古老的DTA(从FindNext获得)复制到一个&#34; shadow&#34; DTA。最后,您将获得最旧文件的DTA,并最终可以计算其中的任何信息:
.MODEL small
.STACK 1000h
.DATA
dta db 128 DUP(?)
dta_hold db 128 DUP(?)
path db "*.*",0
LF db 13,10,'$'
.CODE
main PROC
mov ax, @data
mov ds, ax
mov es, ax ; for movsw
lea dx, dta ; dta: disk transfer area
mov ah, 1AH ; SET DISK TRANSFER AREA ADDRESS
int 21h ; DOS INTERRUPT
mov ah, 4EH ; FIND FIRST MATCHING FILE
lea dx, path ; DS:DX -> ASCIZ file specification (may include path and wildcards)
mov cx, 0 ; file attribute mask
int 21h ; DOS INTERRUPT
call store_dta
call print_filename ; print the first filename
FindNext:
mov ah, 4FH ; FIND NEXT MATCHING FILE
int 21h ; DOS INTERRUPT
jc Finish
; compare filedates & filetimes
lea si, dta_hold ; DTA of the oldest file
lea di, dta ; DTA of the just found file
mov ax, [si+18h] ; filedate
mov bx, [di+18h] ; filedate
cmp ax, bx
jc FindNext ; just found file is newer
jne Older
; filedates are identical
mov ax, [si+16h] ; filetime
mov bx, [di+16h] ; filetime
cmp ax, bx
jc FindNext
Older: ; just found file is older
call store_dta ; copy dta to dta_hold
jmp FindNext
Finish:
call print_filename ; print the last filename
mov ax,4c00h
int 21h
main ENDP
store_dta PROC
mov cx, (128/2) ; size of DTA in WORDs (half of BYTEs)
lea si, dta
lea di, dta_hold
rep movsw ; copy CX times DS:SI => ES:DI
ret
store_dta ENDP
print_filename PROC
lea di, dta_hold + 1Eh
mov dx, di ; start of filename
_B: ; look for NULL (ASCIZ-termination)
cmp BYTE PTR [di], 0
je _F
inc di
jmp _B
_F: ; replace NULL by '$'
mov [di], BYTE PTR '$' ; end-of-string delimiter for INT 21h/09h
mov ah, 09h ; WRITE STRING TO STANDARD OUTPUT
int 21h ; DOS INTERRUPT
lea dx, LF ; new line
mov ah, 09h ; WRITE STRING TO STANDARD OUTPUT
int 21h ; DOS INTERRUPT
ret
print_filename ENDP
END main