[Next] [Art of Assembly][Randall Hyde] [WEBster Home Page]


Art of Assembly Language: Chapter Thirteen



Art of Assembly/Win32 Edition is now available. Let me read that version.


PLEASE: Before emailing me asking how to get a hard copy of this text, read this.


PDF version of text. The Best Way to read "The Art of Assembly Language Programming"
Support Software for "Art of Assembly"


Important Notice: As you have probably discovered by now, I am no longer updating this document. The reason is quite simple: I'm working on a Windows version of "The Art of Assembly Language Programming". In the past I have encouraged individuals to send me corrections to this text. However, as I am no longer updating this material, don't expect those correctioins to appear in a future release. I am collecting errata that I will post to Webster someday, so feel free to continue sending corrections to AoA/DOS (16-bit) to rhyde@cs.ucr.edu. If you're more interested in leading edge material, please see the information about the Win/32 edition, above.


The Legal Stuff (Copyrights, etc.)


Chapter 13 - MS-DOS, PC-BIOS, and File I/O
13.0 - Chapter Overview
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
13.2.6.1 - AH=0: Serial Port Initialization
13.2.6.2 - AH=1: Transmit a Character to the Serial Port
13.2.6.3 - AH=2: Receive a Character from the Serial Port
13.2.6.4 - AH=3: Serial Port Status
13.2.7 - INT 15h - Miscellaneous Services
13.2.8 - INT 16h - Keyboard Services
13.2.8.1 - AH=0: Read a Key From the Keyboard
13.2.8.2 - AH=1: See if a Key is Available at the Keyboard
13.2.8.3 - AH=2: Return Keyboard Shift Key Status
13.2.9 - INT 17h - Printer Services
13.2.9.1 - AH=0: Print a Character
13.2.9.2 - AH=1: Initialize Printer
13.2.9.3 - 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
13.2.12.1 - AH=0: Read the Real Time Clock
13.2.12.2 - 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
13.3.6.1 - Allocate Memory
13.3.6.2 - Deallocate Memory
13.3.6.3 - Modify Memory Allocation
13.3.6.4 - Advanced Memory Management Functions
13.3.7 - MS-DOS Process Control Functions
13.3.7.1 - Terminate Program Execution
13.3.7.2 - Terminate, but Stay Resident
13.3.7.3 - Execute a Program
13.3.8 - MS-DOS "New" Filing Calls
13.3.8.1 - Open File
13.3.8.2 - Create File
13.3.8.3 - Close File
13.3.8.4 - Read From a File
13.3.8.5 - Write to a File
13.3.8.6 - Seek (Move File Pointer)
13.3.8.7 - Set Disk Transfer Address (DTA)
13.3.8.8 - Find First File
13.3.8.9 - Find Next File
13.3.8.10 - Delete File
13.3.8.11 - Rename File
13.3.8.12 - Change/Get File Attributes
13.3.8.13 - Get/Set File Date and Time
13.3.8.14 - Other DOS Calls
13.3.9 - File I/O Examples
13.3.9.1 - Example #1: A Hex Dump Utility
13.3.9.2 - 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



Chapter 13 MS-DOS, PC-BIOS, and File I/O


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.


13.0 Chapter Overview


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.


* The IBM PC BIOS

o Print screen.

* Video services.

o Equipment installed.

o Memory available.

o Low level disk services

* Serial I/O.

o Miscellaneous services.

* Keyboard services.

* Printer services.

o Run BASIC.

o Reboot computer.

o Real time clock.

* MS-DOS calling sequence.

* MS-DOS character functions

o MS-DOS drive commands.

o MS-DOS date and time functions.

o MS-DOS memory management functions.

o MS-DOS process control functions.

* MS_DOS "new" filing calls.

* Open file.

* Create file.

* Close file.

* Read from a file.

* Write to a file.

o Seek.

o Set disk transfer address.

o Find first file.

o Find next file.

* Delete file.

* Rename file.

o Change/get file attributes.

o Get/set file date and time.

o Other DOS calls

* File I/O examples.

* Blocked file I/O.

o The program segment prefix.

o Accessing command line parameters.

o ARGC and ARGV.

* UCR Standard Library file I/O routines.

* FOPEN.

* FCREATE.

* FCLOSE.

* FFLUSH.

* FGETC.

* FREAD.

* FPUTC

* FWRITE.

o Redirection I/O through the STDLIB file I/O routines.
13.0 - Chapter Overview
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
13.2.6.1 - AH=0: Serial Port Initialization
13.2.6.2 - AH=1: Transmit a Character to the Serial Port
13.2.6.3 - AH=2: Receive a Character from the Serial Port
13.2.6.4 - AH=3: Serial Port Status
13.2.7 - INT 15h - Miscellaneous Services
13.2.8 - INT 16h - Keyboard Services
13.2.8.1 - AH=0: Read a Key From the Keyboard
13.2.8.2 - AH=1: See if a Key is Available at the Keyboard
13.2.8.3 - AH=2: Return Keyboard Shift Key Status
13.2.9 - INT 17h - Printer Services
13.2.9.1 - AH=0: Print a Character
13.2.9.2 - AH=1: Initialize Printer
13.2.9.3 - 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
13.2.12.1 - AH=0: Read the Real Time Clock
13.2.12.2 - 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
13.3.6.1 - Allocate Memory
13.3.6.2 - Deallocate Memory
13.3.6.3 - Modify Memory Allocation
13.3.6.4 - Advanced Memory Management Functions
13.3.7 - MS-DOS Process Control Functions
13.3.7.1 - Terminate Program Execution
13.3.7.2 - Terminate, but Stay Resident
13.3.7.3 - Execute a Program
13.3.8 - MS-DOS "New" Filing Calls
13.3.8.1 - Open File
13.3.8.2 - Create File
13.3.8.3 - Close File
13.3.8.4 - Read From a File
13.3.8.5 - Write to a File
13.3.8.6 - Seek (Move File Pointer)
13.3.8.7 - Set Disk Transfer Address (DTA)
13.3.8.8 - Find First File
13.3.8.9 - Find Next File
13.3.8.10 - Delete File
13.3.8.11 - Rename File
13.3.8.12 - Change/Get File Attributes
13.3.8.13 - Get/Set File Date and Time
13.3.8.14 - Other DOS Calls
13.3.9 - File I/O Examples
13.3.9.1 - Example #1: A Hex Dump Utility
13.3.9.2 - 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


Art of Assembly: Chapter Thirteen - 28 SEP 1996

[Next] [Art of Assembly][Randall Hyde]



Number of Web Site Hits since Jan 1, 2000: