0% found this document useful (0 votes)
18 views

Chapter4 - DOS Programming

The document discusses assembly language programming and various functions and interrupts provided by the operating system. It describes INT 10 which provides functions for screen manipulation and INT 21 which provides functions for input/output. It provides examples of using these interrupts to clear the screen, draw lines, and input/output strings of characters.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Chapter4 - DOS Programming

The document discusses assembly language programming and various functions and interrupts provided by the operating system. It describes INT 10 which provides functions for screen manipulation and INT 21 which provides functions for input/output. It provides examples of using these interrupts to clear the screen, draw lines, and input/output strings of characters.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

Assembly Language

Programming
Dr. Ali Mohamed
Faculty of Engineering at Aswan
Aswan University
Objectives
Interrupts

Some useful and important functions provided by the OS


are handed to the user through the interrupts (INT).
Calling interrupt works the same as FAR call which needs to
change the values by CS:IP to be saved in the stack.
There are many interrupts available two of them are
important (INT 10 and INT 21).
Each one of these interrupts can provide many function
depending the value in the register AH.
INT 10 functions are burned on the ROM BIOS.
The INT 10 is concerned with the services of the screen.
The INT instruction has the following format:
INT xx ;the interrupt number xx can be 00 - FFH
INT 10

Much of the manipulation of screen text or graphics is


done through INT 10H.
There are many functions associated with INT 10H.
Among them are:
changing the color of characters or the background
color,
clearing the screen, and
changing the location of the cursor.
These options are chosen by putting a specific value in
register AH.

The 80x86 Microprocessors 1.4 Assembly Language


Screen in Text Mode
The 80x86 Microprocessors 1.6 Assembly Language
Clearing the Screen

It is desirable to clear the screen before displaying data.


To use INT 10H to clear the screen, the following
registers must contain certain values before INT 10H is
called:
AH = 06, AL = 00, BH = 07, CX = 0000, DH = 24, and
DL = 79.
Option AH = 06, called the scroll function, will cause
the screen to scroll upward.
The CH and CL registers hold the starting row and
column, respectively, and DH and DL hold the ending
row and column.

The 80x86 Microprocessors 1.7 Assembly Language


Clearing the Screen
Setting the Cursor to Specific Position
Getting the Cursor Position

Registers DH, DL contain the current row and column


positions of the cursor.
Changing the Video Mode

Regardless of what type of adapter is used (MDA,CGA,


EGA, MCGA, VGA or SVGA), all are upwardly
compatible. For example, the VGA emulates all the
functions of MCGA, EGA, CGA, and MDA.
Therefore, there must be a way to change the video
mode to a desired mode. To do that, one can use INT
10H with AH = 00 and AL = video mode.

The 80x86 Microprocessors 1.11 Assembly Language


Monitor Types
MDA (Monochrome Display Adapter): A monitor that can
display only one color. Usually supports only text.
CGA (Color Graphics Adapter): The first color monitor /
graphics card for PC computers. Capable of producing 16
colors at 160x200 pixels.
EGA (Enhanced Graphics Adapter): Following CGA, an
adapter that could display 16 colors with a screen resolution of
640x350 pixels.
VGA (Video Graphics Adapter): the base standard for PC
monitors. True VGA supports 16 colors at 640x480 pixels or
256 colors at 320x200 pixels.
SVGA (Super VGA): A SVGA monitor is capable of displaying
more pixels (dots on the screen) and/or colors than basic VGA.
It can display 1280x1024, or even 1600x1200, pixels.
The 80x86 Microprocessors 1.12 Assembly Language
Video Mode
Video Mode
Monochrome Monitors

There is an attribute associated with each character


on the screen.
The attribute provides information to the video circuitry,
such as intensity of the character (foreground) and
the background.
The attribute byte for each character on the
monochrome monitor is limited.
Foreground refers to the actual character displayed.
Normal, highlighted intensity and blinking are for the
foreground only.

The 80x86 Microprocessors 1.15 Assembly Language


The 80x86 Microprocessors 1.16 Assembly Language
Monochrome Monitors

We should define the attributes needed to display characters on


the screen (in register BL).
These attributes will define the color and intensity of the
foreground and background of the screen.
To change the video mode (AH=0, AL= Mode, INT 10)
CGA text mode

Color Graphics Adapter (CGA) is the common


denominator for all color monitors.
All color monitors and their video circuitry are
upwardly compatible.
From the bit definition it can be seen that the
background can take eight different colors
The foreground can be any of 16 different
colors by combining red, blue, green, and
intensity.

The 80x86 Microprocessors 1.18 Assembly Language


Attributes of CGA
Example

Write a program using INT 10H to:


Change the video mode.
Display the letter “D" in 200H locations
with attributes black on white blinking
(blinking letters "0" are black and the
screen background is white).

