组装,中断#21,4eh,4fh问题!

时间:2011-04-13 18:10:01

标签: assembly file dos root interrupt

有人可以告诉我如何使用这些功能吗? int 21h,4eh,4fh(MS Dos

我想列出文件和目录......我该怎么做?

我希望有人可以给我一个源代码或int21h 4eh / 4fh的例子..

提前致谢

2 个答案:

答案 0 :(得分:3)

嗯......现在这里有一些古老的代码:

.model small, c

.stack

.data
    file_spec db "*.*", 0
    DTA db 128h dup(0)

.code
main proc
    mov ax, @Data
    mov ds, ax
    mov dx,offset DTA
    mov ah,1Ah
    int 21h

    mov dx,offset file_spec
    xor cx, cx
    mov ah,4Eh
    int 21h
    jc  quit

print_name:
    lea si, DTA + 1eh
next_char:
    lodsb
    int 29h
    test al, al
    jnz next_char

    mov al, 13
    int 29h
    mov al, 10
    int 29h

    mov dx, offset file_spec
    xor cx, cx
    mov ah, 4fh
    int 21h
    jnc print_name
quit:   
    mov ax, 4c00h
    int 21h
main endp
    end main

正如你所看到的,在我年轻的时候,我真的相信很多评论(不过,我不得不承认,即使现在看着它,也不会特别难以理解)。

答案 1 :(得分:2)

功能4eh找到匹配某些属性的第一个文件,根据以下方案存储在cx中:

bit 0 = 1 read-only file
bit 1 = 1 hidden file
bit 2 = 1 system file
bit 3 = 1 volume (ignored)
bit 4 = 1 reserved (0) - directory
bit 5 = 1 archive bit
bits 6-15 reserved (0)

ds:dx应包含(以null结尾的)文件名的地址(允许使用wildchars)。例如,要列出c:\中的所有exes,文件名将为c:\*.exe 返回时,如果进位标志设置为1则没有文件,否则DTA以这种方式填充:

Offset   Size in bytes   Meaning

0        21              Reserved
21       1               File attributes
22       2               Time last modified
24       2               Date last modified
26       4               Size of file (in bytes)
30       13              File name (ASCIIZ)

你可以通过这个简单的片段告诉DOS你想要放置DTA的位置:

mov dx,OFFSET youChoose     ; DS:DX points to DTA 
mov ah,1AH               ; function 1Ah - set DTA
int 21h                     ; call DOS service