7-BIOS and DOS Programming
7-BIOS and DOS Programming
Microprocessor
Mohammad Hosseini
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.
1
3/11/2024
3
BIOS and DOS Programming
❖ 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
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
3
3/11/2024
7
Setting the Cursor Position
➢ 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
➢ 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
12
Write Character and Attribute at Cursor Position
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:
7
3/11/2024
15
Graphics
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
8
3/11/2024
17
Writing Graphics Pixel
18
Changing the Background Color
9
3/11/2024
19
DOS Interrupt 21H
❖ 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
;…
10
3/11/2024
21
Outputting a Single Character to the Monitor
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
11
3/11/2024
23
Example
24
Example
12
3/11/2024
25
Example
CR EQU 0DH
LF EQU 0AH
26
Inputting a Single Character, without Echo
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