The 80x86 Microprocessors 1.21 Assembly Language


Example
Example

Write a program that puts 20H (ASCII


space) on the entire screen. Use high-
intensity white on a blue background
attribute for any characters to be
displayed

The 80x86 Microprocessors 1.23 Assembly Language


The 80x86 Microprocessors 1.24 Assembly Language
Graphics Mode

In 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
rows and columns of pixels.
The number of pixels depends on the resolution.
For each pixel we need to know the location and the
attributes. These information is stored in the video RAM.
In 8086, there are 16 KB of video RAM.
To address pixels we use INT 10, AH = 0C H, the X-
coordinate in CX and the Y-coordinate in DX.
To turn the pixel AL = 01 (white) and AL = 00 (black)
The 80x86 Microprocessors 1.26 Assembly Language
The 80x86 Microprocessors 1.27 Assembly Language
Graphics Mode

The higher the number of pixels and


colors, the larger the amount of memory
that is needed to store them.
In other words, the memory requirement
goes up as the resolution and the number
of colors on the monitor go up.

The 80x86 Microprocessors 1.28 Assembly Language


Example

Write a program to:


Clear the screen.
Set the mode to CGA of 640 x 200
resolution.
Draw a horizontal line starting at column
= 100, row = 50, and ending at column
200, row 50.

The 80x86 Microprocessors 1.29 Assembly Language


Example
INT 21H Option 01H
Inputting a single character with echo

MOV AH, 01
INT 21H
This function waits until a character is input for the keyboard, then echoes
it to the monitor.
The input character (ASCII) will be in AL

Without echo
MOV AH, 07
INT 21H

The 80x86 Microprocessors 1.31 Assembly Language


INT 21H Option 02H
Outputting a single character to monitor

MOV AH, 02
MOV DL, ‘M’
INT 21H
DL is loaded wit the character to be displayed
The carriage return code 0D H
The line feed code 0A H

The 80x86 Microprocessors 1.32 Assembly Language


INT 21H Option 0AH
Inputting a string of data from keyboard, with echo

DATA DB 6,?, 6 DUO(FF)


MOV AH, 0AH
MOV DX, Offset DATA
INT 21H
Get data form keyboard and store it in a predefined area of memory in the
data segment.
DX stores the offset address of the buffer
OS will put the number of character that came in through the keyboard in
the second byte.
The keyed-in data is paced in the buffer starting from the third byte
The last character in the data is the carriage return
06 00 FF FF FF FF FF FF
06 4 ‘S’ ‘I’ ‘N’ ‘E’ 0D FF SINE
06 5 ‘M’ ‘a’ ‘h’ ‘m’ ‘o’ 0D Mahmoud
06 00 0D FF FF FF FF FF
The 80x86 Microprocessors 1.33
 Assembly Language
INT 21H Option 09H
outputting a string of data to the monitor

DATA DB ‘My name is Ahmed’,’$’


MOV AH, 09H
MOV DX, Offset DATA
INT 21H
Display the ASCII data string pointed by DX until it encounters ‘$’.
DX stores the offset address of the data to be displayed

The 80x86 Microprocessors 1.34 Assembly Language


Return Control to the Operating System

MOV AH,4CH
INT 21H

Their purpose is to return control to the operating system.

The 80x86 Microprocessors 1.35 Assembly Language


The 80x86 Microprocessors 1.36 Assembly Language
Checking a key press

To check a key press,

MOV AH, 01
INT 16
ZF = 0 if a key is pressed and ZF = 1 otherwise

To get the key pressed,

MOV AH, 00
INT 16
The ASCII code for the pressed code is stored in AL

The 80x86 Microprocessors 1.37 Assembly Language


Example

The 80x86 Microprocessors 1.38 Assembly Language


HW

From 1 to 7
From 9 to 11

The 80x86 Microprocessors 1.39 Assembly Language


Macros and the Mouse

The 80x86 Microprocessors 1.40 Assembly Language


The 80x86 Microprocessors 1.41 Assembly Language
What is Macro?
Sometimes we need to performer a task repeatedly in the program.
We can group these instructions in a program structure that we can call every
time we need it (similar to functions in C).
The macro definition should include,
macro_name MACRO data1, data2, ….. (optional)
The macro instructions
ENDM
The MACRO directive indicates the beginning of the macro definition and the
ENDM directive signals the end.
What goes in between the MACRO and ENDM directives is called the body of
the macro.
After the macro has been written, it can be invoked (or called) by its name,
and appropriate values are substituted for dummy parameters.

The 80x86 Microprocessors 1.42 Assembly Language


Example

The 80x86 Microprocessors 1.43 Assembly Language


