Académique Documents
Professionnel Documents
Culture Documents
Lab Manual #2
Page 1 of 5
Name
Roll No
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.
After this lab you will be able to
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:
Function
call No.
Value of
AH
Output in
01h
01h
AL
02h,06h
02h,06h
08h
08h
09h
0Ah
09h
0Ah
Functionality
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
Length
Anticipated
Actual
Length
XX
XX
XX
XX
XX
XX
XX
XX
Function 0AH
Before starting
AH = 0AH ; DX = address of keyboard input buffer First byte of buffer contains the
size of the buffer (up to 255)
Second byte of buffer contains the number of characters read. Reading operation
continues until buffer full, or a carriage return (CR = 0DH) is typed.
Table 2.2: Function 0AH of DOS Interrupt.
After ending
Example:
Below is an example on the use of function 0AH, when the user enters the word hello.
Buffer before input:
08
XX
XX
XX
XX
XX
XX
XX
XX
XX
6C
6C
6F
0D
XX
XX
05
68
65
Program 1:
.MODEL SMALL
.STACK 200
.DATA
PROMPT
BUFFER
.CODE
.STARTUP
Lab Manual #2
Page 3 of 5
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
CRLF
PROMPT
STRING1
STRING2
BUFFER
DB
DB
DB
DB
DB
.CODE
.STARTUP
LEA DX, PROMPT
MOV AH, 09H
INT 21H
; display prompt
Lab Manual #2
Page 4 of 5
; display string1
; display string2
Lab Manual #2
Page 5 of 5
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
roll no at that index and display the modified string.