Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lab #03 Input and Output Instruction: Objective

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Lab #03

Input and Output Instruction


Objective
 Understand the working of INT 21H instruction
 Understand program having basic Input and Output Instruction

Theory
The processor cannot access the peripheral devices (like keyboard or monitor) directly. Microprocessor use BIOS
routines or DOS routines to access peripherals. The BIOS (Basic Input/Output System) routines are store in ROM and
directly run the I/O ports where DOS routine use BIOS routine to perform operation that’s why has less complex than
BIOS routine.
The BIOS and DOS both use INT (Interrupt) instruction, the interrupt is actually done by number
which determine nature of interrupt. The format of interrupt instruction is:
INT interrupt number
e.g. INT 21H ; Invoke DOS routine

Function Number Routine


01H Take input with echo
02H Display character
07H Take input without echo
09H Display string
4CH Control back to DOS

0BH Check standard input status

2AH Get system Date

2CH Get system Time


INT 16H ; Invoke BIOS routine

Some INT 21H Function

When INT 21H execute the DOS first see the function number in AH register, so all the function number must be
placed in AH register to execute.

Page 1
Function 01H (Single character input with echo)

After instruction executes, the AL register get the ASCII Code of the character and if non-character key
(control key) is press then than AL register get 00H. The 01H function also displays the character on screen.

MOV AH, 01H ; Move input key function to AH register

INT 21H ; Invoke DOS interrupt

Function 07H (Single character input without echo)

This function works as same as the function of 01H but it not display the press character on screen.

Function 02H (Single character output)

This function displays the signal character whose ASCII Code value is present in DL register.

MOV DL,’A’ ; Move the ASCII code of A ( A = 41H) in DL register

MOV AH, 02H ; Move the single character output function into AH register

INT 21H ; Invoke DOS interrupt

Function 09H (Display string)

The function display the string which is terminated by $ sign present in Data segment register. Data Segment
address is store in DS register and DX register store the offset address of the string to display.

.DATA

Page 2
MESSAGE DB 0AH, 0DH,”INDUS UNIVERSITY$”

.CODE

MOV AX,@DATA ; Get address of DATA segment

MOV DS, AX ; Move address of DATA segment into DS register

MOV DX, OFFSET MESSAGE ;Get offset address of MESSAGE

MOV AH, 09H ;Move display string function into AH register

INT 21H ; Invoke DOS interrupt

Function 4CH (DOS exit function)

When the program terminate (end) the control must return back to the DOS. This is done by 4CH function.

MOV AH, 4CH ; Move return to DOS function into AH register

INT 21H ; Invoke DOS interrupt

Function 0BH (Check for Character available function)

This function is used to check any available character of keyboard. This function return two values in AL
register, if it’s 00H then no character available and if it’s FFH then a character available.

MOV AH, 0BH ; Check for any Character available

INT 21H ; Invoke DOS interrupt

Function 2AH (Get system Date function)

This function returns the Date of the system. The return values are store in varies registers that are CX (year
(1980-2099)), DH (month (00-11)), DL (day (0-30)) and AL (day of the week (00 for Sunday))

MOV AH, 2CH ; Get current time of the system

INT 21H ; Invoke DOS interrupt

Function 2CH (Get system Time function)

This function return the time of the system. The return values store in varies registers that are CH (hour (0-
23)), CL (minutes (0-59)), DH (second (0-59)) and DL (1/100 second (0-99))

MOV AH, 2CH ; Get current time of the system

INT 21H ; Invoke DOS interrupt

Hour store in CH register, Minutes store in CL register, Second store in DH register and milli-second store in
DL register.

Tasks:
1- Write a program to take 4 character input from user and display user input on screen

A)
mov ax, @data
mov ds, ax

Page 3
mov dx, offset a
mov ah, 09h
int 21h

mov ah, 01h


int 21h

MOV BH, AL
mov ah, 01h
int 21h

MOV CH, AL
mov Ch, 01h
int 21h

MOV DH, AL
mov DH, 01h
int 21h

MOV BL, AL

mov dx, offset b


mov ah, 09h
int 21h

mov dl, BH
mov ah, 02h
int 21h
mov dl, BL
mov ah, 02h
int 21h

mov dx, offset c


mov ah, 09h
int 21h

ret

mov DL, 13
mov ah, 02h
int 21h
mov DL, 10
mov ah, 02h
int 21h
ret

2- Write a password program, in which take input from user and display **** instead. (4
Character password)

A) password:
mov ah, 07h
int 21h
cmp al,0dh
mov b[si],al
inc si
Page 4
mov dl, '*'
mov ah,2
int 21h
jmp password

3- Write case conversion program, in which user enters small case character and program
converts it to upper case.

A) READ MACRO MSG


MOV AH,0AH
LEA DX,MSG
INT 21H
ENDM

PRINT MACRO MSG


MOV AH,09H
LEA DX,MSG
INT 21H
ENDM

DATA SEGMENT
CR EQU 0DH
LF EQU 0AH
MSG1 DB \"ENTER THE STRING IN LOWERCASE:$\"
MSG2 DB CR,LF,\"THE UPPERCASE STRING IS :$\"

BUFF DB 255
DB 0
DB 255 DUP (\'$\')
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
PRINT MSG1
READ BUFF
MOV SI,OFFSET BUFF+2
MOV CL,BYTEPTR[SI-1]
MOV CH,00H

LP1: MOV AH,[SI]


MOV AL,61H
JB LP1
CMP AL,7BH
JNB LP1
SUB AL,20H
MOV [SI],AL

LP2:
INC SI
LOOP SP1
PRINT MSG2
PRINT MSG2
PRINT BUFF+2
MOV AH,4CH
INT 21H
CODE ENDS
END START

4- Write a program to display system date


A) .MODEL SMALL

.STACK 64

Page 5
.DATA
EN_DATE DB \'ENTER DATE (dd-mm-yyyy): $\'
MSGDAY DB \'DAY : $\'
MSGMONTH DB \'MONTH : $\'
NL DB 0DH,0AH,\'$\'
DAY DB \' \',\'$\'
MONTH DB \' \',\'$\'
.CODE

MAIN PROC
MOV AX,@DATA
MOV DS,AX

LEA DX,EN_DATE
MOV AH,09H
INT 21H
LEA SI,DAY
READ_DAY:
MOV AH,01H
INT 21H
CMP AL,2DH
JE F_READ_DAY

MOV [SI],AL

INC SI
JMP READ_DAY

F_READ_DAY:
INC SI
MOV AL,\'$\'
MOV [SI],AL

LEA SI,MONTH

READ_MONTH:
MOV AH,01H
INT 21H

CMP AL,2DH
JE F_READ_MONTH

MOV [SI],AL

INC SI
JMP READ_MONTH
F_READ_MONTH:
INC SI
MOV AL,\'$\'
MOV [SI],AL
MOV CL,04H
READ_YEAR:
MOV AH,01H
INT 21H
LOOP READ_YEAR
DISP:
LEA DX,NL
MOV AH,09H
INT 21H

LEA DX,MSGDAY
INT 21H

LEA DX,NL
INT 21H

Page 6
LEA DX,DAY
INT 21H

LEA DX,NL
INT 21H

LEA DX,MSGMONTH
INT 21H

LEA DX,NL
INT 21H

LEA DX,MONTH
INT 21H

MOV AH,4CH
INT 21H

MAIN ENDP
END MAIN

Page 7

You might also like