Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't read a byte from a file

Status
Not open for further replies.

McBugzz

Programmer
Sep 17, 2002
90
JP
I'm trying to read a byte from a file.

I open it...

mov ax, 3D01h
mov dx, offset fileName
int 21h

...and succeed - I get 0006 in ax, then move it to bx before I try to actually read a byte with...

mov ah, 3Fh
mov cx, 01h
mov dx, offset buffer
int 21h

...where buffer is a db 0.

I keep getting a CF = 1, and AX = 05h, which means something like "access violation" as far as I know.

Any comments?
 
McBugzz,

Of course you will get "access violation", because you opened the file for "WRITE ONLY" (AL = 01h) access mode.

Use access mode 0 (AL = 00h, read only) or access mode 2 (AL = 02h, read/write)

Here is the list of access mode ( AL ):

------------------------
Bit(s) Description
2-0 access mode
000 read only
001 write only -> This is what you use
010 read/write
011 (DOS 5+ internal) passed to redirector on EXEC
to allow case-sensitive filenames

3 reserved (0)

6-4 sharing mode (DOS 3.0+) (see #01403)
000 compatibility mode
001 "DENYALL"
prohibit both read and write access by others
010 "DENYWRITE" prohibit write access by others
011 "DENYREAD" prohibit read access by others
100 "DENYNONE" allow full access by others
111 network FCB (only available during server call)

7 inheritance
if set, file is private to current process and
will not be inherited by child processes

------------------------

Hope it helps

-- AirCon --
 
thanks. I figured that out by now but looks like the f***** book lied. Said 001 was Read-only. =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top