0% found this document useful (0 votes)
150 views31 pages

Org Four: Int 21H and INT 10H Programming and Macros

Uploaded by

Buket Cüvelenk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
150 views31 pages

Org Four: Int 21H and INT 10H Programming and Macros

Uploaded by

Buket Cüvelenk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 31

Dec Hex Bin

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 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.

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

• INT 10H subroutines are burned into the ROM BIOS.


– Used to communicate with the computer's screen video.
• Manipulation of screen text/graphics can be done via INT 10H.

• Some the functions associated with INT 10H are:


– changing character or background color,
– Clearing the screen, and
– changing the location of the cursor.

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 top left corner has


been assigned 00,00,
the top right 00,79.
Bottom left is 24,00,
bottom right 24,79.

Figure 4-1 Cursor Locations (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
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.

– AH = 02 Set cursor position


– BH = Page number (BH = 00 represents the current page)
– DX = cursor position (DH = row and DL = 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
• 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:

– After execution of the program, registers DH & DL will


have current row and column positions.
• CX provides information about the shape of the cursor.
– In text mode, page 00 is chosen for the currently viewed
page.

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

• INT 21H is a DOS function call


– Value in AH is used to specify the required function

• Writing a string of data on the screen


– AH = 09
– DX = offset address of the ASCII data to be written on the
screen (data assumed to be in DS).
– End of string is denoted by $ sign

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" :

– 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: 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

• Program 4-1 combines INT 10H and INT 21H.


The program does the following:
(1) Clears the screen.
(2) Sets the cursor to
the center of the screen.
(3) Displays the message "This is a test".

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

.DATA CURSOR MOVAH, 02 ; set the cursor at the center


MESSAGE DB ‘This is a test’, ‘$’ MOV BH, 00 ; page 00
;-------------initializing------------- MOV DH, 12 ; center raw
.CODE MOV DL, 39 ; center column
MAIN PROC FAR INT 10H
MOV AX, @DATA RET
MOV DS, AX CURSOR ENDP
CALL CLEAR ; ----------------------------------
CALL CURSOR DISPLAY PROC
CALL DISPLAY MOV AH, 09
MOV AH, 4CH MOV DX, OFFSET MESSAGE
INT 21H INT 21H
MAIN ENDP RET
;-------------------------------------- DISPLAY ENDP
CLEAR PROC END MAIN
MOV AX, 0600 ; Scroll screen
MOV BH, 07 ; Normal
attribute
MOV CX, 0000 ; From 00;00
MOV DX, 184F ; to 18h;4Fh
INT 10H
RET
CLEAR ENDP

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.

• Buffer is 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: 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.

– Initial Memory contents of offset 0010H:

– The PC won’t exit INT 21H until it encounters a RETURN.

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:

– 0010H = 06 DOS requires the size of the buffer here.


– 0011H = 03 The keyboard was activated three times
(excluding the RETURN key) to key in letters U, S, and A.
– 0012H = 55H ASCII hex value for letter U.
– 0013H = 53H ASCII hex value for letter S.
– 0014H = 41H ASCII hex value for letter A.
– 0015H = 0DH ASCII hex value for CR. (carriage return)
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
• Entering more than six characters (five + the CR = 6)
will cause the computer to sound the speaker.
– The contents of the buffer will look like this:

– Location 0015 has ASCII 20H for <SPACE>


– Location 0016 has ASCII 61H for "a“.
– Location 0017 has 0D for <RETURN> key.
– The actual length is 05 at memory offset 0011H.

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:

– 0AH is placed in memory 0020H.


– 0021H is for the count.
– 0022H IS the first location to have data that was entered.

CR is not included
in the count.

– If only the <RETURN> key is activated, 0022H has 0DH,


the hex code for CR.
• The actual number of characters entered is 0 at location 0021.

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?

• There are applications in Assembly language


programming where a group of instructions
performs a task used repeatedly.
– It does not make sense to rewrite them every time.
• Macros allow the programmer to write the task once
only & invoke it whenever, wherever it is needed.
– Reduces time to write code & reduce possibility of errors.

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 MACRO directive indicates the beginning of the


macro definition, ENDM directive signals the end.
• In between is the body of the macro.
– The name must be unique and must follow Assembly
language naming conventions.
• Dummies are names, parameters, or registers
that are mentioned in the body of the macro.
• The macro can be invoked (or called) by its name, and
appropriate values substituted for dummy parameters.
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
• A macro for displaying a string of data using the widely
used function 09 of 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.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 assembler expands the macro by providing the


following code in the .LST file:

– The (1) indicates that the code is from the macro.


• Earlier versions of MASM, used a plus sign (+).

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

.MODEL SAMALL .CODE


.STACK 64 MAIN PROC FAR
.DATA MOV AX, @DATA
MOV DS, AX
MSG1 DB ‘My name’, ‘$’ CLEAR
MSG2 DB ‘is Ali’, ‘$’ CURSOR 2, 4
MSG3 DB ‘What is’, ‘$’ DISPLAY MSG1
MSG4 DB ‘your name?’, ‘$’ CURSOR 3, 4
; DISPLAY MSG2
CURSOR 10, 4
DISPLAY MSG3
CURSOR 11, 4
DISPLAY MSG4
MOV AH, 4CH
INT 21H
END MAIN

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy