MS-DOS PC-BIOS AND FILE I/O (Part 1)
13.1 - The IBM PC BIOS
13.2 - An Introduction to the BIOS' Services
13.2.1 - INT 5- Print Screen
13.2.2 - INT 10h - Video Services
13.2.3 - INT 11h - Equipment Installed
13.2.4 - INT 12h - Memory Available
13.2.5 - INT 13h - Low Level Disk Services
13.2.6 - INT 14h - Serial I/O
184.108.40.206 - AH=0: Serial Port Initialization
220.127.116.11 - AH=1: Transmit a Character to the Serial Port
18.104.22.168 - AH=2: Receive a Character from the Serial Port
22.214.171.124 - AH=3: Serial Port Status
13.2.7 - INT 15h - Miscellaneous Services
13.2.8 - INT 16h - Keyboard Services
126.96.36.199 - AH=0: Read a Key From the Keyboard
188.8.131.52 - AH=1: See if a Key is Available at the Keyboard
184.108.40.206 - AH=2: Return Keyboard Shift Key Status
13.2.9 - INT 17h - Printer Services
220.127.116.11 - AH=0: Print a Character
18.104.22.168 - AH=1: Initialize Printer
22.214.171.124 - AH=2: Return Printer Status
13.2.10 - INT 18h - Run BASIC
13.2.11 - INT 19h - Reboot Computer
13.2.12 - INT 1Ah - Real Time Clock
126.96.36.199 - AH=0: Read the Real Time Clock
188.8.131.52 - AH=1: Setting the Real Time Clock
13.3 - An Introduction to MS-DOS'
13.3.1 - MS-DOS Calling Sequence
13.3.2 - MS-DOS Character Oriented Functions
13.3.3 - MS-DOS Drive Commands
13.3.4 - MS-DOS "Obsolete" Filing Calls
13.3.5 - MS-DOS Date and Time Functions
13.3.6 - MS-DOS Memory Management Functions
184.108.40.206 - Allocate Memory
220.127.116.11 - Deallocate Memory
18.104.22.168 - Modify Memory Allocation
22.214.171.124 - Advanced Memory Management Functions
13.3.7 - MS-DOS Process Control Functions
126.96.36.199 - Terminate Program Execution
188.8.131.52 - Terminate but Stay Resident
184.108.40.206 - Execute a Program
13.3.8 - MS-DOS "New" Filing Calls
220.127.116.11 - Open File
18.104.22.168 - Create File
22.214.171.124 - Close File
126.96.36.199 - Read From a File
188.8.131.52 - Write to a File
184.108.40.206 - Seek (Move File Pointer)
220.127.116.11 - Set Disk Transfer Address (DTA)
18.104.22.168 - Find First File
22.214.171.124 - Find Next File
126.96.36.199 - Delete File
188.8.131.52 - Rename File
184.108.40.206 - Change/Get File Attributes
220.127.116.11 - Get/Set File Date and Time
18.104.22.168 - Other DOS Calls
13.3.9 - File I/O Examples
22.214.171.124 - Example #1: A Hex Dump Utility
126.96.36.199 - Example #2: Upper Case Conversion
13.3.10 - Blocked File I/O
13.3.11 - The Program Segment Prefix (PSP)
13.3.12 - Accessing Command Line Parameters
13.3.13 - ARGC and ARGV
13.4 - UCR Standard Library File I/O Routines
13.4.1 - Fopen
13.4.2 - Fcreate
13.4.3 - Fclose
13.4.4 - Fflush
13.4.5 - Fgetc
13.4.6 - Fread
13.4.7 - Fputc
13.4.8 - Fwrite
13.4.9 - Redirecting I/O Through the StdLib File I/O Routines
13.4.10 - A File I/O Example
13.5 - Sample Program
|Copyright 1996 by Randall Hyde
All rights reserved.
Duplication other than for immediate display through a browser is prohibited by U.S. Copyright Law.
This material is provided on-line as a beta-test of this text. It is for the personal use of the reader only. If you are interested in using this material as part of a course please contact email@example.com
Supporting software and other materials are available via anonymous ftp from ftp.cs.ucr.edu. See the "/pub/pc/ibmpcdir" directory for details. You may also download the material from "Randall Hyde's Assembly Language Page" at URL: http://webster.ucr.edu
This document does not contain the laboratory exercises programming assignments exercises or chapter summary. These portions were omitted for several reasons: either they wouldn't format properly they contained hyperlinks that were too much work to resolve they were under constant revision or they were not included for security reasons. Such omission should have very little impact on the reader interested in learning this material or evaluating this document.
This document was prepared using Harlequin's Web Maker 2.2 and Quadralay's Webworks Publisher. Since HTML does not support the rich formatting options available in Framemaker this document is only an approximation of the actual chapter from the textbook.
If you are absolutely dying to get your hands on a version other than HTML you might consider having the UCR Printing a Reprographics Department run you off a copy on their Xerox machines. For details please read the following EMAIL message I received from the Printing and Reprographics Department:
We are currently working on ways to publish this text in a form other than HTML (e.g. Postscript PDF Frameviewer hard copy etc.). This however is a low-priority project. Please do not contact Randall Hyde concerning this effort. When something happens an announcement will appear on "Randall Hyde's Assembly Language Page." Please visit this WEB site at http://webster.ucr.edu for the latest scoop.
Redesigned 10/2000 with "MS FrontPage 98" using
17" monitor 1024x768
A typical PC system consists of many component besides the 80x86 CPU and memory. MS-DOS and the PC's BIOS provide a software connection between your application program and the underlying hardware. Although it is sometimes necessary to program the hardware directly yourself more often than not it's best to let the system software (MS-DOS and the BIOS) handle this for you. Furthermore it's much easier for you to simply call a routine built into your system than to write the routine yourself.
You can access the IBM PC system hardware at one of three general levels from assembly language. You can program the hardware directly you can use ROM BIOS routines to access the hardware for you or you can make MS-DOS calls to access the hardware. Each level of system access has its own set of advantages and disadvantages.
Programming the hardware directly offers two advantages over the other schemes: control and efficiency. If you're controlling the hardware modes you can get that last drop of performance out of the system by taking advantage of special hardware tricks or other details which a general purpose routine cannot. For some programs like screen editors (which must have high speed access to the video display) accessing the hardware directly is the only way to achieve reasonable performance levels.
On the other hand programming the hardware directly has its drawbacks as well. The screen editor which directly accesses video memory may not work if a new type of video display card appears for the IBM PC. Multiple display drivers may be necessary for such a program increasing the amount of work to create and maintain the program. Furthermore had you written several programs which access the screen memory directly and IBM produced a new incompatible display adapter you'd have to rewrite all your programs to work with the new display card.
Your work load would be reduced tremendously if IBM supplied in a fixed known location some routines which did all the screen I/O operations for you. Your programs would all call these routines. When a manufacturer introduces a new display adapter it supplies a new set of video display routines with the adapter card. These new routines would patch into the old ones (replacing or augmenting them) so that calls to the old routines would now call the new routines. If the program interface is the same between the two set of routines your programs will still work with the new routines.
IBM has implemented such a mechanism in the PC system firmware. Up at the high end of the one megabyte memory space in the PC are some addresses dedicated to ROM data storage. These ROM memory chips contain special software called the PC Basic Input Output System or BIOS. The BIOS routines provide a hardware-independent interface to various devices in the IBM PC system. For example one of the BIOS services is a video display driver. By making various calls to the BIOS video routines your software will be able to write characters to the screen regardless of the actual display board installed.
At one level up is MS-DOS. While the BIOS allows you to manipulate devices in a very low level fashion MS-DOS provides a high-level interface to many devices. For example one of the BIOS routines allows you to access the floppy disk drive. With this BIOS routine you may read or write blocks on the diskette. Unfortunately the BIOS doesn't know about things like files and directories. It only knows about blocks. If you want to access a file on the disk drive using a BIOS call you'll have to know exactly where that file appears on the diskette surface. On the other hand calls to MS-DOS allow you to deal with filenames rather than file disk addresses. MS-DOS keeps track of where files are on the disk surface and makes calls to the ROM BIOS to read the appropriate blocks for you. This high-level interface greatly reduces the amount of effort your software need expend in order to access data on the disk drive.
The purpose of this chapter is to provide a brief introduction to the various BIOS and DOS services available to you. This chapter does not attempt to begin to describe all of the routines or the options available to each routine. There are several other texts the size of this one which attempt to discuss just the BIOS or just MS-DOS. Furthermore any attempt to provide complete coverage of MS-DOS or the BIOS in a single text is doomed to failure from the start- both are a moving target with specifications changing with each new version. So rather than try to explain everything this chapter will simply attempt to present the flavor. Check in the bibliography for texts dealing directly with BIOS or MS -DOS.
This chapter presents material that is specific to the PC. This information on the PC's BIOS and MS-DOS is not necessary if you want to learn about assembly language programming; however this is important information for anyone wanting to write assembly language programs that run under MS-DOS on a PC compatible machine. As a result most of the information in this chapter is optional for those wanting to learn generic 80x86 assembly language programming. On the other hand this information is handy for those who want to write applications in assembly language on a PC.
The sections below that have a "*" prefix are essential. Those sections with a "o" discuss advanced topics that you may want to put off for a while.
Chapter Thirteen: MS-DOS
File I/O (Part 1)
28 SEP 1996