Practical Lab 6
Practical Lab 6
Practical no.6
Introduction:
In this experiment you will be introduced to the basic Input and Output (I/O)
operations using assembly language. You will use the DOS interrupt (INT 21H)
function calls to access the keyboard and video display. More details will also be
given on the structure of an assembly language program.
Objectives:
1- Demonstrate keyboard access using the DOS INT 21H function calls 01,
02 and 08.
2- Demonstrate string display using the DOS INT 21H function call 09.
3- Show the difference between keyboard read functions, with echo and
without echo.
These are DOS functions 02 and 06 for a single character display, and 09 for a string
display.
Both functions are identical, except that function 02 can be interrupted by a control
break (Ctrl-Break), while function 06 cannot. To display a single character ASCII
character at the current cursor position use the following sequence of instructions:
The Character Code may be the ASCII code of the character taken from the ASCII
table or the character itself written between quotes.
This function is used to display a string of characters ended with a ‘$’ sign. The
following code displays the string MESSAGE defined as:
These include reading a single character, with or without echo, functions 01 and 08,
and reading a whole string.
Function 01H and 08H INT 21H:
To read single character and have it echoed (displayed) on the screen, use the
following code:
If the character is to be read without echo, such as reading a password, use the
following code:
Reading a String:
Reading a string is accomplished by Function 0AH INT 21H. DOS function 0AH will
accept a string of text entered at the keyboard and copy that string into a memory
buffer. DOS 0AH is invoked with DS:DX pointing to an input buffer, whose size
should be at least three bytes longer than the largest input string anticipated.
Before invoking DOS function 0AH, you must set the first byte of the buffer with the
number of character spaces in the buffer. After returning from DOS function 0AH, the
second byte of the buffer will contain a value giving the number of characters actually
read form the keyboard (Table 6.2).
Buffer Actual
Length Length
Below is an example on the use of function 0AH, when the user enters the word
“hello”.
Input:
08 XX XX XX XX XX XX XX XX XX
Output:
08 05 68 65 6C 6C 6F 0D XX XX
Empty String:
Lab Work:
1- What does the program no.1 do? Notice how the program handles the three
different characters.
3- After running the program, notice here the effect of the characters 0DH
and 0AH at the end of the line containing: MESSAGE. What is your
conclusion?
4- Note also the effects of the function calls 01H, 08H.
Lab Assignment:
.MODEL SMALL
.DATA
X EQU ’B’
Y DB 43H
.STACK 200
.CODE
MOV AX,@DATA
MOV DS,AX
END
Program no.2
; This program displays a string terminated by a $ sign using INT 21H function 09H.
.MODEL SMALL
.DATA
MESSAGE DB ‘This is the message to be displayed’,’$’
.STACK 200
.CODE
MOV AX,@DATA
MOV DS, AX
Program no.3
.MODEL SMALL
.DATA
MESSAGE DB ‘Enter a character: ’,’$’
MESSAGE2 DB ‘The character you typed is: ’,0DH, 0AH,’$’
.STACK 200
.CODE
MOV AX,@DATA
MOV DS,AX