Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

UOZ – CS. Dept. Microprocessors Lab. 2020 – Lab.

Sheet #2

Reading Data from Keyboard in Assembly


Language (MS-DOS)
Introduction:
In this lab experiment you will learn how to read data from keyboard
in assembly language using (INT 21h) so let’s start with the following
simple program and try to understand how it works:

The Code:
.MODEL SMALL
.STACK 100H
.DATA

str DB 30 DUP('$')
NL DB 0Dh,0Ah,’$’

.CODE

START:

MOV AX,@DATA
MOV DS,AX
LEA SI,str ; same as MOV SI, offset str1

MOV AH,0AH
MOV DX,SI
INT 21H

MOV AH,09H
LEA DX,NL ; same as MOV SI, offset NL
INT 21H ; to print newline

Instructors: Omar, Qaidar and Samyian


1
UOZ – CS. Dept. Microprocessors Lab. 2020 – Lab. Sheet #2

LEA DX,str+2 ; skip 2 bytes


INT 21H

MOV AH,4CH
INT 21H

END START

After completing the code save the code to prog2.asm file.

Assembling and Linking:

Instructors: Omar, Qaidar and Samyian


2
UOZ – CS. Dept. Microprocessors Lab. 2020 – Lab. Sheet #2

Running the program:

When you run the code, the output will be as shown below:

Now try to modify the code to look like the code listed below:

.MODEL SMALL
.STACK 100H
.DATA

str1 DB 'Enter Your Name: $'


str2 DB 0Dh,0Ah,'Welcome $'
str3 DB 30 DUP('$')

.CODE

START:
MOV AX,@DATA
MOV DS,AX

MOV AH,09H
LEA DX,str1
INT 21H

MOV AH,0AH
MOV DX,str3
INT 21H

Instructors: Omar, Qaidar and Samyian


3
UOZ – CS. Dept. Microprocessors Lab. 2020 – Lab. Sheet #2

MOV AH,09H
LEA DX,str2
INT 21H

LEA DX,str3+2
INT 21H

MOV AH,4CH
INT 21H

END START

After completing the code save it to prog3.asm file.

Assembling and Linking:

Instructors: Omar, Qaidar and Samyian


4
UOZ – CS. Dept. Microprocessors Lab. 2020 – Lab. Sheet #2

Running the program:

When you run the code, the output will look like the picture below:

AH = 0Ah - BUFFERED INPUT

Entry: DS:DX

Return: buffer filled with user input

Notes:

• ^C/^Break are checked


• reads from standard input

Format of DOS input buffer:

Offset Size Description


00 1 maximum characters buffer can hold
number of chars from last input which may be recalled OR number of characters
01 1
actually read, excluding CR
02 n actual characters read, including the final carriage return

Instructors: Omar, Qaidar and Samyian


5

You might also like