You are on page 1of 14

Chapter 07

INT 21H
DOS interrupts
 INT 21h is provided by DOS.
 When MS-DOS is loaded into the computer, INT 21H can be
invoked to perform some extremely useful functions.
 These functions are commonly referred to as DOS INT 21H
function calls.
 Data input and output through the keyboard and monitor are the
most commonly used functions.
Below are two examples that use DOS interrupts.

1. Display the message defined with variable DATA DB


‘Microprocessor,’$’

MOV AH,09 Option 9 to display string of data

MOV DX, OFFSET D ATA DX= offset address of data


INT 21H Invoke the interrupt
2. Inputting a single character, with echo.
MOV AH, 01 Option 01 to input one character
INT 21H Invoke the interrupt
DOS (Disk Operating System) Interrupts
1. Function call 01: Read the key board
Input parameter AH = 01 read a character from keyboard. Echo it on CRO
screen and return the ASCII code of the key pressed in AL output parameter:
AL = ASCII code of character
3. Function call 09: Display a
2. Function call 02h: Display on CRT screen character string
Input parameter: AH = 02 Input parameter: AH = 09,
DS:DX= Address of character
Dl = ASCII character to be displayed on string
CRT screen
Function: Displays the
4. Function call 0Ah: Buffered key board input characters available in the
Input parameter: AH = 0Ah string to CRT till a $ symbol
DS:DX = Address of keyboard input buffer
Function: The ASCII codes of the characters received from keyboard are stored
in keyboard buffer from 3rd byte. 1st byte of buffer = size of buffer upto 255. It
receives the characters till specified no.Of characters are received or enter key
is presses which ever is earlier
Interrupt Service Routines

ALL Interrupts
Interrupts for Input
Interrupts for Output
Interrupts for Input
INT 21h / AH=1 - read character from standard
input, with echo
INT 21h / AH=6 - direct console input or output
INT 21h / AH=7 - character input without echo to
AL
INT 21h / AH=0Ah - input of a string
Interrupts for Output
INT 21h / AH=2 - write character to
standard output
INT 21h / AH=9 - output of a string
INT 21h Function 07h
A program to read a character from Keyboard without Echo
solution: INT 21h / AH=7 - character input without echo to AL

.MODEL SMALL ; Select SMALL model


.DATA
CHAR DB ?
.CODE ; Start CODE Segment
START: MOV AX, @DATA ; Start Program
MOV DS, AX
LEA SI, CHAR
MOV AH, 07H ; Read without echo
INT 21H ; access DOS to read key
MOV [SI], AL
HLT
END START
After execution AL will have ASCII equivalent of the typed character
INT 21h Function 01h
A program to read a character from Keyboard Echo
solution: INT 21h / AH=1 - read character from standard input, with echo

.MODEL SMALL ; Select SMALL model


.DATA
CHAR DB ?
.CODE ; Start CODE Segment
START: MOV AX, @DATA ; Start Program
MOV DS, AX
LEA SI, CHAR
MOV AH, 01H; Select function 01H
INT 21H ; access DOS to read key
MOV [SI], AL ; saving the input character in memory
HLT
END START
After execution AL will have ASCII equivalent of the typed character, and at the same time the
character in AL will display to screen
INT 21h Function 06h
A program display a given character onto the screen, for example write a program to display
two character on their respective lines
solution: INT 21h / AH=6 - direct console input or output
.MODEL SMALL ; Select SMALL model
.CODE ; Start code segment
DISP MACRO A ; display A macro
MOV AH, 06H ; DOS function 06H
MOV DL, A ; Place parameter A in DL OUTPUT OF THE PROGRAM
INT 21H
ENDM
START:MOV AH, 06H
MOV DL, 'A'
INT 21H
DISP 0DH ;Display carriage return
DISP 0AH ; Display line feed
MOV AH, 06H
MOV DL, 'B'
INT 21H
HLT
END START
INT 21h Function 0AH
Program to read a string of 12 characters into a buffer from keyboard
solution: INT 21h / AH=0Ah - input of a string
OUTPUT OF THE PROGRAM
We can have two solutions

.MODEL SMALL ; Select SMALL model


.DATA
.MODEL SMALL ; Select SMALL model MSG DB 12
.DATA
MSG DB 20 DUP (?) ; 20 is greater than 12
DB 0
.CODE ; Start CODE Segment DB 12 DUP (?)
START: MOV AX, @DATA ; Start Program .CODE ; Start CODE Segment
MOV DS, AX START: MOV AX, @DATA ; Start Program
MOV MSG, 12 ; character count of 12
MOV AH, 0AH ; MOV DS, AX
MOV DX, OFFSET MSG ; address MSG MOV AH, 0AH ;
INT 21H ; access DOS to read key MOV DX, OFFSET MSG ; address MSG
HLT
END START
INT 21H ; access DOS to read key
HLT
END START
INT 21h Function 09h
A Program to display a string , for example display the string ‘Hello Engineers’
solution: INT 21h / AH=9 - output of a string

.MODEL SMALL ; Select SMALL model


.DATA
MSG DB 'HELLO ENGINEERS','$'
.CODE ; Start CODE Segment
START: MOV AX, @DATA ; Start Program
MOV DS, AX
MOV AH, 09H ; function number
MOV DX, OFFSET MSG ; address MSG
INT 21H ; access DOS to read key
HLT
END START OUTPUT OF THE PROGRAM

NB: the string to be displayed


should be followed with a
special character, i.e., $
INT 21h Function 09h, 0AH, 02H
Write a program that prompts to a user to receive a string from keyboard and redisplays
the received string following a confirmation message
.MODEL SMALL
.DATA
PROMPT DB 10, 13,' ENTER A STRING:$‘ ; prompts a string
PROF DB 10, 13, ' THE ENTERED MESSAGE IS:$‘ ; a confirmation message
MSG DB 12
DB 0
DB 12 DUP (0)
.CODE
START: MOV AX, @DATA
MOV DS, AX
OUTPUT OF THE PROGRAM MOV DX, OFFSET PROMPT
MOV AH, 09H
INT 21H
LEA DX, MSG
MOV AH, 0AH
INT 21H
LEA DX, PROF
MOV AH, 09H
INT 21H
LEA BX, MSG
INC BX
INC BX
MOV CX, 0CH
BACK:MOV DL, [BX]
MOV AH, 02H
INT 21H
INC BX
LOOP BACK
HLT
END START
Write a program that prompts a user to receive a string from keyboard and redisplays the
received string following a confirmation message , and again display the reverse of the
string

OUTPUT OF THE PROGRAM

You might also like