Reputation: 243
The program should open the file,read from it and print the first 4 characters.
I can't figure out what the problem is.I even created the file myself there and it still cannot open the file.
org 100h
jmp start
filename db "C:\f1.txt",0
errormessage: db "Ndodhi nje gabim gjate ekzekutimit$"
Buffer db 50h dup(?)
start:
lea dx,filename
mov ah,3Dh
mov al,0
int 21h
jc error
mov bx,ax
mov ah,3Fh
mov cx,4
lea dx,Buffer
int 21h
jmp end
error:mov dx,offset errormessage
mov ah,09h
int 21h
end: ret
Upvotes: 0
Views: 5295
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
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
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