Vous êtes sur la page 1sur 5

Microprocessor Systems laboratory (EE 351)

Lab Manual #2

Page 1 of 5

Name
Roll No
Section
Marks

Input and Output Operations of 8086/8088 Assembly Language Contd

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

Reads a character from keyboard, stores it in AL and


display it (echo it ) on screen.
Screen
Display the content of register DL on screen in ASCII
form.
AL
Read character from keyboard without echoing it on
screen
Screen
Display the string that is terminated by$ sign.
Offset in Read a string of characters from keyboard.
DX

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.

Microprocessor Systems laboratory (EE 351)

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

Figure 2.1: Keyboard buffer structure

Function 0AH

Read from Keyboard

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

MOV AH, 0AH


INT 21H

; Read from keyboard the word hello


Buffer after input:
08

05

68

65

Program 1:
.MODEL SMALL
.STACK 200
.DATA
PROMPT
BUFFER

.CODE
.STARTUP

DB 'Enter your name(max. 9 characters): ', 0DH, 0AH, '$'


DB 10, 11 DUP (?) ; Allocate 13 bytes for BUFFER
; and put value 10 in the 1st byte.

; this directive initializes the DS and CS segments.

LEA DX, PROMPT ; display prompt

Microprocessor Systems laboratory (EE 351)

Lab Manual #2

Page 3 of 5

MOV AH, 09H


INT 21H
MOV AH, 0AH
LEA DX, BUFFER
INT 21H

; read into buffer

MOV AH, 4CH


INT 21H
END

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

0DH, 0AH, '$'


'Enter your name (max. 9 characters):, 0DH, 0AH, '$'
'Mr./Miss ','$'
' has ambitions to do something great for his/her country.','$'
10, 12 DUP (?)

.CODE
.STARTUP
LEA DX, PROMPT
MOV AH, 09H
INT 21H

; display prompt

Microprocessor Systems laboratory (EE 351)

Lab Manual #2

Page 4 of 5

MOV AH, 0AH


LEA DX, BUFFER
INT 21H

; read into buffer

LEA DX, CRLF


MOV AH, 09H
INT 21H

; move cursor to next line

LEA DX, STRING1


MOV AH, 09H
INT 21H

; display string1

; Now display the buffer i.e. what has been read.


MOV AH, 09H
MOV BH, 00H
MOV BL, BUFFER [1]
MOV BUFFER [BX+2],'$'
LEA DX, BUFFER [2]
INT 21H

; BX gets actual buffer length


; put a $ sign at the end of buffer
; load actual start of string

LEA DX, STRING2


MOV AH, 09H
INT 21H

; display string2

LEA DX, CRLF


MOV AH, 09H
INT 21H

; move cursor to next line

MOV AH, 02H


MOV DL, BUFFER [1]
ADD DL, 30H
INT 21H

; display number of characters read if less than 10


; read second byte of buffer
; convert to number

MOV AH, 4CH


INT 21H
END

Compile and run program 1 give your comments here:

Microprocessor Systems laboratory (EE 351)

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.

Vous aimerez peut-être aussi