[Chapter Thirteen][Previous] [Next] [Art of Assembly][Randall Hyde]

Art of Assembly: Chapter Thirteen


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.1 The IBM PC BIOS


Rather than place the BIOS routines at fixed memory locations in ROM, IBM used a much more flexible approach in the BIOS design. To call a BIOS routine, you use one of the 80x86's int software interrupt instructions. The int instruction uses the following syntax:

int value

Value is some number in the range 0..255. Execution of the int instruction will cause the 80x86 to transfer control to one of 256 different interrupt handlers. The interrupt vector table, starting at physical memory location 0:0, holds the addresses of these interrupt handlers. Each address is a full segmented address, requiring four bytes, so there are 400h bytes in the interrupt vector table -- one segmented address for each of the 256 possible software interrupts. For example, int 0 transfers control to the routine whose address is at location 0:0, int 1 transfers control to the routine whose address is at 0:4, int 2 via 0:8, int 3 via 0:C, and int 4 via 0:10.

When the PC resets, one of the first operations it does is initialize several of these interrupt vectors so they point at BIOS service routines. Later, when you execute an appropriate int instruction, control transfers to the appropriate BIOS code.

If all you're doing is calling BIOS routines (as opposed to writing them), you can view the int instruction as nothing more than a special call instruction.


13.2 An Introduction to the BIOS' Services


The IBM PC BIOS uses software interrupts 5 and 10h..1Ah to accomplish various operations. Therefore, the int 5, and int 10h.. int 1ah instructions provide the interface to BIOS. The following table summarizes the BIOS services:

INT Function

5 Print Screen operation.

10h Video display services.

11h Equipment determination.

12h Memory size determination.

13h Diskette and hard disk services.

14h Serial I/O services.

15h Miscellaneous services.

16h Keyboard services.

17h Printer services.

18h BASIC.

19h Reboot.

1Ah Real time clock services.



Most of these routines require various parameters in the 80x86's registers. Some require additional parameters in certain memory locations. The following sections describe the exact operation of many of the BIOS routine.


13.2.1 INT 5- Print Screen






Instruction:    int 5h
BIOS Operation: Print the current text screen.
Parameters:     None

If you execute the int 5h instruction, the PC will send a copy of the screen image to the printer exactly as though you'd pressed the PrtSc key on the keyboard. In fact, the BIOS issues an int 5 instruction when you press the PrtSc, so the two operations are absolutely identical (other than one is under software control rather than manual control). Note that the 80286 and later also uses int 5 for the BOUNDS trap.


13.2.2 INT 10h - Video Services






Instruction:    int 10h
BIOS Operation: Video I/O Services
Parameters:     Several, passed in ax, bx, cx, dx, and es:bp registers.

The int 10h instruction does several video display related functions. You can use it to initialize the video display, set the cursor size and position, read the cursor position, manipulate a light pen, read or write the current display page, scroll the data in the screen up or down, read and write characters, read and write pixels in a graphics display mode, and write strings to the display. You select the particular function to execute by passing a value in the ah register.

The video services represent one of the largest set of BIOS calls available. There are many different video display cards manufactured for PCs, each with minor variations and often each having its own set of unique BIOS functions. The BIOS reference in the appendices lists some of the more common functions available, but as pointed out earlier, this list is quite incomplete and out of date given the rapid change in technology.

Probably the most commonly used video service call is the character output routine:





Name:           Write char to screen in TTY mode
Parameters      ah = 0Eh, al = ASCII code (In graphics mode, bl = Page number)

This routine writes a single character to the display. MS-DOS calls this routine to display characters on the screen. The UCR Standard Library also provides a call which lets you write characters directly to the display using BIOS calls.

Most BIOS video display routines are poorly written. There is not much else that can be said about them. They are extremely slow and don't provide much in the way of functionality. For this reason, most programmers (who need a high-performance video display driver) end up writing their own display code. This provides speed at the expense of portability. Unfortunately, there is rarely any other choice. If you need functionality rather than speed, you should consider using the ANSI.SYS screen driver provided with MS-DOS. This display driver provides all kinds of useful services such as clear to end of line, clear to end of screen, etc. For more information, consult your DOS manual.

BIOS Video Functions (Partial List)
AH Input

Parameters
Output

Parameters
Description
0 al=mode   Sets the video display mode.
1 ch- Starting line.

cl- ending line
  Sets the shape of the cursor. Line values are in the range 0..15. You can make the cursor disappear by loading ch with 20h.
2 bh- page

dh- y coordinate

dl- x coordinate
  Position cursor to location (x,y) on the screen. Generally you would specify page zero. BIOS maintains a separate cursor for each page.
3 bh- page ch- starting line

cl- ending line

dl- x coordinate

dh- y coordinate
Get cursor position and shape.
4     Obsolete (Get Light Pen Position).
5 al- display page   Set display page. Switches the text display page to the specified page number. Page zero is the standard text page. Most color adapters support up to eight text pages (0..7).
6 al- Number of lines to scroll.

bh- Screen attribute for cleared area.

cl- x coordinate UL

ch- y coordinate UL

dl- x coordinate LR

dh- y coordinate LR
  Clear or scroll up. If al contains zero, this function clears the rectangular portion of the screen specified by cl/ch (the upper left hand corner) and dl/dh (the lower right hand corner). If al contains any other value, this service will scroll that rectangular window up the number of lines specified in al.
7 al- Number of lines to scroll.

bh- Screen attribute for cleared area.

cl- x coordinate UL

ch- y coordinate UL

dl- x coordinate LR

dh- y coordinate LR
  Clear or scroll down. If al contains zero, this function clears the rectangular portion of the screen specified by cl/ch (the upper left hand corner) and dl/dh (the lower right hand corner). If al contains any other value, this service will scroll that rectangular window down the number of lines specified in al.
8 bh- display page al- char read

ah- char attribute
Read character's ASCII code and attribute byte from current screen position.
9 al- character

bh- page

bl- attribute

cx- # of times to replicate character
  This call writes cx copies of the character and attribute in al/bl starting at the current cursor position on the screen. It does not change the cursor's position.
0Ah al- character

bh- page
  Writes character in al to the current screen position using the existing attribute. Does not change cursor position.
0Bh bh- 0

bl- color
  Sets the border color for the text display.
0Eh al- character

bh- page
  Write a character to the screen. Uses existing attribute and repositions cursor after write.
0Fh   ah- # columns

al- display mode

bh- page
Get video mode


Note that there are many other BIOS 10h subfunctions. Mostly, these other functions deal with graphics modes (the BIOS is too slow for manipulating graphics, so you shouldn't use those calls) and extended features for certain video display cards. For more information on these calls, pick up a text on the PC's BIOS.


13.2.3 INT 11h - Equipment Installed






Instruction:    int 11h
BIOS Operation: Return an equipment list
Parameters:     On entry: None, on exit: AX contains equipment list

On return from int 11h, the AX register contains a bit-encoded equipment list with the following values:





Bit 0           Floppy disk drive installed
Bit 1           Math coprocessor installed
Bits 2,3                System board RAM installed (obsolete)
Bits 4,5                Initial video mode
                        00- none
                        01- 40x25 color
                        10- 80x25 color
                        11- 80x25 b/w
Bits 6,7                Number of disk drives
Bit 8           DMA present
Bits 9,10,11    Number of RS-232 serial cards installed
Bit 12          Game I/O card installed
Bit 13          Serial printer attached
Bits 14,15      Number of printers attached.

Note that this BIOS service was designed around the original IBM PC with its very limited hardware expansion capabilities. The bits returned by this call are almost meaningless today.


13.2.4 INT 12h - Memory Available






Instruction:    int 12h
 BIOS Operation:Determine memory size
Parameters:     Memory size returned in AX

Back in the days when IBM PCs came with up to 64K memory installed on the motherboard, this call had some meaning. However, PCs today can handle up to 64 megabytes or more. Obviously this BIOS call is a little out of date. Some PCs use this call for different purposes, but you cannot rely on such calls working on any machine.


13.2.5 INT 13h - Low Level Disk Services






Instruction:    int 13h
BIOS Operation: Diskette Services
Parameters:     ax, es:bx, cx, dx (see below)

The int 13h function provides several different low-level disk services to PC programs: Reset the diskette system, get the diskette status, read diskette sectors, write diskette sectors, verify diskette sectors, and format a diskette track and many more. This is another example of a BIOS routine which has changed over the years. When this routine was first developed, a 10 megabyte hard disk was considered large. Today, a typical high performance game requires 20 to 30 megabytes of storage.

Some Common Disk Subsystem BIOS Calls
AH Input

Parameters
Output

Parameters
Description
0 dl- drive (0..7fh is floppy, 80h..ffh is hard) ah- status (0 and carry clear if no error, error code if error). Resets the specified disk drive. Resetting a hard disk also resets the floppy drives.
1 dl- drive (as above) ah- 0

al- status of previous disk operation.
This call returns the following status values in al:

0- no error

1- invalid command

2- address mark not found

3- disk write protected

4- couldn't find sector

5- reset error

6- removed media

7- bad parameter table

8- DMA overrun

9- DMA operation crossed 64K boundary

10- illegal sector flag

11- illegal track flag

12- illegal media

13- invalid # of sectors

14- control data address mark encountered

15- DMA error

16- CRC data error

17- ECC corrected data error

32- disk controller failed

64- seek error

128- timeout error

170- drive not ready

187- undefined error

204- write error

224- status error

255- sense failure
2 al- # of sectors to read

es:bx- buffer address

cl- bits 0..5: sector #

cl- bits 6/7- track bits 8 & 9

ch- track bits 0..7.

dl- drive # (as above)

dh- bits 0..5: head #

dh- bits 6&7: track bits 10 & 11.
ah- return status

al- burst error length

carry- 0:success, 1:error
Reads the specified number of 512 byte sectors from the disk. Data read must be 64 Kbytes or less.
3 same as (2) above same as (2) above Writes the specified number of 512 byte sectors to the disk. Data written must not exceed 64 Kbytes in length.
4 Same as (2) above except there is no need for a buffer. same as (2) above Verifies the data in the specified number of 512 byte sectors on the disk.
0Ch Same as (4) above except there is no need for a sector # Same as (4) above Sends the disk head to the specified track on the disk.
0Dh dl- drive # (80h or 81h) ah- return status

carry-0:no error

1:error
Reset the hard disk controller


Note: see appropriate BIOS documentation for additional information about disk subsystem BIOS support.

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


Art of Assembly: Chapter Thirteen - 28 SEP 1996

[Chapter Thirteen][Previous] [Next] [Art of Assembly][Randall Hyde]



Number of Web Site Hits since Jan 1, 2000: