1

我正在为一个学校项目使用程序集,我的任务需要找到与给定扩展名(*.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
4

1 回答 1

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

那是来自 Nasm 语法(不应该打扰你吗?)而不是我是怎么做的,所以可能存在复制错误,但如果幸运的话,你会指出正确的方向(?)

于 2015-11-11T05:53:30.370 回答