MP Lab Manual
MP Lab Manual
Department of CSE
Subject Code: 10CSL48
Hours/Week: 03
Total Hours: 42
Faculty: Mr. Mahesh
I.A. Marks: 25
Exam Hours: 03
Exam Marks: 50
Notes:
Develop and execute the following programs using 8086 Assembly
Language. Any suitable assembler like MASM, TASM etc may be used.
Program should have suitable comments.
The board layout and the circuit diagram of the interface are to be
provided to the student during the examination.
Session 1:
Introduction to 8086 Microprocessor programming.
P1. Search a key element in a list of n 16-bit numbers using the Binary search
algorithm.
P2. Sort a given set of n numbers in ascending order using the Bubble Sort algorithm.
Session 2:
P3. Read the current time from the system and display it in the standard format on
the screen. P4. Compute nCr using recursive procedure. Assume that n and r are
non-negative integers.
Session 3:
P5. Write a program to create a file (input file) and to delete an existing file.
P6. Write two ALP modules stored in two different files; one module is to read a
character from the keyboard and the other one is to display a character. Use the
above two modules to read a string of characters from the keyboard terminated
by the carriage return and print the string on the display in the next line.
Session 4:
P7. Reverse a given string and check whether it is a palindrome or not.
P8. Read two strings, store them in locations STR1 and STR2. Check whether
they are equal or not and display appropriate messages. Also display the length
of the stored strings.
Session 5:
P9. Read your name from the keyboard and display it at a specified location on
the screen after the message What is your name? You must clear the entire
screen before display.
P10. Read an alphanumeric character and display its equivalent ASCII code at
the center of the screen.
Session 6:
P11. Read a pair of input co-ordinates in BCD and move the cursor to the
specified location on the screen.
P12. Write a program to simulate a Decimal Up-counter to display 00-99.
Session 7:
P13. Read the status of eight input bits from the Logic Controller Interface and
display FF if it is the parity of the input read is even; otherwise display 00.
Session 10:
P19. Convert a 16-bit binary value (assumed to be an unsigned integer) to BCD
and display it from left to right and right to left for specified number of times on a
7-segment display interface.
P20. Scan a 8 x 3 keypad for key closure and to store the code of the key
pressed in a memory location or display on screen. Also display row and column
numbers of the key pressed.
Session 11:
P21. Generate the Sine Wave using DAC interface (The output of the DAC is to
be displayed on the CRO).
P22. Generate a Half Rectified Sine wave form using the DAC interface. (The
output of the DAC is to be displayed on the CRO).
Session 12:
P23. Generate a Fully Rectified Sine waveform using the DAC interface. (The
output of the DAC is to be displayed on the CRO).
P24. Drive an elevator interface in the following way:
i. Initially the elevator should be in the ground floor, with all requests in OFF state.
ii. When a request is made from a floor, the elevator should move to that floor, wait there for a
couple of seconds (approximately), and then come down to ground floor and stop. If some
requests occur during going up or coming down they should be ignored.
Note: In the examination each student picks one question from the lot of all
12 questions.
CONTENTS
1. A) BINARY SEARCH
B)
PARITY CHECK
2. A) ALP MACROS
B)
3. A) BUBBLE SORT
B)
DISPLAY X*Y
5. A) PALINDROME
B)
8. A) COMPUTING NCR
B)
GENERATE SINE-WAVE
ELEVATOR INTERFACE
.model small
.data
.code
a db 3h,5h,7h,10h,20h
n dw $-a
key db 5h
m1 db 10,13,"KEY FOUND$"
m2 db 10,13,"KEY NOT FOUND$"
.code
start:mov ax,@data
mov ds,ax mov
cx,key mov
dx,n
dec dx
mov al,key
again:cmp cx,dx
ja over1 mov
bx,cx add
bx,dx shr
bx,01h mov
si,bx cmp
al,a[si] je
over2 cmp
al,a[si] jae
big
dec si
mov dx,si
jmp again
big: inc si
mov cx,si
jmp again
over1:lea dx,m2
mov ah,09
int 21h
jmp exit
over2:lea dx,m1
mov ah,09h
int 21h
exit: mov ah,4ch
int 21h
end start
LOGIC
CONTROLLER
BOARD
PORT A
OUTPUT
(RED LEDS)
X86
MICROPROCESSOR
8
B
I
8255 PPI
(GREEN LEDS)
PORT B
INPUT
OR
INTERFACING
CARD
PORT
A
PERSONAL
COMPUTER
(PCI CARD)
B
PORT
PORT
S
W
I
T
C
H
C
PORT C
(LOWER)
OUTPUT
4
B
I
T
S
W
I
T
C
PORT C
(UPPER
)
INPUT
RDKEY
CMP AL,13
JZ EXT
STOSB
INC CX
JMP UP1
EXT:
MOV AL,0AH
ECHO
MOV AL,0DH
ECHO
LEA SI,STR
UP2:
LODSB
ECHO
LOOP UP2
MOV AH,4CH
INT 21H
END PROG
ENDM
FILE NAME F2.MAC
ECHO MACRO
MOV DL,AL
MOV AH,02H
INT 21H
ENDM
LOGIC
CONTROLLER
BOARD
PORT A
OUTPUT
(RED LEDS)
X86
MICROPROCESSOR
8255 PPI
OR
INTERFACING
CARD
PERSONAL
(PCI CARD)
COMPUTER
PORT
A
PORT
B
PORT
C
10
CMP AL,0FFH
JE UP4
JMP UP5
QUIT : MOV AH,4CH
INT 21H
DELAY PROC
PUSH CX
PUSH BX
MOV CX,05FFFH
UP2 : MOV BX,0FFFFH
UP1 : DEC BX
JNZ UP1
LOOP UP2
POP BX
POP CX
RET
DELAY ENDP
END
11
.Model Small
.data
a dw 20h,70h,40h,10h,50h
cnt equ ($-a)
.code
start:mov ax,@data
mov ds,ax mov
dx,cnt-1
again0:mov
cx,dx lea si,a
again1:mov ax,[si]
cmp ax,[si+2]
jl pr1
xchg [si+2],ax
xchg [si],ax
pr1: add si,02
loop again1
dec dx
jnz again0
mov ah,4ch
int 21h
end start
12
LOGIC
CONTROLLER
BOARD
PORT A
OUTPUT
(RED LEDS)
X86
MICRO-
(GREEN LEDS)
8
B
I
PROCESSOR
8255 PPI
OR
INTERFACING
CARD
PORT
A
PORT
(PCI CARD)
B
PORT
PERSONAL
COMPUTER
PORT B
INPUT
T
S
I
C
H
C
PORT C
(LOWER)
OUTPUT
4
B
I
PORT C
INPUT
(UPPER)
S
W
I
T
C
H
13
14
.model small
.data
msg db "ENTER A KEY",10,13,"$"
.code
start: mov ax,@data
mov ds,ax mov
ah,00h mov
al,03h
int 10h
mov dx,offset
msg mov ah,09h
int 21h mov
ah,01h int
21h mov
bl,al mov
ah,02 mov
bh,00 mov
dh,12 mov
dl,40 int
10h mov
al,bl and
al,0f0h mov
cl,04 shr
al,cl call
disp mov
al,bl and
al,0fh call
disp mov
ah,4ch int
21h
disp proc
cmp al,0ah
jb skip add
al,7h
skip: add al,30h
mov dl,al
mov ah,02h
int 21h
ret
disp endp
end start
15
X86
MICRO-
8255 PPI
PROCESSOR
INTERFACING
CARD
(PCI CARD)
OR
PERSONAL
PORT A
PORT C
COMPUTER
D5
D4
D3
D2
D1
D0
5
3 TO 8
4
PC2
PORT C PC1
PC0
D
E
C
O
D
E
R
3
2
1
0
To display a word on a Display Unit Di ( i=0 to 5), the seven segment code of
the character to be displayed on the unit is to be output through Port A, while the
display unit is selected by the combination on PC2-PC0 bits of port C.
16
7-SEGMENT CODES
Character
In Hex
71H
06H
77H
b
c
e
d
79H
76H
79H
38H
73H
CONTROL WORD:
D6
D5
D4
D3
D2
D1
D7
1
GA
GA
PA
PCU
GB
1
0
0
0
0
0
0
All ports are configured as I/O ports in Mode-0.
Port A & Port C are output ports.
D0
PB
0
PCL
= 80H
17
.CODE
START : MOV
AX,@DATA MOV DS,AX
MOV DX,9803H
MOV AL,80H
OUT DX,AL
MOV BH,0AH
AGAIN : MOV SI,OFFEST
FIRSTCODE CALL DISPLAY1
CALL DELAY
MOV SI,OFFSET SECCODE
CALL DISPLAY1
CALL DELAY
DEC BH
CMP BH,00H
JE TERMINATE
JMP AGAIN
DISPLAY1 PROC
MOV CX,04H
LOOP2 : MOV
BL,08H MOV AL,[SI]
NEXT : ROR AL,01H
MOV DX,9801H
OUT DX,AL
PUSH AX
MOV AL,0FFH
INC DX
OUT DX,AL
MOV AL,00H
OUT DX,AL
DEC BL
POP AX
JZ NEXT1
JMP NEXT
NEXT1 : INC SI
LOOP
LOOP2 RET
DISPLAY1 ENDP
DELAY PROC
PUSH AX
PUSH CX
MICROPROCESSOR LAB (10CSL48)
DEPT. OF COMPUTER SCIENCE & ENGG. IV SEM
18
MOV CX,0FFFFH
LOOP1 : MOV AX,0FFFH
LOOP3 : DEC AX
JNZ LOOP3
LOOP LOOP1
POP CX
POP
AX RET
DELAY ENDP
TERMINATE : MOV
AH,4CH INT 21H
END START
19
.model small
.data
str db "MADAM$"
len equ 5
rstr db 10 dup(?)
msg1 db 10,13,"PALINDROME$"
msg2 db 10,13,"NOT A PALINDROME$"
.code
mov ax,@data
mov ds,ax
mov es,ax
lea si,str
lea di,rstr
add di,len
dec di
mov cl,len
lea dx,msg2
mov ah,09h
int 21h
jmp
exit END
20
.MODEL SMALL
.DATA
STRING DB 0C0H, 0F9H, 0A4H, 0B0H, 099H, 092H, 082H, 0F8H, 080H,
098H, 88H, 83H, 0C6H
LEN DW ($-STRING)
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AL,080H
MOV DX,9803H
OUT DX,AL
L1 : MOV CX,LEN
LEA SI,STRING
L2 : MOV AL,[SI]
CALL DISPLAY1
CALL DELAY
INC SI
LOOP L2
JMP TERMINATE
DISPLAY1
PROC PUSH CX
MOV CX,08
L3 : MOV DX,9801H
ROL AL,01
OUT DX,AL
PUSH AX MOV
DX,9802H
MOV AL,0FFH
OUT DX,AL
MOV AL,00H
OUT DX,AL
POP AX
LOOP L3
POP CX
RET
DISPLAY1 ENDP
TERMINATE : MOV AH,4CH
INT 21H
DELAY PROC
PUSH CX
PUSH BX
MOV CX,03FFFH
L4 : MOV BX,0FFFFH
L5 : DEC BX
JNZ L5
MICROPROCESSOR LAB (10CSL48)
DEPT. OF COMPUTER SCIENCE & ENGG. IV SEM
21
LOOP L4
POP BX
POP CX
RET
DELAY ENDP
END
22
23
DISP M5
JMP NEXT
STRNODE :DISP M6
NEXT :DISP M3
MOV AL,L1
CALL DISPL
DISP M4
MOV AL,L2
CALL DISPL
MOV AH,4CH
INT 21H
READ PROC
MOV AH,0AH
INT 21H
RET
READ ENDP
DISPL PROC
AAM
MOV BX,AX
ADD BX,3030H
MOV AH,2
MOV DL,BH
INT 21H
MOV DL,BL
INT 21H
RET
DISPL ENDP
END
24
PB EQU 9801H
PC EQU 9802H
CW EQU 9803H
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AL,90H
MOV DX,CW
OUT DX,AL MOV
CX,BIN MOV
AX,00H
AGN : ADD
AL,1 DAA
JNC NOINCAH
ADD AH,1
MOV AL,AH
DAA
MOV AH,AL
MOV AL,00
NOINCAH : LOOP AGN
MOV DX,AX
MOV BL,10H
MOV AH,00
MOV AL,DH
DIV BL
MOV BCD,AL
MOV BCD+1,AH
MOV AH,00
MOV AL,DL DIV
BL
MOV BCD+2,AL
MOV BCD+3,AH
MOV CL,0AH
REPEAT : CALL BCDLDISP
CALL DELAY1
CALL BCDRDISP
CALL DELAY1
LOOP REPEAT
MOV AH,4CH
MICROPROCESSOR LAB (10CSL48)
DEPT. OF COMPUTER SCIENCE & ENGG. IV SEM
25
INT 21 BCDLDISP
PROC
PUSH CX
MOV SI,3
NEXTCHAR : MOV AH,08H
MOV AL,BCD[SI]
LEA BX,DISPTBL
XLAT
NEXTSEG : MOV
DX,PB OUT DX,AL
MOV CH,AL
MOV AL,00H
MOV DX,PC
OUT DX,AL
MOV AL,0FFH
OUT DX,AL
DEC AH
JZ OVERCHK
MOV AL,CH
ROR AL,01 JMP
NEXTSEG
OVERCHK : DEC SI
CMP SI,-1H
JNE NEXTCHAR
POP CX
RET
BCDLDISP ENDP
BCDRDISP
PROC PUSH CX
MOV SI,0
NEXTCHAR1 : MOV AH,08H
MOV AL,BCD[SI]
LEA BX,DISPTBL
XLAT
NEXTSEG1 : MOV
DX,PB OUT DX,AL
MOV CH,AL
MOV AL,00H
MOV DX,PC
OUT DX,AL
MOV AL,0FFH
OUT DX,AL
DEC AH
JZ OVERCHK1
MOV AL,CH ROR
AL,01 JMP
NEXTSEG1
OVERCHK1 : INC SI
CMP SI,04
JNE NEXTCHAR1
POP CX
MICROPROCESSOR LAB (10CSL48)
DEPT. OF COMPUTER SCIENCE & ENGG. IV SEM
26
RET
BCDRDISP ENDP
DELAY1 PROC
PUSH CX
PUSH BX
MOV CX,0FAAH
L4 : MOV BX,0FFFFH
L3 : DEC BX
JNZ L3
LOOP L4
POP BX
POP CX
RET
DELAY1 ENDP
END
27
EXPERIMENT NO.:- 7(a) READ FROM KEY BOARD & DISPLAY ON SCREEN
AIM: Read your name from the keyboard and display it at a specified location
on the screen in front of the message What is your name? You must clear the
entire screen before display.
strread macro
loc mov
ah,01h int
21h mov
loc,al endm
.model small
.data
m1 db "WHAT IS UR NAME ?$
" arr db 20h dup(?)
.code
start: mov ax,@data
mov ds,ax mov
si,0h
loop1: strread
arr[si] inc si
cmp al,13
jnz loop1
mov arr[si],"$"
mov ah,00h
mov al,03h
int 10h
mov ah,02h
mov bh,00h
mov dh,12h
mov dl,20h
int 10h
lea dx,m1
mov ah,09h
int 21h
mov si,0h
lea dx,arr[si]
mov ah,09h
int 21h
mov ah,4ch
int 21h
end start
MICROPROCESSOR LAB (10CSL48)
DEPT. OF COMPUTER SCIENCE & ENGG. IV SEM
28
X86
MICRO-
K
E
Y
B
O
A
R
8255 PPI
PROCESSOR
INTERFACING
CARD
(PCI CARD)
OR
PORT A
PORT C
I
N
T
PERSONAL
E
R
F
A
C
COMPUTER
PORT C PC1
PC2
CE
7
%
PA0
PA1
PA2
PA3
PORT A
PA4
PA5
PA6
PA7
29
EXPERIMENT NO.:- 7(b) DISPLAY OF ROW & COLUMN NO. OF KEY PRESSED
AIM: Scan an 8 x 3 keypad for key closure and to store the code of the key
pressed in a memory location or display on screen. Also display row and
column numbers of the key pressed.
.MODEL SMALL
.DATA
DISP DB 0123456789.+-X/%ACH=WXYZ$
MSG DB 10,13,KEY PRESSED IS ,$
MSG1 DB 10,13,THE ROW NUMBER IS =
ROW DB ?,10,13,$
MSG2 DB 10,13,THE COLUMN NUMBER IS
= COL DB ?,10,13,$
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AL,90H
MOV DX,9803H
OUT DX,AL
REPEAT : MOV DX,9802H
MOV AL,01H
OUT DX,AL
MOV DX,9800H
IN AL,DX
CMP AL,00
JNZ F_C
MOV DX,9802H
MOV AL,02H
OUT DX,AL
MOV DX,9800H
IN AL,DX
CMP AL,00
JNZ S _C
MOV AL,04H
MOV DX,9802H
OUT DX,AL
MOV DX,9800H
IN AL,DX
CMP AL,00
JNZ T_C JMP
REPEAT
JMP NEXT1
S_C : MOV SI,OFFSET
DISP ADD SI,08H
MICROPROCESSOR LAB (10CSL48)
DEPT. OF COMPUTER SCIENCE & ENGG. IV SEM
30
MOV ROW,32H
MOV CL,30H
NEXT2 : INC CL
SHR AL,01
JC DISP1
INC SI
JMP NEXT2
T_C : MOV SI,OFFSET
DISP ADD SI,10H
MOV ROW,33H
MOV CL,30H
NEXT3 : INC CL
SHR AL,01
JC DISP1
INC SI
JMP NEXT3
DISP1 : LEA DX,MSG
MOV AH,09H
INT 21H MOV
DL,[SI] MOV
AH,02H INT
21H MOV
DL,0DH MOV
AH,02H INT
21H MOV
COL,CL
MOV DX,OFFSET
MSG1 MOV AH,09H
INT 21H
MOV DX,OFFSET
MSG2 MOV AH,09H
INT 21H MOV
AH,4CH INT
21H
END
31
.model small
.data
n dw 3h
r dw 2h
ret
res1: inc ncr
ret
resn: add
ncr,ax ret
MICROPROCESSOR LAB (10CSL48)
DEPT. OF COMPUTER SCIENCE & ENGG. IV SEM
32
ncrproc
endp end
33
8255 PPI
INTERFACING
CARD
(PCI CARD)
PERSONAL
COMPUTER
PORT C
STEPPER
MOTOR
INTERFACING
MODULE
STEPPER MOTOR-1
STEP SEQUENCE
PC3PC2_PC1PC0ORPC
7PC6PC5_PC4__1110110
PC3-PC0
STEPPER
MOTOR
INTERFACING
PORT C
(PC7-
110110111
STEPPER MOTOR-1
MODULE
PC0)
PC7-PC4
ANTI-
CLOCK
CLOCK
STEPPER MOTOR-2
(OPTIONAL)
D0
PB
0
PCL
= 80H
34
CLOCKWISE PROGRAM:
.MODEL SMALL
.DATA
N DW 200
.CODE
MOV AX,@DATA
MOV DS,AX
MOV DX,09803H
MOV AL,80H
OUT DX,AL MOV
DX,09800H MOV
AL,88H MOV
CX,N
AGAIN : OUT DX,AL
CALL DELAY
ROR AL,01
LOOP AGAIN
MOV AH,4CH
INT 21H
DELAY PROC
PUSH BX
PUSH CX
MOV CX,0FFFH
REPEAT : MOV BX,0FFFFH
HERE1 : DEC BX
JNZ HERE1
REPEAT
POP CX
POP BX
RET
DELAY
ENDP END
ANTICLOCKWISE PROGRAM:
.MODEL SMALL
.DATA
N DW 200
.CODE
MOV AX,@DATA
MOV DS,AX
MOV DX,09803H
MOV AL,80H
OUT DX,AL MOV
DX,09800H MOV
AL,88H MOV
CX,N
MICROPROCESSOR LAB (10CSL48)
DEPT. OF COMPUTER SCIENCE & ENGG. IV SEM
35
DELAY
ENDP END
36
.model small
.code
mov ah,2ch
int 21h
mov al,ch
aam
mov bx,ax
call disp
mov dl,':'
mov ah,02h
int 21h
mov al,cl
aam
mov bx,ax
call disp
mov ah,4ch
int 21h
disp proc
mov dl,bh
add dl,30h
mov ah,02h
int 21h mov
dl,bl add
dl,30h mov
ah,02h int
21h
ret
disp endp
end
37
8255 PPI
PROCESSOR
INTERFACING
CARD
(PCI CARD)
OR
PERSONAL
COMPUTER
DUAL DAC
INTERFACE
MODULE
PORT A
OR
CRO
PORT B
OUT1
CRO
DAC 1
GND
(OPTIONAL)
PORT B
OUT2
(PB0-PB7)
DAC 2
CRO
GND
D1
GB
0
D0
PB
0
PCL
= 80H
38
.CODE
MOV AX,@DATA
MOV DS,AX
MOV DX,9803H
MOV AL,80H
OUT DX,AL
UP1:LEA SI,ARR
MOV CX,60 UP:
MOV AL,[SI]
MOV DX,9800H
OUT DX,AL
MOV DX,9801H
OUT DX,AL
CALL DELAY
INC SI
LOOP UP
JMP UP1
MOV AH,4CH
INT 21H
DELAY PROC
PUSH BX
PUSH CX
MOV CX,0FH
REPEAT : MOV BX,0FFH
HERE1 : DEC BX
JNZ HERE1
LOOP REPEAT
POP CX
POP BX
RET
DELAY
ENDP END
39
.model small
.code
mov al,030h
loop1: mov dl,al
mov ah,02h
int 21h
push ax
mov bl,030h
loop2: mov dl,bl
mov ah,02h
int 21h
inc bl call
delay
mov ah,03h
int 10h
mov dl,01h
mov ah,02h
int 10h
cmp bl,039h
jle loop2
mov dl,00h
mov ah,02h
int 10h
pop ax
inc al
cmp al,039h
jle loop1
mov ah,4ch
int 21h
delay proc
push cx
push bx
mov cx,0fffh
loop3: mov bx,0ffffh
loop4: dec bx
jnz loop4
loop loop3
pop bx
MICROPROCESSOR LAB (10CSL48)
DEPT. OF COMPUTER SCIENCE & ENGG. IV SEM
40
pop
cx ret
delay
endp end
41
.CODE
MOV AX,@DATA
MOV DS,AX
MOV DX,9803H
MOV AL,80H
OUT DX,AL
UP1:LEA SI,ARR
MOV CX,60 UP:
MOV AL,[SI]
MOV DX,9800H
OUT DX,AL
MOV DX,9801H
OUT DX,AL
CALL DELAY
INC SI
LOOP UP
JMP UP1
MOV AH,4CH
INT 21H
DELAY PROC
PUSH BX
PUSH CX
MOV CX,0FH
REPEAT : MOV BX,0FFH
HERE1 : DEC BX
JNZ HERE1
LOOP REPEAT
POP CX
POP BX
RET
DELAY
ENDP END
42
endm
.model small
.data
m1 db 10,13,"ENTER ROW VALUE (00-24)
$" m2 db 10,13,"ENTER COL VALUE (0079) $" m3 db 10,13,"PRESS ANY KEY $"
row db ?
col db ?
.code
mov ax,@data
mov ds,ax
disp m1
call read
mov row,al
disp m2 call
read mov
ah,08h int
21h
mov col,al
disp m3
mov ah,00h
mov al,03h
int 10h
mov dh,row
mov dl,col
mov ah,02h
int 10h
mov ah,08h
int 21h
mov ah,4ch
MICROPROCESSOR LAB (10CSL48)
DEPT. OF COMPUTER SCIENCE & ENGG. IV SEM
43
int 21h
read proc
mov ah,01h
int 21h
and al,0fh
mov bl,al
mov ah,01h
int 21h
and al,0fh
mov ah,bl
aad
ret
read
endp end
44
H,OFBH,0F8H,0F3H,0EDH
DB 0E6H,0DDH,0D4H,0CAH,0BFH,0B2H,0A6H,99H,08CH,7FH
.CODE
MOV AX,@DATA
MOV DS,AX
MOV DX,9803H
MOV AL,80H
OUT DX,AL
UP1:LEA SI,ARR
MOV CX,30H
UP: MOV AL,[SI]
MOV DX,9800H
OUT DX,AL
MOV DX,9801H
OUT DX,AL
CALL DELAY
INC SI
LOOP UP
JMP UP1
MOV AH,4CH
INT 21H
DELAY PROC
PUSH BX
PUSH CX
MOV CX,0FH
REPEAT : MOV BX,0FFH
HERE1 : DEC BX
JNZ HERE1
LOOP REPEAT
POP CX
POP BX
RET
DELAY
ENDP END
45
.MODEL SMALL
.DATA
MSG1 DB 10, 13,"PRESS 1: CREATE FILE 2: DELETE
FILE$" MSG2 DB 10, 13,"ENTER YOUR CHOICE: $"
MSG3 DB 10, 13,"ERROR$" F1
DB "anu.TXT$", 0
.CODE
MOV AX,@DATA
MOV DS, AX
LEA DX, MSG1
CALL DISP
LEA DX, MSG2
CALL DISP
MOV AH, 1H
INT 21H
CMP AL,'1'
JE CREATE
CMP AL,'2'
JE DELETE
ERROR: LEA DX, MSG3
CALL DISP
EXIT: MOV AH, 4CH
INT 21H
CREATE: MOV CX, 0
LEA DX, F1
MOV AH,
3CH INT 21H
JC ERROR
JMP EXIT
DELETE: LEA DX, F1
MOV AH, 41H
INT 21H
JC ERROR
JMP EXIT
DISP PROC NEAR
MOV AH, 9
INT 21H
RET
DISP ENDP
END
46
X86
MICRO-
E
L
E
V
A
T
O
R
NUMBER
(REQUEST
SWITCH INDICATOR)
8255 PPI
3(R)
PROCESSOR
INTERFACING
OR
CARD
(PCI CARD) PORT A
2(R)
PERSONAL
POSITION OF ELEVATOR
PORT B
COMPUTER
B
O
A
R
1(R)
0(R)
G
Y
Y
G
Y
Y
G
Y
Y
G
Q
_
CP
270
270
Y
SECOND
CP
Q
_
Y
FIRST
Q
R
Y
R
GROUND
A00
A11
A22
CP
Q
Q
74LS4
2
CP
PORT
OUT
A(PA7-PA4)
U1
PORT
B(PB3-PB0)
IN
PORT A(PA3-PA0)
OUT
The following points to be noted w.r.t the usage of elevator interface by the programmer.
1. The BCD value on PA3-PA0 (Output) indicates the position of elevator (0 to 9).
Lift position LEDs (Green) indicates the position of Lift at any time.
2. The bits in the PA7-PA4 (Output) can be used to RESET Request LED (Red). The bits
corresponding to a floor must be reset to logic 0 to turn off corresponding request LED.
3. The status of Request LEDs can be read by port PB3-PB0. Logic 0 in a bit
indicates the Request from a floor and the corresponding Red LED is seen glowing.
4. Switches (or Keys) are used to signal elevator service request, which turns on Red LEDs.
47
CONTROL WORD:
D7
1
1
D6
GA
0
D5
D4
D3
D2
GA
PA
PCU
0
0
0
0
D1
GB
1
D0
PB
0
PCL
= 82H
All ports are configured as I/O ports in Mode-0. Port A is output and Port B is Input.
48
Initially the elevator should be in the ground floor, with all requests in OFF state.
When a request is made from a floor, the elevator should move to that floor, wait there for
a couple of seconds, and then come down to ground floor and stop. If some requests
occur during going up or coming down they should be ignored.
.MODEL SMALL
.STACK
.DATA
ARR DB 04H, 07H, 0AH, 0D3H, 0B6H, 79H
.CODE
MOV AX,@DATA
MOV DS,AX
MOV DX,9803H
MOV AL,82H
OUT DX,AL
LEA SI,ARR
MOV DX,9800H
MOV AL,0F0H
OUT DX,AL
MOV DX,9801H
UP: IN AL,DX
OR AL,0F0H
CMP AL,0FFH
JE UP
SHR AL,01H
JNC DN0
SHR AL,01H
JNC DN1
INC SI
SHR AL,01
JNC DN1
INC SI
DN1:MOV CL,[SI]
MOV BL,CL
MOV DX,9800H
MOV AL,0F0H
UP1:OUT DX,AL
CALL DELAY
INC AL LOOP
UP1 ADD
SI,0003H
MOV AL,[SI]
OUT DX,AL
MOV CL,BL
DEC CL
UP2:DEC AL
OUT DX,AL
CALL DELAY
LOOP UP2
MICROPROCESSOR LAB (10CSL48)
DEPT. OF COMPUTER SCIENCE & ENGG. IV SEM
49
JMP STOP
DN0:CALL DELAY
CALL DELAY MOV
DX,9800H MOV
AL,0E0H OUT
DX,AL STOP:MOV
AH,4CH INT 21H
DELAY PROC
PUSH BX
PUSH CX
MOV CX,0FFFH
REPEAT : MOV BX,0FFFFH
HERE1 : DEC BX
JNZ HERE1
LOOP REPEAT
POP CX
POP BX
RET
DELAY
ENDP END
50
51