0% found this document useful (0 votes)
7 views

7-BIOS and DOS Programming

The document covers BIOS and DOS programming, detailing the use of interrupt instructions (INT) for accessing various subroutines. It explains how to manipulate the screen, set cursor positions, and manage video modes using INT 10H, along with input and output operations using INT 21H. Additionally, it discusses graphics modes and keyboard programming techniques for handling user input.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

7-BIOS and DOS Programming

The document covers BIOS and DOS programming, detailing the use of interrupt instructions (INT) for accessing various subroutines. It explains how to manipulate the screen, set cursor positions, and manage video modes using INT 10H, along with input and output operations using INT 21H. Additionally, it discusses graphics modes and keyboard programming techniques for handling user input.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

3/11/2024

Microprocessor

Mohammad Hosseini

BIOS and DOS Programming

2
BIOS and DOS Programming
❖ There are some useful subroutines within BIOS and DOS that are available to
the user through the INT (interrupt) instruction.

INT int_num ; the interrupt number can be 00 - FFH

❖ The INT instruction is somewhat like a FAR call.


➢ Saves CS:IP and the flags on the stack and
goes to the subroutine associated with that interrupt.

▪ INT 10H BIOS


▪ INT 21H DOS

1
3/11/2024

3
BIOS and DOS Programming

❖ Before requesting a service, certain registers must have specific values


in them, depending on the function being requested.

❖ Various functions of INT 21H and INT 10H are selected by the value
put in the AH register.

❖ The registers that have not been used by the interrupt remain unchanged

4
BIOS INT 10H

❖ INT 10H subroutines are burned into the ROM BIOS of the 80x86-based
IBM PC and compatibles

➢ Used to communicate with the computer’s screen video.

2
3/11/2024

5
Monitor Screen in Text Mode

❖ The monitor screen in the IBM PC is divided into 80 columns and 25 rows
in normal text mode (the default mode).

00,00 00,79(4FH)

Screen center
12,39

24(18H),00 24,79

6
Clearing the Screen
❖ The screen can be cleared using the scroll function (AH=06)
MOV AH, 06 ; Scrolls a specified window upward a
; number of lines
MOV AL, 00 ; Number of lines to scroll (00: entire screen)
MOV BH, 07 ; Display attribute for blank lines (color)
MOV CH, 00 ; Row number of upper left corner
MOV AX, 0600H
MOV CL, 00 ; Column number of upper left corner MOV BH, 07
MOV DH, 24 ; Row number of lower right corner MOV CX, 0000
MOV DL, 79 ; Column number of lower right corner MOV DX, 184FH
INT 10H
INT 10H

➢ Lines are inserted at the bottom with all lines moving up


➢ The new lines are filled with blank characters of a specified display attribute (value in BH)
➢ The lines that disappear at the top of the window are lost

3
3/11/2024

7
Setting the Cursor Position

MOV AH, 02 ; Set cursor position


MOV BH, 00 ; Page number
MOV DH, 15 ; Row
MOV DL, 25 ; Column
INT 10H

➢ Video RAM can have more than one page of text, but only one of them can be viewed
at a time.
➢ In graphics modes, this service sets the logical position of the cursor, even though the
cursor itself is not displayed (there is no cursor display in any graphics mode)
➢ To make the cursor invisible, position it on row 25

8
Getting the Cursor Position

MOV AH, 03 ; Get cursor position


MOV BH, 00 ; Page number
INT 10H

➢ After execution of the program above, registers DH and DL will have the
current row and column positions

4
3/11/2024

9
Setting the Video Mode
MOV AH, 00 ; Set video mode
MOV AL, 07 ; Mode (7 for monochrome, 3 for CGA text)
INT 10H

10
Attribute Byte in Monochrome Monitors
➢ There is an attribute associated with each character on the screen
specifying the color of the character (foreground) and its background
D7 D6 D5 D4 D3 D2 D1 D0

foreground intensity
0 = normal intensity
1 = highlighted intensity

background intensity

0 = nonblinking
1 = blinking
Binary Hex Result
-------------- ------- -------
0000 0111 07 white on black normal
1111 0000 F0 black on white blinking

5
3/11/2024

11
Attribute Byte in CGA Text Mode

D7 D6 D5 D4 D3 D2 D1 D0
B R G B I R G B
Blinking Background Intensity Foreground

Binary Hex Result


-------------- ------- -------
0000 0001 01 blue on black
0001 1111 1F high-intensity white on blue

12
Write Character and Attribute at Cursor Position

MOV AH, 00 ; set video mode


MOV AL, 07 ; mode (7 for monochrome, 3 for CGA text)
INT 10H

MOV AH, 09 ; write character


MOV BH, 00 ; page 0
MOV AL, 44H ; ASCII of the character to be displayed
MOV CX, 5 ; repeat 5 times
MOV BL, 0F0H ; attribute (black on white blinking)
INT 10H

6
3/11/2024

13
Graphics

❖ In the text mode, the screen is viewed as a matrix of rows and columns of
characters
❖ In graphics mode, the screen is viewed as a matrix of horizontal and
vertical pixels.
❖ The number of pixels varies among monitors and depends on monitor
resolution and the video board.

❖ There are two facts associated with every pixel on the screen:
➢ The location of the pixel
➢ Its attributes: color and intensity
▪ These two facts must be stored in the video RAM

