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

EL - 224 Microprocessor Based Systems: Experiment# 04

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

EL – 224 Microprocessor Based Systems

Experiment# 04

Multiline Message on Dos Screen

Performed on

Student Name:
Roll Number:

Maximum Marks Performance = 05 Viva = 05 Total = 10

Marks Obtained

Remarks (if any)

Experiment evaluated by

Instructor Name: Engr. Farhat Hasnain

Signature and Date:

Copyright © Department of Electrical Engineering – Usman Institute of Technology


IMPLEMENTATION OF PRINTING, INPUT, CMP, AAA AND
AAS INSTRUCTIONS
HOW TO DISPLAY MULTILINE MESSAGE ON DOS SCREEN:
If you want to display a multiline message on DOS screen you can use DB command.
With its other argument that is 0dh and 0ah. Example see the example program.

Sample Program:

.MODEL SMALL
.STACK 100H
.DATA
BIODATA DB "USMAN INTITUTE OF TECHNOLOGY",0DH,0AH
DB "*********MY BIODATA*********",0DH,0AH
DB "NAME: ",0DH,0AH
DB "DEPT:", 0DH,0AH
DB "ROLL NUMBER:", 0DH,0AH
DB "C.G.P.A: ", 0DH,0AH
DB "ENROLLMENT NUMBER: ", 0DH,0AH
DB "BLOOD GROUP: ",'$'
.CODE
.STARTUP

MOV AH,09H
MOV DX, OFFSET BIODATA
INT 21H

.EXIT
END

HOW TO TAKE USER INPUT


There are a number of DOS functions for standard input, but some most commonly
used functions are4 describe below

01h Filtered Input with Echo:


DOS function 1 wait for a single character to be read for the standard input, echoes
the character to the standard output and store the character in AL, the user can halt
the program by pressing Ctrl+Break.

Copyright © Department of Electrical Engineering – Usman Institute of Technology


Sample Program

.MODEL SMALL
.STACK 100H
.DATA
CHAR DB ?
.CODE
.STARTUP

MOV AH, 01H


INT 21H
MOV CHAR, AL
MOV DL, CHAR
MOV AH, 02H
INT 21H

.EXIT
END

0Ah Buffered Input


Function 0Ah read character string up to 255 characters from standard input and store
it in a buffer. The backspace key can be used to erase character and backup the
cursor. The user can terminate the input by pressing the Enter key.DOS after filter out
any non-ASCII key, such as cursor arrow and PgDn so they will be store in the buffer,
Ctrl+Break is active and all characters are echoed on standard output. The input AH
= 0ah and DX contain the offset of a record containing the keyboard parameter the
format of this record is shown in following fig
OFFSET
n M
n = Max number of character allowed
m = Number of characters actually input
remaining part is the input buffer area

Sample Program

.MODEL SMALL
.STACK 100H
.DATA
UIT:
MAXKEY DB 50
CHARINPUT DB ?
BUFFER DB 50 DUP('$'); USE $ TO TERMINATE STRING
.CODE
.STARTUP

MOV AH,0AH
MOV DX, OFFSET UIT
INT 21H
MOV CH, CHARINPUT
MOV AX,0

Copyright © Department of Electrical Engineering – Usman Institute of Technology


MOV AL,CH
ADD AX, 3030H
MOV DL, AL
MOV AH, 02H
INT 21H
MOV AH,09H
MOV DX, OFFSET BUFFER
INT 21H

.EXIT
END

Output Function
02h; Character input
DOS function 2 sends a character to standard output advance the cursor 1 position,
input AH = 2 dl contain the character

Sample Program

.MODEL SMALL
.STACK 100H
.DATA
MSG1 DB 0DH,0AH,"PRESS ANY KEY ",0DH,0AH,'$'
MSG2 DB 0DH,0AH,"YOU HAVE PRESSED: ",'$'
NUM DB ?
.CODE
.STARTUP

MOV AH,09H
MOV DX, OFFSET MSG1
INT 21H
MOV AH, 01H
INT 21H
MOV NUM, AL
MOV AH, 09H
MOV DX, OFFSET MSG2
INT 21H
MOV DL, NUM
MOV AH, 02H
INT 21H

.EXIT
END

JUMP on the basis of user input

Sample Program

.MODEL SMALL
.STACK 100H

Copyright © Department of Electrical Engineering – Usman Institute of Technology


.DATA
MAIN_MENU DB " USMAN INSTITUTE OF TECHNOLOGY",0DH,0AH
DB "* PRESS 1 FOR EE",0DH,0AH
DB "* PRESS 2 FOR CE",0DH,0AH
DB "* PRESS 3 FOR TE",0DH,0AH
DB "* PRESS 4 FOR IE",0DH,0AH
DB "* PRESS 5 FOR BS",0DH,0AH
DB "* PRESS E FOR EXIT",0DH,0AH
DB "*PRESS R TO RETURN TO MAIN MENU",0DH,0AH
DB "ENTER YOUR CHOICE",'$'
EE1 DB 0DH,0AH,"WELCOME TO EE DEPPT",0DH,0AH,'$'
CE1 DB 0DH,0AH,"WELCOME TO CE DEPPT",0DH,0AH,'$'
TE1 DB 0DH,0AH,"WELCOME TO TE DEPPT",0DH,0AH,'$'
IE1 DB 0DH,0AH,"WELCOME TO IE DEPPT",0DH,0AH,'$'
BS1 DB 0DH,0AH,"WELCOME TO BS DEPPT",0DH,0AH,'$'
EX DB 0DH,0AH,"GOOD BYE & HAVE A NICE TIME",0DH,0AH,'$'
USER_INPUT DB ?
.CODE
.STARTUP

;***************PRINT MAIN MENU*******************


MOV AH,09H
MOV DX, OFFSET MAIN_MENU
INT 21H
;*********TAKE USER INPUT FROM MEUNU**************

START:
MOV AH,01H
INT 21H
MOV USER_INPUT,AL
MOV AL, USER_INPUT
CMP AL,'1'
JE EE
CMP AL,'2'
JE CE
CMP AL,'3'
JE TE
CMP AL,'4'
JE IE
CMP AL,'5'
JE BS
CMP AL,'E'
JE EXIT
CMP AL,'R'
JE START
JMP START
EE:
MOV AH, 09H
MOV DX, OFFSET EE1
INT 21H

Copyright © Department of Electrical Engineering – Usman Institute of Technology


JMP START
CE:
MOV AH, 09H
MOV DX, OFFSET CE1
INT 21H
JMP START
TE:
MOV AH, 09H
MOV DX, OFFSET TE1
INT 21H
JMP START
IE:
MOV AH, 09H
MOV DX, OFFSET IE1
INT 21H
JMP START
BS:
MOV AH, 09H
MOV DX, OFFSET BS1
INT 21H
JMP START
EXIT:
MOV AH, 09H
MOV DX, OFFSET EX
INT 21H

.EXIT
END

AAA
The AAA (ASCII adjustment after addition) instruction adjusts the binary result of an
ADD instruction. It makes the result in AL consistent with ASCII digit representation.
The will hold in AX.

Sample Program

.MODEL SMALL
.STACK 100H
.DATA
MSG1 DB 0DH, 0AH, "ENTER FIRST NUMBER:",0DH,0AH,'$'
MSG2 DB 0DH, 0AH, "ENTER SECOND NUMBER:",0DH,0AH,'$'
OP1 DB ?
OP2 DB ?
.CODE
.STARTUP
;FIRST OPERAND
MOV AH, 09H
MOV DX, OFFSET MSG1
INT 21H
MOV AH, 01H

Copyright © Department of Electrical Engineering – Usman Institute of Technology


INT 21H
MOV OP1, AL
;SECOND OPERAND
MOV AH, 09H
MOV DX, OFFSET MSG2
INT 21H
MOV AH, 01H
INT 21H
MOV OP2, AL
MOV AL, OP1
MOV BL, OP2
ADD AL,BL
AAA
OR AX, 3030H
; PRINT RESULT
MOV AH, 0EH
INT 10H
.EXIT
END

AAS
The AAS (ASCII adjust after subtraction) instruction adjust the binary result of an SUB
instruction. It makes the result in AL consistent with ASCII digit representation. The
ASCII will hold in AX.

Sample Program:

.MODEL SMALL
.STACK 100H
.DATA
MSG1 DB 0DH, 0AH, "ENTER FIRST NUMBER:",0DH,0AH,'$'
MSG2 DB 0DH, 0AH, "ENTER SECOND NUMBER:",0DH,0AH,'$'
OP1 DB ?
OP2 DB ?
.CODE
.STARTUP
;FIRST OPERAND
MOV AH, 09H
MOV DX, OFFSET MSG1
INT 21H
MOV AH, 01H
INT 21H
MOV OP1, AL
;SECOND OPERAND
MOV AH, 09H
MOV DX, OFFSET MSG2
INT 21H
MOV AH, 01H
INT 21H
MOV OP2, AL

Copyright © Department of Electrical Engineering – Usman Institute of Technology


MOV AL, OP1
MOV BL, OP2
SUB AL,BL
AAS
OR AX, 3030H
; PRINT RESULT
MOV AH, 0EH
INT 10H
.EXIT
END

Copyright © Department of Electrical Engineering – Usman Institute of Technology


Lab Task
Write a program in assembly language that show a user menu as shown in FIG-01
and ask for user input if user press
A it performs addition
S it performs subtraction
E it performs Exit
R it performs return to main menu
Note: For simplicity in subtraction the first operand should be greater than second
operand.

Copyright © Department of Electrical Engineering – Usman Institute of Technology

You might also like