Org Four: Int 21H and INT 10H Programming and Macros
Org Four: Int 21H and INT 10H Programming and Macros
4 4 00000100
ORG ; FOUR
INT 21H
and INT 10H
Programming and
Macros
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
OBJECTIVES
this chapter enables the student to:
• Use INT 10H function calls to:
– Clear the screen.
– Set the cursor position.
– Write characters to the screen in text mode.
– Change the video mode.
• Use INT 21H function calls to:
– Input characters from the keyboard.
– Output characters to the screen.
– Input or output strings.
• Programming with Macros
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: INT 21H and 10H
• INT 10H and INT 21H are the most widely used
interrupts with various functions selected by the
value in the AH register.
• In x86 processors, 256 interrupts can be defined
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.1: BIOS INT 10H 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
4.1: BIOS INT 10H PROGRAMMING
monitor screen in text mode
• The monitor screen in the x86 PC is divided into
80 columns and 25 rows in normal text mode.
– Columns are numbered from 0 to 79.
– Rows are numbered 0 to 24.
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.1: BIOS INT 10H PROGRAMMING
screen clearing with INT 10H function 06H
• To clear the screen using INT 10H, some registers
must contain certain values before INT 10H is called:
– Option AH = 06 calls the scroll function, to scroll upward.
– CH & CL registers hold starting row & column.
– DH & DL registers hold ending row & column.
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.1: BIOS INT 10H PROGRAMMING
setting the cursor to a specific location
• INT 10H function AH = 02 set the cursor to a specific
location.
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.1: BIOS INT 10H PROGRAMMING
setting the cursor to a specific location
• Example 4-1 demonstrates setting the cursor to a
specific location.
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.1: BIOS INT 10H PROGRAMMING
get current cursor position
• In text mode, determine where the cursor is located
at any time by executing the following:
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 21H
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 21H Option 09
outputting a data string the monitor
• The data segment and code segment, to display the
message "The earth is but one country"
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: DOS INTERRUPT 21H Option 02
outputting a single character
• To output a single character,
• AH = 02
DL is loaded with the character to be displayed.
• The following displays the letter "J" :
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 21H Option 01
inputting a single character, with echo
• Inputting a single character with echo
• This function waits until a character is input from
the keyboard, then echoes it to the monitor.
– AH = 01
– 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: DOS INTERRUPT 21H Option 07, inputting a single
character without echo
• Option 07 requires the user to enter a single
character, which is not displayed (or echoed)
on the screen.
keyboard input without echo
– The PC waits until a single character is entered
and provides the character 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: Combining INT 10H and INT 21H
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: Combining INT 10H and INT 21H
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 21H Option 0AH
inputting a data string from the keyboard
• Enables to get keyboard data & store it in a
predefined memory area.
– AH = 0AH.
– DX = offset address at which the string of data is stored.
• Commonly referred to as a buffer area.
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 21H Option 0AH
inputting a data string from the keyboard
• This program accepts up to six characters from the
keyboard, including the return (carriage return) key.
– Six buffer locations were reserved, and filled with FFH.
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 21H Option 0AH
inputting a data string from the keyboard
• Assuming the data entered through the keyboard
was "USA" <RETURN>, the contents of memory
locations starting at offset 0010H would look like:
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 21H
inputting more than buffer size
• If only the CR key is activated & no other character:
CR is not included
in the count.
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.3: WHAT IS A MACRO, AND HOW IS IT USED?
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.3: WHAT IS A MACRO, AND HOW IS IT USED?
MACRO definition
• Every macro definition must have three parts:
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.3: WHAT IS A MACRO, AND HOW IS IT USED?
MACRO definition
• In the following code segment, the macro can be
invoked by its name with the user's actual data:
• Instruction "STRING MESSAGE1" invokes the macro.
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.3: WHAT IS A MACRO, AND HOW IS IT USED?
LOCAL directive and its use in macros
• If a macro is expanded more than once, and there is
a label in the label field of the body of the macro,
these labels must be declared as LOCAL.
– Otherwise, an assembler error would be generated when
the same label was encountered in two or more places.
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.3: WHAT IS A MACRO, AND HOW IS IT USED?
LOCAL directive and its use in macros
• Rules which must be observed in the macro body:
– 1. All labels in the label field must be declared LOCAL.
– 2. LOCAL directive must be right after the MACRO
directive.
– 3. The LOCAL directive can be used to declare all names
and labels at once.
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.3: WHAT IS A MACRO, AND HOW IS IT USED?
LOCAL directive and its use in macros
• In example 4-7, the "BACK" label is defined as LOCAL right after the MACRO directive.
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: Macro Definitions
CLEAR MACRO
MOV AX, 0600 ; Scroll
screen
MOV BH, 07 ; Normal
attribute
MOV CX, 0000 ; From
00;00
MOV DX, 184F ; to CURSOR MACRO RW, CLM ; set the cursor position
18h;4Fh MOV AH, 02
MOV BH, 00 ; page 00
INT 10H MOV DH, RW
ENDM MOV DL, CLM
; ---------------------------------- INT 10H
DISPLAY MACRO MESSAGE ENDM
MOV AH, 09
MOV DX, OFFSET
MESSAGE
INT 21H
ENDM
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: Macro Definitions
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
Dec Hex Bin
4 4 00000100
ENDS ; FOUR
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