2012-12-09 20 views
1

我想打印當前的工作目錄及其內容。該程序將使用x86,16位Intel語法,使用中斷的DOS彙編完成。我將使用的彙編程序將是Turbo彙編程序。這裏是我的代碼到目前爲止(不多):在程序集中列出目錄內容?

ASSUME cs:code, ds:data 
data segment 
buffer db 64 dup (0) ; buffer for the current directory name 
data ends 
code segment 
start: 
mov  ax,  data ; 
mov  ds,  ax ; move data segment into ds, es registers 
mov  es,  ax ; 

mov  dl,  0    ; default drive 
mov  si,  offset buffer ; put current directory in buffer 
mov  ah,  47h ; GET CURRENT DIRECTORY 
int  21h     

; appending '$' to buffer end 
    ; search until 0 found 
mov  cx,  64 ; search over all buffer 
cld         ; starting from the beginning 
    end_string:       
lodsb        ; get current byte in al register 
cmp  al,  0 ; compare it with 0 
jne  continue     ; if not equal jump to continue label 
mov  al,  36 ; if equal copy 36('$' - ASCII) in al 
mov  di,  si ; set destination index to source index 
sub  di,  1   ; decrement di 
stosb        ; store in es:di the value contained in al 
mov  cx,  1 ; stop looping by setting cx to 1 
    continue: 
    loop end_string 
    ; print string obtained 
mov  dx,  offset buffer ; ds:dx - string start 
mov  ah,  09h   ; WRITE STRING TO STANDARD OUTPUT 
int  21h 

mov  ax,  4c00h   ; end program with exit code 0 
int  21h 
    code ends 
    end start 

我設法讓它運行並顯示當前的工作目錄。但現在我不知道如何獲得他的子目錄和目錄中包含的文件。所以我的問題是:我如何得到它們?

回答

1

使用DOS服務FindFirst0x4e)和FindNext0x4f),以獲得在給定的目錄項的列表。然後您可以根據返回的屬性區分子目錄和文件。

1

但在調用「FindNext」之前獲取DTA。
DTA - 磁盤傳輸面積:http://stanislavs.org/helppc/dta.html

RBIL-> inter61b.zip-> INTERRUP.F

--------D-212F------------------------------- 
INT 21 - DOS 2+ - GET DISK TRANSFER AREA ADDRESS 
AH = 2Fh 
Return: ES:BX -> current DTA 
Note: under the FlashTek X-32 DOS extender, the pointer is in ES:EBX 
SeeAlso: AH=1Ah 

德克