File I/O - PowerPoint PPT Presentation

About This Presentation
Title:

File I/O

Description:

File I/O I/O Flags Flags are passed to give some information about how the file is to be used. Read only file flag=0x0 Write only file flag=0x1 Read and write ... – PowerPoint PPT presentation

Number of Views:10
Avg rating:3.0/5.0
Slides: 11
Provided by: WilliamT155
Category:
Tags: buffer | file

less

Transcript and Presenter's Notes

Title: File I/O


1
File I/O

2
I/O Flags
  • Flags are passed to give some information about
    how the file is to be used.
  • Read only file flag0x0
  • Write only file flag0x1
  • Read and write flag0x2
  • Also tell other info by ORing above with
  • Create flag0x100
  • Truncate flag0x200
  • Append flag0x8
  • And tell the type by ORing above with
  • Text 0x4000
  • Binary 0x8000

3
File Descriptor
  • This is a value (held in 4 bytes 1 word) that
    uniquely identifies the file.
  • It is provided when the file is opened.
  • This is used when accessing the file to identify
    the file.
  • The open uses the file name and the system
    assigns a file descriptor value to be used by the
    other file I/O commands

4
File Open
  • Use syscall with v0 code 13
  • a0 has address of string containing the filename
    (zero/null terminated with no LF).
  • a1 flags
  • a2 permissions
  • v0 file descriptor for future use (-1 for error)

5
File Read
  • Use syscall code 14
  • a0 has the file descriptor (from the open)
  • a1 has the address of the buffer of where to put
    the stuff read in (character string)
  • a2 has the size of the buffer.
  • v0 returns the count of how much data was read
    in (-1 for error, 0 for EOF)

6
File Write
  • Uses syscall code 15
  • a0 has the file descriptor
  • a1 has the address of the buffer to write out
    (character string)
  • a2 has the size of the buffer to write out
  • v0 returns the amount actually written (should
    be the same as a2 unless there was a problem)

7
File Close
  • Uses syscall code 16
  • a0 has the file descriptor
  • THATS IT

8
Review of Read String
  • Uses syscall code 8
  • a0 has the address of where to put the string
    (buffer)
  • a1 has the size of the buffer
  • The input is read up the return character and a
    LF is put at the end of the string along with the
    null character (after the LF).
  • Some applications dont want the LF so it needs
    to be removed.

9
ASCII
  • All the file I/O commands use the address of a
    buffer.
  • This I/O is all done without conversion to ASCII
    characters.
  • You can write out binary numbers by placing them
    in the buffer, however these values will not be
    displayable on the screen (much like executable
    files).
  • To write numbers to a file that you can see, you
    must convert to ASCII
  • However, you can write numbers to a file in
    binary and have another program read them (not a
    human).

10
Character I/O
  • Syscall code 11 is print a character
  • The character is in the lower byte of a0
  • Syscall 12 is read a character
  • v0 contains the character in the lower byte
  • Read a character does not wait for the return
Write a Comment
User Comments (0)
About PowerShow.com