在这个简单的汇编程序中找不到错误

时间:2012-02-28 06:35:15

标签: file assembly writetofile file-search

我正在使用以下16位汇编代码:

            .model tiny
            .code

            ORG 100H

FILE_NAME       EQU 9EH     ;DTA Position after execution of search_first_file

START:          
            mov     ah,9            ;Print start message
            mov dx,OFFSET STR_START
            int 21H

            mov     ah,4EH      ;Search first file
            mov dx,OFFSET PATH
            int 21H
            jc  NO_FILE_FOUND

FILE_FOUND: 
            mov     ah,9            ;Print file found message
            mov dx,OFFSET STR_FILE_FOUND
            int 21H     

            mov ah,3DH      ;Open file to write
            mov al,01H
            mov dx,FILE_NAME
            int 21H

            mov     ah,9            ;Print file opened message
            mov dx,OFFSET STR_FILE_OPENED
            int 21H     

            mov ah,40H      ;Write code
            mov bx,ax
            mov dx,100H
            mov cx,44
            int 21H

            mov     ah,9            ;Print file written message
            mov dx,OFFSET STR_FILE_WRITTEN
            int 21H     

            mov ah,3EH      ;Close file
            int 21H

            mov ah,4FH      ;Search next
            int 21H
            jnc FILE_FOUND          

NO_FILE_FOUND:
            ret

PATH                db      'C:\comfiles_folder\HOST.COM',0
STR_START       db  'program started!',0
STR_FILE_FOUND  db  'file found!',0
STR_FILE_OPENED db  'file opened!',0
STR_FILE_WRITTEN    db  'code written!',0

            END START

此程序基本上搜索路径comfiles_folder上的文件夹C:\comfiles_folder\HOST.COM,并将自己的代码写入找到的文件。

我使用CodeView对其进行了调试,发现它无法找到HOST.COM文件。有人可以告诉我有什么问题吗?

1 个答案:

答案 0 :(得分:1)

Find First File调用需要一个参数。 在Int 21 0x4E(查找Fist文件)调用之前,您没有在寄存器cx中设置file attributes