I'm working with assembly for a school project and my assigments in few words requires to find files that match the given extension (*.txt, *.exe etc) and print out that file's size, date, file name etc. So far I've managed to successfully find files and set up the DTA. Everything is fine when it comes down to file name but I'm struggling when I have to print out size or date. I assume they're in binary right? How do I decode them from binary to a undestandable format?
;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-----------------------------------------
Thats my code but it's messy and a work in progress.
.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
I forget. Looks like everybody else does, too. As I recall, the size is just a 32-bit number. You should be able to find some number to text routine that will do that. Time and date are a little weird. Let me see what I can find...
; es:di points to text buffer
mov ax, [date]
and ax, 1E0h ; month
shr ax, 5
call show_2_dec
mov al, '/'
stosb
mov ax, [date] ; again
and ax, 1Fh ; day
call show_2_dec
mov al, '/'
stosb
mov ax, [date] ; again
and ax, 0FE00h ; year
shr ax, 9
add ax, 50h ; Y2K problem?
call show_2_dec
mov al, 0 ; or '$' - terminator
stosb
; and print it
; new buffer in es:di?
mov ax, [time]
and ax, 0F800h ; hours
shr ax, 0Bh
call show_2_dec
mov al, ':'
stosb
mov ax, [time]
and ax, 7E0h ; minutes
shr ax, 5
call show_2_dec
mov al, ':'
stosb
mov ax, [time]
and ax, 1Fh ; seconds/2
shl ax, 1 ; seconds
call show_2_dec
; terminate and print
;
show_2_dec:
aam
xchg al, ah
or ax, 3030h
stosb
mov al, ah
stosb
ret
That's from Nasm syntax (shouldn't bother you?) and not exactly how I did it, so there are probably copying errors, but with luck will get you pointed in the right direction(?)