【问题标题】:Listing directory content in assembly?在程序集中列出目录内容?
【发布时间】:2012-12-09 13:06:36
【问题描述】:

我想打印当前工作目录及其内容。该程序将在 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   

我设法让它运行并显示当前工作目录。但是现在我不知道如何获取他的子目录以及目录中包含的文件。所以我的问题是:我如何得到它们?

【问题讨论】:

    标签: assembly x86 dos interrupt directory


    【解决方案1】:

    使用 DOS 服务 FindFirst (0x4e) 和 FindNext (0x4f) 获取给定目录中的条目列表。然后,您可以根据返回的属性区分子目录和文件。

    【讨论】:

      【解决方案2】:

      但在调用“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
      

      德克

      【讨论】:

        猜你喜欢
        • 2019-02-27
        • 2010-12-16
        • 1970-01-01
        • 2013-12-07
        • 2019-01-11
        • 2011-06-10
        • 1970-01-01
        • 2015-05-24
        • 2021-06-22
        相关资源
        最近更新 更多