我正在为一个学校项目的汇编工作,我的几个单词的分配需要找到与给定扩展名(* .txt,* .exe等)匹配的文件,并打印出该文件的大小,日期,文件名等到目前为止,我已成功找到文件并设置了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
答案 0 :(得分:0)
我忘记了。看起来像其他人一样。我记得,大小只是一个32位的数字。您应该能够找到一些可以执行此操作的文本例程。时间和日期有点奇怪。让我看看我能找到什么......
; 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
; 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
这是来自Nasm语法(不应该打扰你?)而不是我是怎么做的,所以可能有复制错误,但幸运的话会让你指向正确的方向(?)