14
Graphics
❖ CGA board: 16K bytes (128K bits) of memory
❖ The 16K bytes of memory can be used in three different ways:

➢ 1- Text mode of 80 × 25 characters


▪ 2K bytes (80 × 25 = 2000) for the characters
▪ 2K bytes of memory for their attributes
▪ Results in four pages of (full screen) data
▪ 16 colors are supported
✓ To select this mode: AH=00, AL=03, INT 10H

7
3/11/2024

15
Graphics

➢ Graphics mode of 320 × 200 (medium resolution)


▪ 64,000 pixels
▪ 2 bits for the color of each pixel (128K/64000=2) → four colors
✓ To select this mode: AH=00, AL=04, INT 10H

➢ Graphics resolution of 640 × 200 (high resolution)


▪ 128,000 pixels
▪ 1 bit for color (black/white)
✓ To select this mode: AH=00, AL=06, INT 10H

o To create more colors in VGA boards, one must increase the memory on
the video board since there must be a storage place to store the extra colors.

16
Writing Graphics Pixel

MOV AH, 0CH ; write graphics pixel


MOV BH, 00 ; page 0
MOV AL, 1 ; color
MOV CX, 100 ; column
MOV DX, 200 ; row
INT 10H

8
3/11/2024

17
Writing Graphics Pixel

18
Changing the Background Color

MOV AH, 00 ; set video mode


MOV AL, 04 ; CGA STANDARD 300X200 WITH 4 COLOR
INT 10H

MOV AH, 0BH ; set background/border color


MOV BH, 0 ; setting background color for graphics modes,
; or border color for text modes
MOV BL, 1 ; color (blue)
INT 10H

9
3/11/2024

19
DOS Interrupt 21H

❖ INT 21H is provided by DOS

❖ When MS-DOS (or its IBM version PC-DOS) is loaded into the computer,
INT 21H can be invoked to perform some useful functions.

20
Outputting a String of Data to the Monitor

MYSTRING DB ‘This is a sample string.’, ’$’

;…

MOV AH, 09 ; display a string


MOV DX, OFFSET MYSTRING
INT 21H

❖ Displays the ASCII data string pointed at by DX until it encounters the


dollar sign “$”.

10
3/11/2024

21
Outputting a Single Character to the Monitor

MOV AH, 02 ; display a character


MOV DL, ‘W’ ; the character to be displayed
INT 21H

❖ This option can also be used to display '$'

22
Inputting a Single Character, with Echo

❖ This functions waits until a character is input from the keyboard, then
echoes it to the monitor.
❖ After the interrupt, the input character will be in AL

MOV AH, 01 ; input one character


INT 21H

11
3/11/2024

23
Example

24
Example

12
3/11/2024

25
Example

CR EQU 0DH
LF EQU 0AH

MSG2 DB CR,LF,'You entered: ','$'

26
Inputting a Single Character, without Echo

❖ This functions waits until a character is input from the keyboard


❖ The character is not displayed (or echoed) on the screen
❖ After the interrupt, the input character will be in AL

MOV AH, 07 ; input one character (without echo)


INT 21H

13
3/11/2024

27
Inputting a String of Data from the Keyboard
❖ A buffer area is required
➢ The first byte of the buffer specifies its size.
➢ DOS will put the number of characters that came in through the
keyboard in the second byte.
➢ Keyed-in data is placed in the buffer starting at the third byte.

BUF1 DB 8, ?, 8 DUP(0FFH)
;…
MOV AH, 0AH ; input a string from keyboard
MOV DX, OFFSET BUF1 ; address of the buffer
INT 21H
❖ When the data comes in, the computer will not exit the INT 21H routine
until it encounters the return key.

28
Inputting a String of Data from the Keyboard
ORG 100H ; fetch the count value
BUF1 DB 8, ?, 8 DUP(0FFH) MOV BX, OFFSET BUF1
;… SUB CH, CH
MOV AH, 0AH MOV CL, [BX]+1
; To locate the CR value in the string and
MOV DX, OFFSET BUF1
; replace it, say with 00.
INT 21H MOV SI, CX
MOV BYTE PTR[BX+SI]+2,00
Memory 0100 0101 0102 0103 0104 0105 0106 0107 0108 0109 010A
contents: 08 00 FF FF FF FF FF FF FF FF FF
Assuming the data that has been entered through the keyboard is “Hello" <RETURN>
08 5 48 65 6C 6C 6F 0D FF FF FF
‘H’ ‘e’ ‘l’ ‘l’ ‘o’ ‘CR’

14
3/11/2024

29
INT 16H Keyboard Programming
❖ Function AH=07H of INT 21H waits for the user to input a character
❖ What if a program must run a certain task continuously while checking for
a key press? MOV AH, 01 ; check for key press
INT 16H ; it is a BIOS INT
❖ This function does not wait for the user to press a key.
❖ It simply checks to see if there is a key press.
❖ Upon return, ZF=0 if there is a key press; ZF=l if there is no key press.
MOV AH, 00 ; returns the next character in the keyboard buffer
INT 16H
❖ Upon return, AL contains the ASCII character of the pressed key; its scan key
is in AH.
❖ Notice that if no character is available, this service waits until one is available

30
Example

15
3/11/2024

31
Reading Assignment

➢ MACRO
➢ Chapter 5 of the book

16

You might also like