1

I am working with the following 16-bit assembly code:

            .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

This program basically searches the folder comfiles_folder at the path C:\comfiles_folder\HOST.COM and writes its own code to the file that is found.

I debugged it using CodeView and found out that it is not able to find the HOST.COM file. Can someone please tell me what is wrong?

user904832
  • 557
  • 1
  • 6
  • 10

1 Answers1

1

Find First File call needs one parameter more. You didn't set file attributes in register cx before Int 21 0x4E (Find Fist File) call.

GJ.
  • 10,810
  • 2
  • 45
  • 62