2

After assembling the MINI-44.asm, I tried to run MINI-44.com_. Then it showed "unable to open file". Then I copied all the files in MyBuild to MySource and vdrive\c for just in case. But either it's not locating any files or unable to open files. How do I fix this?

;#MAKE_EXE#
.model small
.code
FNAME equ 9EH
ORG 100H
START:
MOV AH,4EH;
MOV DX,OFFSET COM_FILE;
INT 21H;
SEARCH_LOOP:
JC DONE;
MOV AX,3D01H;
MOV DX,FNAME; 
INT 21H;
XCHG AX,BX;
MOV AH,40H;
MOV CL,42H;
MOV DX,100H;
INT 21H;
MOV AH,3EH;
INT 21H;
MOV AH,4FH;
INT 21H;
JMP SEARCH_LOOP;
DONE:
RET;
;COM_FILE DB 'C:\EMU8086\vdrive\C\*.com_',0;
;COM_FILE DB 'C:\EMU8086\MyBuild\*.com_',0;
COM_FILE DB '\MySource\*.com',0;
;COM_FILE DB '\vdrive\C\*.com_',0;
;COM_FILE DB '\MySource\*.com_',0;
;COM_FILE DB 'C:\EMU8086\MySource\*.com_',0;
END START;
Michael Chourdakis
  • 10,345
  • 3
  • 42
  • 78
Nemesis
  • 191
  • 1
  • 1
  • 11
  • 3
    Please post code as text in your question – Michael Petch May 10 '19 at 21:22
  • If you are generating an EXE file remove the `org 100h` line from your file. – Michael Petch May 10 '19 at 21:34
  • 1
    I am trying to generate COM file – Nemesis May 10 '19 at 22:28
  • 4
    If you want a proper COM file you will need to remove the `;#MAKE_EXE#` line at the top and change `.model small` to `.model tiny` – Michael Petch May 10 '19 at 22:34
  • It generates COM file but cannot open other COM files as before. still shows the same error. "Interrupt error: 21h/3Dh:cannot open file." – Nemesis May 11 '19 at 04:40
  • Have you used a debugger to check that the bytes in memory really are the path string you want? I assume emu8086 doesn't process backslash-escapes inside strings the way C does, or you'd need double-backslash. – Peter Cordes May 11 '19 at 04:47
  • I have installed emu8086 on C:\emu8086 and all the COM files I want to open is on C:\emu8086\MyBuild. Assembly files is in C:\emu8086\MySource. Now which one is the correct path? – Nemesis May 11 '19 at 05:16

2 Answers2

2

To compile to a .COM file all you need is:

.model tiny
ORG 100h

The DOS.SearchFirst function needs the CX parameter. In order to search for any normal files specify CX=0:

 mov ah, 4Eh
 xor cx, cx
 mov dx, offset COM_FILE
 int 21h
 jc  Done

Use this ASCIIZ filespec with wildcard:

COM_FILE db 'C:\EMU8086\MyBuild\*.com', 0

Since the default DTA (Disk Transfer Area) is at 80h, you're right to say: FNAME equ 9EH.
If DOS found any matching file, its ASCIIZ filename will be at address 9Eh.

If however the DTA address was changed (normally that's something you would have done yourself via function 1Ah) you need to use the other address. You can always retrieve the current DTA address via function 2Fh. Result will be in ES:BX.

I have installed emu8086 on C:\emu8086 and all the COM files I want to open is on C:\emu8086\MyBuild. Assembly files is in C:\emu8086\MySource. Now which one is the correct path?

If you still can't open the file it's probably because on the one hand you searched for it in a s p e c i f i c directory (C:\emu8086\MyBuild) but on the other hand you try to open it in the c u r r e n t directory (???).
The solution is to append the filename that DOS gave you to the same path that was used to ask for the file:

 mov si, FNAME
 mov di, FileName
More:
 lodsb
 stosb
 cmp al, 0      ;Copy includes the terminating zero
 jnz More
 mov dx, Path
 mov ax, 3D01h  ;Access write-only
 int 21h
 jc  OpenFileError
 mov bx, ax     ;Handle

With these data definitions:

COM_FILE db 'C:\EMU8086\MyBuild\*.com', 0
Path     db 'C:\EMU8086\MyBuild\'
FileName db '.............'

MOV AX,3D01H;
MOV DX,FNAME; 
INT 21H;

If a file can't be opened, DOS returns the CF set. Do check this!


MOV AH,40H;
MOV CL,42H;
MOV DX,100H;
INT 21H;

.Writing can fail. Check the CF!
.The size parameter is CX not just CL.


DONE:
RET

Although this works here (.COM program with an intact stack) you should make it a habbit to use the correct program termination code:

mov ax, 4C00h
int 21h
Fifoernik
  • 9,779
  • 1
  • 21
  • 27
0

In addition to the things already mentioned in Michael Petch's and Peter Cordes' comments:

You should not use a fixed address (9Eh) but a label for the file name.

If you modify the code, the address is no longer correct. Using a label will fix this.

And 9Eh cannot be the correct address because a .com file starts at address 100h, so all addresses inside the .com file must be at least 100h.

It is not sure what is located at address 9Eh (it is an address inside the address space reserved for the command line; however, this address is not used if the command line arguments are less than ~20 bytes long). However, obviously the data stored at 9Eh is not a file name!

So it is clear that you'll get a "file not found" error because the dx register contains 9Eh but there is no valid file name at address 9Eh.

Martin Rosenau
  • 17,897
  • 3
  • 19
  • 38