Chapt er FO UR
I N T 2 1H
Programming
The x86 PC
Assembly Language, Design, and Interfacing © 2010, 2003, 2000, 1998 Pearson Higher Education, Inc.
By Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey Pearson Prentice Hall - Upper Saddle River, NJ 07458
OBJE CT IVES
this chapter enables the student to:
• Use INT 21H function calls to:
– Input characters from the keyboard.
– Output characters to the screen.
– Input strings.
– Output strings.
The x86 PC
Assembly Language, Design, and Interfacing © 2010, 2003, 2000, 1998 Pearson Higher Education, Inc.
By Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey Pearson Prentice Hall - Upper Saddle River, NJ 07458
4 . 0: I NT 21 H
• 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.
– In x86 processors, 256 interrupts, numbered 00 to FF.
• INT 10H and INT 21H are the most widely used with various
functions selected by the value in the AH register.
The x86 PC
Assembly Language, Design, and Interfacing © 2010, 2003, 2000, 1998 Pearson Higher Education, Inc.
By Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey Pearson Prentice Hall - Upper Saddle River, NJ 07458
4 . 2: DOS INTERRUPT 2 1H
• In previous chapters, a fixed set of data was defined
in the data segment & results viewed in a memory.
– This section uses information inputted from the keyboard,
and displayed on the screen.
• A much more dynamic way of processing information.
• When the OS is loaded, INT 21H can be invoked
to perform some extremely useful functions.
– Commonly referred to as DOS INT 21H function calls.
The x86 PC
Assembly Language, Design, and Interfacing © 2010, 2003, 2000, 1998 Pearson Higher Education, Inc.
By Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey Pearson Prentice Hall - Upper Saddle River, NJ 07458
4 . 2: D OS INTERRUPT 2 1H Option 09
outp ut ting a data string the m on it or
• INT 21H can send a set of ASCII data to the monitor.
– Set AH = 09 and DX = offset address of the ASCII data.
• Displays ASCII data string pointed at by DX until it encounters
the dollar sign "$".
• The data segment and code segment, to display the
message "The earth is but one country" :
The x86 PC
Assembly Language, Design, and Interfacing © 2010, 2003, 2000, 1998 Pearson Higher Education, Inc.
By Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey Pearson Prentice Hall - Upper Saddle River, NJ 07458
4 . 2: D OS INTERRUPT 2 1H Option 02
outp ut ting a single character
• To
To output
output only
only aa single
single character,
character, 02
02 is
is put
put in
in AH,
AH,
and DL is loaded with the character to be displayed.
• The following displays the letter "J" :
– This option can also be used to display '$' on the monitor
as the string display option (option 09) will not display '$‘.
The x86 PC
Assembly Language, Design, and Interfacing © 2010, 2003, 2000, 1998 Pearson Higher Education, Inc.
By Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey Pearson Prentice Hall - Upper Saddle River, NJ 07458
4 . 2: D OS INTERRUPT 2 1H Option 01
inpu tt ing a single character, wi th e ch o
• 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.
The x86 PC
Assembly Language, Design, and Interfacing © 2010, 2003, 2000, 1998 Pearson Higher Education, Inc.
By Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey Pearson Prentice Hall - Upper Saddle River, NJ 07458
4 . 2: D OS INTERRUPT 2 1H Option 0A H
inpu tt ing a data string from t he k ey b oa rd
• A means by which one can get keyboard data from &
store it in a predefined data segment memory area.
– Register AH = 0AH.
– DX = offset address at which the string of data is stored.
• Commonly referred to as a buffer area.
• DOS requires a buffer area be defined in the data
segment.
– The first byte specifies the size of the buffer.
– The number of characters from the keyboard is in the
second byte.
– Keyed-in data placed in the buffer starts at the third byte.
The x86 PC
Assembly Language, Design, and Interfacing © 2010, 2003, 2000, 1998 Pearson Higher Education, Inc.
By Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey Pearson Prentice Hall - Upper Saddle River, NJ 07458
4 . 2: D OS INTERRUPT 2 1H
usin g LABEL to define a string b uf fe r
• Use this directive to define a buffer area for the
string keyboard input:
• In the code segment the data can be accessed by
name as follows:
The x86 PC
Assembly Language, Design, and Interfacing © 2010, 2003, 2000, 1998 Pearson Higher Education, Inc.
By Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey Pearson Prentice Hall - Upper Saddle River, NJ 07458