Lab #03 Input and Output Instruction: Objective
Lab #03 Input and Output Instruction: Objective
Lab #03 Input and Output Instruction: Objective
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
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.
This function works as same as the function of 01H but it not display the press character on screen.
This function displays the signal character whose ASCII Code value is present in DL register.
MOV AH, 02H ; Move the single character output function into AH register
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
When the program terminate (end) the control must return back to the DOS. This is done by 4CH 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.
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))
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))
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 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 dl, BH
mov ah, 02h
int 21h
mov dl, BL
mov ah, 02h
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.
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
LP2:
INC SI
LOOP SP1
PRINT MSG2
PRINT MSG2
PRINT BUFF+2
MOV AH,4CH
INT 21H
CODE ENDS
END START
.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