Configuration :
MS-DOS 16 BIT (writing in a .asm file, then compiling them with TASM and TLINK)
Windows 7 x64
I've made a simple program in Assembly that should only OPEN a file and write a text to it.
Here is the code to it:
assume cs:code, ds:data
data segment
fileName db "input.txt", 0 ; We assure it is an ASCIIZ(ero) file.
toWrite db "Hello World!", "$"
data ends
code segment
writeToFile:
; pentru functia 3Dh
mov AH, 3Dh
mov AL, 0h
mov dx, offset fileName
int 21h
ret
start_program:
mov ax, data
mov ds, ax
CALL writeToFile
mov ax, 4c00h
int 21h
code ends
end start_program
I used TurboDebugger to see what happens. Strangely, it always puts in AX
value 0005
meaning Access Denied
Everything I could find on the internet for searching ASSEMBLY access denied open file
was about DLL
's and that did not help.
I've tried anything, from restarting my program to opening dosbox "As an administrator". Sadly, nothing worked and I am out of ideas.
What's also strange is, that a friend of mine said that after activating his windows 10, everything worked just fine.
What is the reason for getting only "access denied"? I mention that I was able to create, delete and close files, but I cannot open them.
For proper operation your writeToFile procedure needs to
What I noticed is that you terminate the text that you'll be writing in this file with a "$". I wonder if you know that the DOS function to actually write the file only works with a specified length in
CX
and not with any kind of delimiter. You could have other valid reasons for this "$" character -;Where you place the NOK label and what you do there entirely depends on how much effort you want to spent in dealing with errors returned by DOS. Here in this very simple program, you might just return from the
call
and have the program terminate.