1
我正在爲一個學校項目和我的assigments幾句話的工作需要找到與給定的擴展名(* .txt,* .exe等)相匹配的文件並打印出來該文件的大小,日期,文件名等。到目前爲止,我已經成功地找到了文件並設置了DTA。當涉及到文件名時,一切都很好,但當我不得不打印尺寸或日期時,我正在掙扎。我認爲他們是二進制的權利?我如何將它們從二進制文件解碼爲難以忍受的格式?彙編DTA文件的屬性,大小,名稱等
;This is my DTA start----------------------------------
DTA db 15h dup (0)
fatt db 0 <-------------
ftime db 0,0 <------------ how do I decode these????
fdate db 0,0 <-------------
fsize db 4 dup (0) <-----------
fname db 13 dup (0)
;DTA end-----------------------------------------
這就是我的代碼,但它是凌亂的和正在進行的工作。
.model small
.stack 100h
.data
;This DTA start----------------------------------
DTA db 15h dup (0)
fatt db 0
ftime db 0,0
fdate db 0,0
fsize db 4 dup (0)
fname db 13 dup (0)
;DTA end-----------------------------------------
extension db 12 dup (0)
sourceFHandle dw ?
testas db "C:\ATI\",0
directory db 64 dup (0)
writefile db "C:\menulis.txt",0
writehandle dw ?
buffer db 20 dup (?)
simbolis db ?
.code
START:
mov ax, @data
mov es, ax ; es kad galetume naudot stosb funkcija: Store AL at address ES:(E)DI
mov si, 81h ; programos paleidimo parametrai rasomi segmente es pradedant 129 (arba 81h) baitu
call skip_spaces
_2:
;; extension nuskaitymas
lea di, extension
call read_filename ; perkelti is parametro i eilute
cmp byte ptr es:[extension], '$' ; jei nieko nenuskaite
jne _3
_3:
;; directory nusk
lea di, directory
call read_filename ; perkelti is parametro i eilute
push ds
push si
mov ax, @data
mov ds, ax
;nustatom DTA
mov ah,1ah
mov dx, offset DTA
int 21h
;; rasymui sukuria faila
mov dx, offset writefile ; ikelti i dx destF - failo pavadinima
mov ah, 3ch ; isvalo/sukuria faila - komandos kodas
xor cx,cx ; normal - no attributes
int 21h ; INT 21h/AH= 3Ch - create or truncate file.
; Jei nebus isvalytas - tai perrasines senaji,
; t.y. jei pries tai buves failas ilgesnis - like
; CF set on error AX = error code.
; atidaro faila
mov dx,offset writefile
mov al,2
mov ah,3dh
int 21h
mov writehandle,ax
;keicia direktorija
mov ah,3bh
mov dx,offset directory
int 21h
;iesko failo
mov ah,4eh
mov cx,0
lea dx,extension
int 21h
call write_to_file
;raso i faila duomenis
; lea dx,fname
; mov bx,writehandle
; mov ah,40h
; mov cx, 13
;int 21h
find_next:
mov ah,4fh
lea dx,extension
int 21h
call write_to_file
;uzdaryti faila
mov ah,3eh
mov bx,writehandle
int 21h
mov ah,9h
mov dx,offset directory
int 21h
mov ah, 4ch
mov al, 0
int 21h
;; procedures
skip_spaces PROC near
skip_spaces_loop:
cmp byte ptr ds:[si], ' '
jne skip_spaces_end
inc si
jmp skip_spaces_loop
skip_spaces_end:
ret
skip_spaces ENDP
read_filename PROC near
push ax
call skip_spaces
read_filename_start:
cmp byte ptr ds:[si], 13 ; jei nera parametru
je read_filename_end ; tai taip, tai baigtas failo vedimas
cmp byte ptr ds:[si], ' ' ; jei tarpas
jne read_filename_next ; tai praleisti visus tarpus, ir sokti prie kito
read_filename_end:
mov al, 0 ; irasyti 0 gale
stosb ; Store AL at address ES:(E)DI, di = di + 1
pop ax
ret
read_filename_next:
lodsb ; uzkrauna kita simboli
stosb ; Store AL at address ES:(E)DI, di = di + 1
jmp read_filename_start
read_filename ENDP
write_to_file PROC near
lea dx,fname
mov bx,writehandle
mov ah,40h
mov cx,13
int 21h
ret
write_to_file ENDP
end START
這個'add ax,50h; Y2K問題?'不會顯示正確的一年!由於假設年份在2000年後是安全的,所以最好從這個7位年份字段中減去20。 –
爲什麼不簡化代碼'stosb'' mov al,ah''stosb'到一個'stosw'?對於兩個頂級域(年和小時)的ANDING也是多餘的,因爲下一個SHIFTING RIGHT將給出所需的零。 –
謝謝!這讓我走上了正確的道路 – Aivaras