Comments in Macros
Can macros contain comments? The answer is yes, but there is a way
to suppress comments and make the assembler show only the lines
that generate opcodes.
If the comment preceded with ; the will appear in .lst file.
If the comment preceded with ;; the will not appear in .lst file.
There are also three directive that affect the .lst file,
.LALL works the same before.
.SALL suppress the listing of the macro body and the comments. This
is especially useful if the macro is invoked many times within the same
program and there is no need to see it listed every time. It is used to
make the list file shorter and easier to read.
.XALL list only parts of macro that generate opcode.

The 80x86 Microprocessors 1.44 Assembly Language


Example

1. Write macro definitions for setting the cursor position,


displaying a string, and clearing the screen.
2. Using the macro definition, write a program that clears
the screen and then at each of the following screen
locations displays the indicated message:
at row 2 and column 4 "My name"
at row 12 and column 44 "what is"
at row 7 and column 24 "is Joe"
at row 19 and column 64 "your name?"

The 80x86 Microprocessors 1.45 Assembly Language


The 80x86 Microprocessors 1.46 Assembly Language
The 80x86 Microprocessors 1.47 Assembly Language
LOCAL Directive
In the discussion of macros so far. examples have been chosen that
do not have a label or name in the body of the macro.
This is because if a macro is expanded more than once in a program
and there is a label in the label field of the body of the macro, these
labels must be declared as LOCAL.
The following rules must be observed in the body of the macro:
All labels in the label field must be declared LOCAL.
The LOCAL directive must be right after the MACRO directive. In
other words, it must be placed even before comments and the body of
the macro; otherwise, the assembler gives an error.
The LOCAL directive can be used to declare all names and labels at
once as follows:
LOCAL name1,name2,name3
or one at a time as: LOCAL name1
LOCAL name2
The 80x86 Microprocessors 1.48 Assembly Language
Example

The 80x86 Microprocessors 1.49 Assembly Language


INCLUDE Directive

The INCLUDE directive is used to make using the macros more


effective.
We can make a library of macros then we can use them in any
program any time.
This can be done by constructing macro files that can be included
later in any program by the INCLUDE directive.

The 80x86 Microprocessors 1.50 Assembly Language


The 80x86 Microprocessors 1.51 Assembly Language
The 80x86 Microprocessors 1.52 Assembly Language
Mouse Programming (INT 33)
The original IBM PC and DOS did not provide support for the mouse. For this
reason, mouse interrupt INT 33H is not part of BIOS or DOS.
This is in contrast to INT 2l H and INT l0 H, which are the DOS and BIOS
interrupts, respectively.
INT 33H is part of the mouse driver software.
In INT 2lH and INT IOH, the AH register is used to select the functions. This is
not the case in INT 33H. In INT 33H the register AL is used to select various
functions and AH is set to O.
Detecting the presence of a mouse use INT 33 and if the value in AX = 0
there is no mouse supported if AX = FFFF there is a mouse.

The 80x86 Microprocessors 1.53 Assembly Language


Mouse Programming

Display the mouse cursor this can be done by AX = 01 then INT 33H to
hide it use AX = 02 then INT 33H

The 80x86 Microprocessors 1.54 Assembly Language


Mouse Programming

1. The option AX = 3 can get the current position of the mouse, the
horizontal position will be in CX and vertical in DX. The position is
given in pixels.
2. The option AX = 4 can set the position of the mouse, the
horizontal position will put in CX and vertical in DX. The position is
given in pixels.
3. The option AX = 5 can obtain which button is pressed of the
mouse. Upon return from INT 33H we find,
AX the status of the key pressed where,
D0 = Left button, 1 if down and 0 if up
D1 = center button, 1 if down and 0 if up
D2 = Right button, 1 if down and 0 if up
BX button press count
CX and DX is the coordinates of the last press.

The 80x86 Microprocessors 1.55 Assembly Language


Mouse Programming

Setting horizontal boundary for mouse pointer (AX=07)


This function set the x boundaries in which mouse movement is
confined. Call as follows.
AX=07
CX = minimum x coordinate in pixels (0 - 639)
DX = maximum x coordinate in pixels (0 - 639)
Notice that CX must be less than DX; otherwise, they are swapped.
Setting vertical boundary for mouse pointer (AX=08)
AX = 08
CX = minimum y coordinate in pixels (0 - 199)
DX = maximum y coordinate in pixels (0 - 199)

The 80x86 Microprocessors 1.56 Assembly Language


Mouse Programming

This function is used to set an area that is


off-limits for the mouse cursor.
If the mouse cursor moves to the
exclusion area, it disappears.
AX = 10H
CX = upper x coordinate,
DX = upper y coordinate,
SI = lower x coordinate
DI = lower y coordinate
The 80x86 Microprocessors 1.57 Assembly Language
HW

What is the difference between Macro


and subroutine?

The 80x86 Microprocessors 1.58 Assembly Language

You might also like