Lind
Lind

Reputation: 243

[Emu 8086]Can't open file

The program should open the file,read from it and print the first 4 characters.

Upvotes: 0

Views: 5295

Answers (3)

Ruud Helderman
Ruud Helderman

Reputation: 11018

You are using an emulator. Your program has access to an emulated C: drive, which is not the real C: drive of your PC.

As it says on http://www.emu8086.com/ :

dos file system is emulated in \vdrive\ folder

In other words, put file f1.txt in folder c:\emu8086\vdrive\c; your program will see the file in what appears to be C:\.

If you installed emu8086 in a folder other than c:\emu8086, then obviously you will have to look for vdrive there.

Upvotes: 5

Martin Rosenau
Martin Rosenau

Reputation: 18493

If the error message prints correctly you can be sure that the DS segment register is set correctly and the problem must be before the first "int 21h".

You should open the file with a hexadecimal editor and check if the string "c:\f1.txt" is really present. Some assemblers handle backslashes in strings like C so you'll have to write two backslashes ("c:\\f1.txt") to get one backslash in the .COM file.

Upvotes: 0

Ruud Helderman
Ruud Helderman

Reputation: 11018

You should put your data (all the db stuff) underneath a .data directive, and the code under .code. In an old-fashioned .com file, it does not matter, but in an .exe, the data segment (ds) and the code segment (cs) are different, and you are supposed to tell the assembler what belongs where.

Explanation: the DOS function expects the filename to be on address ds:dx, but chances are, there is nothing there (likely just NUL characters, which is interpreted as an empty string) because the filename is on address cs:dx.

Upvotes: 0

Related Questions