Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Name
CMS ID
Section
Marks
Introduction
The objective of this lab session is to make you comfortable with performing
some input/output operations using DOS INT 21H function calls.
Take input from key board using functions calls 01H,08H and 0AH of INT 21H
Show output on the screen using function calls 02H,06H and 09H of INT 21H
Work with character strings
Last time we have seen how to output a string and a character on screen further we learned how to get a
character input from the user. A brief summary of I/O operation using INT 21H is given below:
Now we are ready to learn how to get a string of characters as input from the user.
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.
Lab Manual #2 Page 2 of 5
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 from the keyboard (Table 2.2).
Buffer Actual XX XX XX XX XX XX XX XX
Length Length
Anticipated
Figure 2.1: Keyboard buffer structure
Example:
Below is an example on the use of function 0AH, when the user enters the word “hello”.
08 XX XX XX XX XX XX XX XX XX
08 05 68 65 6C 6C 6F 0D XX XX
Program 1:
.MODEL SMALL
.STACK 200
.DATA
.CODE
.STARTUP ; this directive initializes the DS and CS segments.
Compile and run program 1 then go to view-›variables and select BUFFER from the window of
variables to see contents of this buffer are in the memory before and after running the program. What do
you see there? Write your observations here:
Program 2:
.MODEL SMALL
.STACK 100H
.DATA
.CODE
.STARTUP
LEA DX, PROMPT ; display prompt
MOV AH, 09H
INT 21H
Lab Manual #2 Page 4 of 5
END
Lab Manual #2 Page 5 of 5
Compile and run program 1 give your comments here:
Lab Assignment:
1. Prompt separately for first and second name of the user, both must be placed inside a
buffer separated by a space, also display that buffer to the user.
2. Read a string of 8 characters from the user then ask user to give you an index (1 to 8). Place your
CMS ID at that index and display the modified string.