EC8681-MPMC Research

You might also like

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

V-SEMESTER B.Tech.

IT
EC8681 – MICROPROCESSORS AND MICROCONTROLLERS LAB
INDEX

Ex. No, Name of the experiment Page

Programs using 8086 microprocessor

1. Basic arithmetic and logical operations using 8086

2. Move a data block without overlap

3. a) Code Conversion: Hexadecimal To Decimal

b) Decimal Arithmetic

c) Matrix Addition

d) Matrix Multiplication

4. a) String Manipulation

b) Sorting of elements in ascending order

c) Search an element in an array of list

5. a) Password checking

b) Print system date

6. Interfacing 8086 with 8255 for Traffic Light Control

7. Stepper Motor Control

Keyboard and Display Interface (8279) with 8086 for


8.
Rolling Display

Programs using 8051 microcontroller

9. Basic arithmetic and logical operations

10. a) 2’s Complement of an 8-bit number


b) Square of an 8-bit number
c) Cube of an 8-bit number

11. Unpacked BCD to ASCII


Ex. No: 1. Basic arithmetic and logical operations using 8086

Aim: To write an 8086 assembly language programs to perform basic arithmetic and logical
operations.

1.a. 16-bit addition

Algorithm:
1. Start
2. Load the 1st data into AX register from the memory location 1100H.
3. Add 1st data in AX with 2nd data from the memory location 1102H.
4. Store the AX result in memory location 1104H.
5. Stop
Program:
MOV AX, [1100H]
ADD AX, [1102H]
MOV [1104H], AX
HLT

Input: Data1: 3471 Data2: 6835

Output: 9CA6

1.b. 16-bit subtraction

Algorithm:
1. Start
2. Load the 1st data into AX register from the memory location 1100H.
3. Load the 2nd data from with memory location 1102H and subtract from AX.
4. Store the AX result in memory location 1104H.
5. Stop
Program:
MOV AX, [1100H]
SUB AX, [1102H]
MOV [1104H], AX
HLT

Input: Data1: 9814 Data2: 6273

Output: 35A1
1.c. 16-bit multiplication

Algorithm:
1. Start
2. Load the 1st data into AX register from the memory location 1100H.
3. Load the 2nd data into BX register from the memory location 1102H.
4. Multiply AX and BX
5. Store the AX result in memory location 1104H.
6. Store the DX result in memory location 1106H.
7. Stop
Program:
MOV AX,[1100H]
MOV BX,[1102H]
MUL BX
MOV [1104H],AX
MOV [1106H],DX
HLT

Input: Data1: 3412 Data2: 7856


Output: 1879 EE0C

1.d. 16-bit division

Algorithm:
1. Start
2. Load the lower 16-bit dividend into AX register
3. Load the higher 16-bit dividend into DX register
4. Load the 16-bit divisor into BX register
5. Divide the dividend by the divisor
6. Store the AX result (Quotient) into memory location 1200H.
7. Store the DX result (Remainder) into memory location 1202H.
8. Stop
Program:
MOV AX,1243H
MOV DX,1879H
MOV BX,7855H
DIV BX
MOV [1200H],AX
MOV [1202H],DX
HLT

Input: Dividend: 18791243H Divisor: 7855


Output: [1200H]: 3410H (Quotient) [1202H]: 48F3H (Remainder)
1.e. Logical AND operation:

Algorithm:
1. Start
2. Load the 1st data into AX register from the memory location 1100H.
3. AND 1st data in AX with 2nd data from the memory location 1102H.
4. Store the AX result into memory location 1104H.
5. Stop
Program:
MOV AX, [1100H]
AND AX, [1102H]
MOV [1104H], AX
HLT

Input: Data1: [1100H]: B1 [1101]:C5


Data2: [1102H]: C5 [1103]:13

Output: [1104]: 81 [1105]: 01

1.f. 2’s complement using logical NOT operation:

Algorithm:
1. Start
2. Load the 1st data into AX register from the memory location 1100H.
3. Perform the NOT operation on AX.
4. Add 01H to AX register
5. Store the AX result into memory location 1200H.
6. Stop
Program:
MOV AX, [1100H]
NOT AX
ADD AX, 0001H
MOV [1102H], AX
HLT

Input: [1100H]: 1A35

Output: [1102]: E5CB

Result:
Thus the 8086 ALP for basic arithmetic and logical operations were successfully executed.
Ex. No: 2. Move a data block without overlap

Aim:
To write an 8086 ALP to move a data block without overlap.

Algorithm:
1. Start
2. Load the starting address of source data block in SI register
3. Load the destination address in DI register to move the data block
4. Store the count value for number of data in CX register
5. Move the data from source location to destination location
6. Increment SI and DI
7. Repeat the operation from step 5 until counter CX will be 0.
8. Stop

Program:
MOV SI,2000H
MOV DI,3000H
MOV CX,08H
L1: MOV AX,[SI]
MOV [DI],AX
INC SI
INC DI
LOOP L1
HLT

Input: Output:
[2000]=15 [3000]=15
[2001]=40 [3001]=40
[2002]=25 [3002]=25
[2003]=50 [3003]=50
[2004]=35 [3004]=35
[2005]=20 [3005]=20
[2006]=45 [3006]=45
[2007]=30 [3007]=30

Result:
Thus the 8086 ALP for moving a data block without overlap was successfully executed.
Ex. No: 3.a) CODE CONVERSION: HEXADECIMAL TO DECIMAL

Aim:
To write an 8086 ALP to convert the hexadecimal number to decimal.

Algorithm:
1. Start
2. The number is divided by powers of 10 starting from 10000 to 10.
3. The input number is divided by 2710H (10000d) and the quotient is the most significant
digit of the decimal number.
4. The remainder is divided by 3E8H (1000d) and the quotient is the next
most significant digit.
5. The remainder is divided by 64H (100d) and the quotient likewise stored to obtain the
100's digit.
6. The remainder is divided by 0AH (10d) and the quotient is the tens digit, the remainder
being the units digit of the resultant decimal number.
7. Stop

Program:
CODE SEGMENT
ASSUME CS:CODE
ORG 1000h
MOV AX,0F54Eh
MOV DX,0h
MOV CX,2710H
DIV CX
AND AX,00FFh
MOV SI,1200h
MOV [SI],AL
MOV AX,DX
MOV DX,0h
MOV CX,03E8H
DIV CX
AND AX,00FFh
INC SI
MOV [SI],AL
MOV AX,DX
MOV BL,64H
DIV BL
INC SI
MOV [SI],AL
AND AX,0FF00h
MOV AL,AH
MOV AH,0h
MOV BL,0AH
DIV BL
INC SI
MOV [SI],AL
INC SI
MOV [SI],AH
MOV AH,4CH
INT 21H
CODE ENDS
END

Input: F54E Output: [1200]=06, [1201]=02, [1202]=07, [1203]=09, [1204]=08

Result:
Thus the 8086 ALP to convert hexadecimal number into decimal was successfully executed.

Ex. No: 3.b) Decimal Arithmetic

Aim:
To write an 8086 ALP to perform the decimal arithmetic operations.

Algorithm:
1. Start
2. Load the 1st data in AL register and 2nd data in BL register
3. Add the AL and BL
4. Perform the decimal adjust after addition and store the result in memory
5. Load the 1st data in AL register and 2nd data in BL register
6. Subtract the BL from AL
7. Perform the decimal adjust after subtraction and store the result in memory
8. Stop

Program:
CODE SEGMENT
ASSUME CS:CODE
ORG 1000H
MOV SI,1200H
MOV AL,[SI]
INC SI
MOV BL, [SI]
ADD AL,BL
DAA
INC SI
MOV [SI],AL

MOV SI,1210H
MOV AL,[SI]
INC SI
MOV BL,[SI]
SUB AL,BL
DAS
INC SI
MOV [SI],AL

MOV AH,4CH
INT 21H
CODE ENDS
END

For Decimal Addition For Decimal Subtraction


INPUT INPUT
[1200] : 05 [1200] : 25
[1201 ] : 06 [1201] : 07

OUTPUT OUTPUT
[1202] : 11 [1202] : 18

Result:
Thus the 8086 ALP to perform decimal arithmetic was successfully executed.

Ex. No: 3.c) Matrix Addition

Aim:
To write an 8086 ALP to perform the matrix addition.

Algorithm:
1. Start
2. Assign the address of 1st matrix in SI pointer and 2st matrix in DI pointer
3. Load the 1st matrix element in AL and Add with 2nd matrix element
4. Store the result in memory location pointed by BX register.
5. Stop
Program:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
ORG 1200H
DIM EQU 09
MAT1 DB 01,02,03,04,05,06,07,08,09
MAT2 DB 02,04,06,08,01,03,05,07,09
RESMAT DW 09H DUP(?)
DATA ENDS

CODE SEGMENT
ORG 4000H
MOV AX,DATA
MOV DS,AX
MOV CX,DIM
MOV SI,OFFSET MAT1
MOV DI,OFFSET MAT2
MOV BX,OFFSET RESMAT
NEXT: XOR AX,AX
MOV AL,[SI]
ADD AL,[DI]
MOV WORD PTR [BX], AX
INC SI
INC DI
ADD BX,02
LOOP NEXT
MOV AH,4CH
INT 21H
CODE ENDS
END

Input:
Matrix-A: 01 02 03 Matrix-B 02 04 06
04 05 06 08 01 03
07 08 09 05 07 09

Output: 03 06 09
0C 06 09
0C 0F 12

Result:
Thus the 8086 ALP to perform matrix addition was successfully executed.
Ex. No: 3.d) Matrix Multiplication

Aim: To write an 8086 ALP to perform the matrix multiplication

Algorithm:
1. Start
2. Assign the address of 1st matrix in SI pointer and 2st matrix in DI pointer
3. Multiply the 1st matrix and 2nd matrix elements
4. Store the result in memory location pointed by BX register.
5. Stop

Program:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
ORG 1200H
ROWCOL EQU 03H
MAT1 DB 01,02,03,04,05,06,07,08,09
MAT2 DB 01,02,03,04,05,06,07,08,09
RESMAT DW 09H DUP(?)
DATA ENDS

CODE SEGMENT
ORG 4000H
MOV AX,DATA
MOV DS,AX
MOV CH,ROWCOL
MOV BX,OFFSET RESMAT
MOV SI,OFFSET MAT1
NXTRW: MOV DI,OFFSET MAT2
MOV CL,ROWCOL
NXTCL: MOV DL,ROWCOL
MOV BP,0000H
MOV AX,0000H
NXTEL: MOV AL,[SI]
MUL BYTE PTR [DI]
ADD BP,AX
INC SI
ADD DI,03
DEC DL
JNZ NXTEL
SUB DI,08
SUB SI,03
MOV [BX], BP
ADD BX,02
DEC CL
JNZ NXTCL
ADD SI, 03
DEC CH
JNZ NXTRW
MOV AH,4CH
INT 21H
CODE ENDS
END

Input:
Matrix-A: 01 02 03 Matrix-B 01 02 03
04 05 06 04 05 06
07 08 09 07 08 09

Output: IE 24 2A
42 51 60
66 7E 96

Result:
Thus the 8086 ALP to perform matrix multiplication was successfully executed.
Ex. No: 4.a) STRING MANIPULATION

Aim:
To write an 8086 ALP to perform string manipulation.

Algorithm:
1. Start
2. Perform the move string byte operation
3. Perform the load string byte operation
4. Perform the store string byte operation
5. Perform the compare string byte operation
6. Perform the scan string byte operation
7. Stop

PROGRAM:

ASSUME CS:CODE,DS:DATA
DATA SEGMENT
ORG 0500H
SSTR DB 'abcd'
MBT DB 04H DUP(?)
SBT DB 04H DUP(?)
CSTR DB 'abde'
CBT1 DB 01H DUP(?)
CBT2 DB 01H DUP(?)
SNBT DB 01H DUP(?)
DATA ENDS
CODE SEGMENT
ORG 1000H
MOV AX,DATA
MOV DS,AX
MOV ES,AX

LEA SI,SSTR
LEA DI,MBT ; ****MOVE STRING BYTE****
MOV CX,04H
CLD
XX: MOVSB
LOOP XX

CLD ; ****LOAD STRING BYTE****


LEA SI,SSTR
LODSB

MOV CX,04H ; ****STORE STRING BYTE****


LEA DI,SBT
CLD
SR: STOSB
LOOP SR

CLD ; ****COMPARE STRING BYTE****


MOV CX,04H
LEA SI,SSTR
LEA DI,MBT
REPE CMPSB
JNE J1
MOV CBT1,01H
JMP J2
J1: MOV CBT1,02H

J2: CLD
MOV CX,04H
LEA SI,SSTR
LEA DI,CSTR
REPE CMPSB
JNE J3
MOV CBT2,01H
JMP J4
J3: MOV CBT2,02H
J4:
CLD ; ****SCAN STRING BYTE****
MOV CX,04H
LEA DI,SSTR
MOV AL,'f'
REPNE SCASB
JNE J5
MOV SNBT,03H
JMP J6
J5: MOV SNBT,04H

J6: MOV AH,4CH


INT 21H
CODE ENDS
END

Input:
Source string sstr: abcd

Output:
Move String Byte: abcd
Load String Byte: a
Store String Byte: aaaa
Compare String Byte: ‘abcd’ and ‘abcd’ String equal
Compare String Byte: ‘abcd’ and ‘abde’ String not equal
Scan String Byte: character f is scanned in the string abcd f is not found in the string abcd

Result:
Thus the 8086 ALP to perform string manipulation was successfully executed.
Ex. No: 4.b) Sorting of elements in ascending order

Aim:
To write an 8086 ALP to sort the elements in ascending order.

Algorithm:
1. Start
2. Read number of elements
3. Read the elements
4. Sort the elements by comparing them and store it in appropriate location
5. Stop

Program:
ASSUME CS:CODE,DS:MYDA
MYDA SEGMENT
ORG 2000H
N DB 05H
DATA1 DB 51H
DATA2 DB 47H
DATA3 DB 69H
DATA4 DB 5FH
DATA5 DB 12H
MYDA ENDS

CODE SEGMENT
ORG 1000H
MOV AX,DATA
MOV DS,AX
MOV SI,2000H
MOV CL,[SI]
DEC CL

STEP1: MOV SI,2000H


MOV CH,[SI]
DEC CH
INC SI

STEP2: MOV AL,[SI]


INC SI
CMP AL,[SI]
JC STEP3
XCHG AL,[SI]
XCHG AL,[SI-1]
STEP3: DEC CH
JNZ STEP2
DEC CL
JNZ STEP1
MOV AH,4CH
INT 21H
CODE ENDS
END

Input:
N=05H
Elements: 51H, 47H, 69H, 5FH, 12H

Output:

After sorting:

Elements: 12H, 47H, 51H, 5FH, 69H

Result:
Thus the 8086 ALP to sort the elements in ascending order was successfully executed.

Ex. No: 04.c) Search an element in an array of list

Aim:
To write an 8086 ALP to search an element in an array of list.

Algorithm:
1. Start
2. Read number of elements
3. Read all the elements for the list
4. Get the key element to be searched
5. Compare the key element with all the elements in the list
6. If found, display the position of the element in the list.
7. Stop

Program:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
ORG 1500H
COUNT DB 08H
ELEMENT DB 36H,51H,82H,19H,75H,23H,48H,64H
KEY DB 23H
AVAIL DB ?
POSITION DB ?
DATA ENDS

CODE SEGMENT
ORG 2000H
MOV AX,DATA
MOV DS,AX
MOV SI,OFFSET COUNT
MOV CL,[SI]
MOV BX,00H

NEXT: MOV AL,ELEMENT[BX]


CMP AL,KEY
JE FOUND
INC BX
DEC CL
JNZ NEXT
MOV AVAIL,00H
MOV POSITION,00H
JMP SKIP

FOUND: MOV SI, OFFSET POSITION


INC BX
MOV [SI],BX
MOV AVAIL,01H

SKIP: MOV AH,4CH


INT 21H
CODE ENDS
END

Input:
No. of elements: 08H
Elements: 36H, 51H, 82H, 19H, 75H, 23H, 48H, 64H

Output:
Element to be searched: 23H Element 23 is found in the list and position 6

Element to be searched: 50H Element 50 is not found in the list

Result:
Thus the 8086 ALP to search an element in an array of list was successfully executed.
Ex. No: 5.a) Password checking

Aim:
To write an 8086 ALP to check the password.

Algorithm:
1. Start
2. Store the password.
3. Enter the password to get into the login.
4. Validate the entered password with already stored password
5. If they match, login will be successful otherwise reenter the correct password
6. Stop

Program:
PRINTSTRING MACRO msg
MOV AH,09H ;Request for display
MOV DX,OFFSET msg
INT 21H ;Call DOS service
ENDM

DATA SEGMENT
ORG 1000H
CR EQU 0DH
LF EQU 0AH
PASSWORD DB 'INDIA123',CR
msg1 DB 'Enter password: ','$'
msg2 DB CR,LF,'Enter password again: ','$'
msg3 DB CR,LF,'You are unauthorized person','$'
msg4 DB CR,LF,'Welcomes You','$'
str1 DB 80 dup(?)
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA ;Initialize CS,DS
ORG 2000H
START: MOV AX,DATA ;Initialize DS to data segment
MOV DS,AX

PRINTSTRING msg1

NEXTATTEMPT: ;Read characters without echo


MOV SI, OFFSET str1

RDCHAR:
MOV AH,08H ;Read request without echo
INT 21H ;Call DOS Service
;Returns character in AL
MOV [SI],AL
;Display '*' instead of character
PUSH AX
MOV AH,02 ;Display character
MOV DL, '*'
INT 21H ;Call DOS service
POP AX
INC SI
CMP AL,CR
JNE RDCHAR ;Read until CR is pressed

MOV SI, OFFSET PASSWORD ;Validate the password


MOV DI, OFFSET str1

NEXTCHK:
MOV AL,[SI]
CMP AL,[DI]
JNE NOTAUTHO
INC SI
INC DI
CMP AL,CR
JNE NEXTCHK
JE AUTHO
NOTAUTHO:
PRINTSTRING msg3
PRINTSTRING msg2
JMP NEXTATTEMPT
AUTHO:
PRINTSTRING msg4

MOV AH,4CH ;Program termination function


MOV AL,00H ;Return code for error level setting
INT 21H ;Call DOS Service

CODE ENDS ;End of segment


END START ;End of program

Output:
Enter password: tech2020
You are unauthorized person
Enter password again

Output:
Enter password: INDIA123
Welcomes You

Result:
Thus the 8086 ALP for password checking was successfully executed.
Ex. No: 5. b) Print System Date

Aim: To write an 8086 ALP to print system date.

Algorithm:
1. Start
2. Use DOS service for getting date
3. After getting day, month & year, convert them into ASCII string from Hexadecimal number
4. Display the day, month and year.
5. Stop

Program:
PRINTSTRING MACRO msg ;user defined macro
MOV AH,09H
MOV DX,OFFSET msg
INT 21H
ENDM
DATA SEGMENT
ORG 1500H
CR EQU 0DH ;ASCII code for carriage return
LF EQU 0AH ;ASCII code for line feed
msg1 DB 'Day :','$'
msg2 DB CR,LF,'Month:', '$'
msg3 DB CR,LF,'Year :', '$'
day DB ?
month DB ?
year DW ?
resdisp DB 10 dup( ? )
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
ORG 2000H
START: MOV AX,DATA
MOV DS,AX
MOV AH,2AH ;DOS service for get date function
INT 21H
MOV day,DL ;Store the returned value
MOV month,DH
MOV year, CX
MOV SI, OFFSET resdisp ;Write day
PRINTSTRING msg1
MOV AH,00
MOV AL,day
CALL HEX2ASC
PRINTSTRING resdisp
PRINTSTRING msg2 ;Write month
MOV AH,00
MOV AL,month
CALL HEX2ASC
PRINTSTRING resdisp
PRINTSTRING msg3 ;Write year
MOV AX,year
CALL HEX2ASC
PRINTSTRING resdisp
MOV AH,4CH ;Program termination
MOV AL,00H
INT 21H
HEX2ASC PROC NEAR ;Function to convert Hexadecimal number to ASCII string
;AX – input number, SI – pointer to result storage area
PUSH AX ; save registers
PUSH BX
PUSH CX
PUSH DX
PUSH SI
MOV CX,00H ;Counter for intermediate data pushed
MOV BX,0AH ;Load 10 in BL
RPT1: MOV DX,00
DIV BX ;divide num by 10
ADD DL,'0' ;convert remainder to ASCII
PUSH DX ;store ASCII digit onto the stack
INC CX ;update counter
CMP AX,0AH ;Is num less than or equal to 10
JGE RPT1 ;if yes, perform conversion
ADD AL,'0' ;convert last digit to ASCII
MOV [SI],AL ;store last digit
RPT2: ;pop all intermediate data from stack and store in result
POP AX ;pop data
INC SI ;advance result string pointer
MOV [SI],AL ;store result
LOOP RPT2
INC SI
MOV AL,'$'
MOV [SI],AL ;append end of string
POP SI ;restore the registers
POP DX
POP CX
POP BX
POP AX
RET
HEX2ASC ENDP
CODE ENDS
END START

Output: Day: 02 Month: 11 Year: 2020

Result:
Thus the 8086 ALP to print the system date was successfully executed.
EX.NO.6 INTERFACING 8086 WITH 8255 FOR TRAFFIC LIGHT CONTROL

AIM:
To design a traffic light control system by interfacing the 8086 microprocessor with 8255 as
per the following manner:
1) Switch ON green signal to allow the traffic only from NORTH for 10 seconds. Then switch
ON yellow signal for 3 seconds before switch ON red signal.
2) Switch ON green signal to allow the traffic only from EAST for 10 seconds. Then switch ON
yellow signal for 3 seconds before switch ON red signal.
3) Switch ON green signal to allow the traffic only from SOUTH for 10 seconds. Then switch
ON yellow signal for 3 seconds before switch ON red signal.
4) Switch ON green signal to allow the traffic only from WEST for 10 seconds. Then switch
ON yellow signal for 3 seconds before switch ON red signal.

Algorithm:
1. Set the Control Word into the Control Register of 8255.
2. Assign the starting address of the data sequence in BX register.
3. Call TSIGNAL subroutine for green signal.
4. Call DELAY1 for Green signal.
5. Call TSIGNAL subroutine for transition signal.
6. Call DELAY2 for Transition signal.
7. Repeat the process from Step (2).
Subroutine TSIGNAL:
1. Get the data from BX register to accumulator and display it in Port A.
2. Increment BX register.
3. Get the data from BX register to accumulator and display it in Port B.
4. Increment BX register.
5. Get the data from BX register to accumulator and display it in Port C.
6. Increment BX register.
7. Return.
Subroutine DELAY1 & 2:
1. Load the count value in a register.
2. Decrement the count value of the register.
3. Repeat the step2 until the zero flag is set.
4. Return.

8255 CONTROL REGISTER AND PORTS ADDRESS AND PORT WITH LEDS CONNECTIONS:

Control Word for I/O Mode: Address of Control Register: 26H


B7 B6 B5 B4 B3 B2 B1 B0
1 0 0 0 0 0 0 0 80H
Address of Port A: 20H
PORT BIT PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0
LED D8 D7 D6 D5 D4 D3 D2 D1
Address of Port B: 22H
PORT BIT PB7 PB6 PB5 PB4 PB3 PB2 PB1 PB0
LED D20 D19 D18 D17 DL7DL8 DL5DL6 DL3DL4 DL1DL2
Address of Port C: 24H
PORT BIT PC7 PC6 PC5 PC4 PC3 PC2 PC1 PC0
LED D16 D15 D14 D13 D12 D11 D10 D9
PROGRAM:
ADDRESS OBJECTCODE LABEL MNEMONICS COMMENTS

1000 B0, 80 MOV AL,80H Set the control word

1002 E6, 26 OUT 26,AL Assign control word address

1004 B1, 04 REPEAT: MOV CL,04H Load the count value in CL register

1006 BB, 45, 10 MOV BX,1045H Initialize the BX register

1009 E8, 0F, 00 NEXT: CALL TSIGNAL Call TSIGNAL subroutine

100C E8, 1C, 00 CALL DELAY1 Call DELAY1 subroutine

100F E8, 09, 00 CALL TSIGNAL Call TSIGNAL subroutine

1012 E8, 23,00 CALL DELAY2 Call DELAY2 subroutine

1015 FE,C9 DEC CL Decrement the CL register

1017 75, F0 JNZ NEXT Jump to the label NEXT

1019 EB, E9 JMP REPEAT Repeat the process

101B 8A, 07 TSIGNAL: MOV AL,[BX] Move the data to accumulator

101D E6, 20 OUT PORTA,AL Display it in Port A

101F 43 INC BX Increment BX register

1020 8A,07 MOV AL,[BX] Move the data to accumulator

1022 E6, 22 OUT PORTB,AL Display it in Port B

1024 43 INC BX Increment BX register

1025 8A, 07 MOV AL,[BX] Move the data to accumulator

1027 E6, 24 OUT PORTC,AL Display it in Port C

1029 43 INC BX Increment BX register

102A C3 RET Return

102B BF,30,00 DELAY1: MOV DI, 0030H Load count value into DI register

102E BA, FF, FF LP2: MOV DX,FFFFH Load count value into DX register

1031 4A LP1: DEC DX Decrement DX register


1032 75, FD JNZ LP1 Jump to LP1 if ZF≠0

1034 4F DEC DI Decrement DI register

1035 75, F7 JNZ LP2 Jump to LP2 if ZF≠0

1037 C3 RET Return

1038 BF,15,00 DELAY2: MOV DI, 0015H Load count value into DI register

103B BA, FF, 2F LP4: MOV DX,9FFFH Load count value into DX register

103E 4A LP3: DEC DX Decrement DX register

103F 75, FD JNZ LP3 Jump to LP3 if ZF≠0

1041 4F DEC DI Decrement DI register

1042 75, F7 JNZ LP4 Jump to LP4 if ZF≠0

1044 C3 RET Return

1045 DATASEQ 04H, 20H, 12H, 04H, 20H, 11H Data Sequences for Traffic light
90H, 20H, 10H, 88H, 20H, 10H control
84H, 80H, 10H, 84H, 40H, 10H
84H, 20H, 40H, 84H, 20H, 20H

Result:

Thus the 8086 ALP for traffic light control system was executed successfully.
Ex. No:07. STEPPER MOTOR CONTROL

AIM:

To write an 8086 ALP to run the stepper motor in both forward and reverse direction with delay.

ALGORITHM:
1. Start
2. Move forward rotation data sequence addressed by DI register to the port
3. Rotate the motor in forward direction with necessary delay value
4. Move reverse rotation data sequence addressed by DI register to the port
5. Rotate the motor in reverse direction with necessary delay value
6. Repeat the process from Step (2).

PROGRAM:

Address Object Code Label Mnemonics


1000 B3, 20 START: MOV BL, 20H
1002 BF, 37, 10 LPFW: MOV DI, OFFSET FORW
1005 E8, 18, 00 CALL ROTATE
1008 FE, CB DEC BL
100A 75, F6 JNZ LPFW
100C E8, 21, 00 CALL DELAY
100F B3, 20 MOV BL, 20H
1011 BF, 3B, 10 LPRV: MOV DI, OFFSET REV
1014 E8, 09, 00 CALL ROTATE
1017 FE, CB DEC BL
1019 75, F6 JNZ LPRV
101B E8, 12, 00 CALL DELAY
101E EB, E0 JMP START
1020 B1, 04 ROTATE: MOV CL,04H
1022 8A, 05 LP2: MOV AL, [DI]
1024 E6, C0 OUT C0, AL
1026 BA, 10, 10 MOV DX,1010H
1029 4A LP1: DEC DX
102A 75, FD JNZ LP1
102C 47 INC DI
102D E2, F3 LOOP LP2
102F C3 RET
1030 BA, FF, FF DELAY: MOV DX,FFFFH
1033 4A LP3: DEC DX
1034 75, FD JNZ LP3
1036 C3 RET
0AH, 06H, 05H,
1037 FORW: 0AH,06H,05H,09H
09H
09H, 05H, 06H,
103B REV: 09H,05H,06H,0AH
0AH

RESULT:
Thus the 8086 ALP to rotate the stepper motor in both forward and reverse direction with
delay was successfully executed.
EX.NO: 08 KEYBOARD AND DISPLAY INTERFACE (8279) WITH 8086 FOR ROLLING

DISPLAY

AIM:
To interface Keyboard/Display controller (8279) with 8086 processor and to display a
particular string.

ALGORITHM: (To display the string “HELP US”)


1. Form the look up table and set pointer to initialize SI register
2. Initialize the counter
3. Set the mode word for 8-digit right entry character display.
4. Set the command word for clear display.
5. Set the write display command word.
6. Get the data from the lookup table and display it
7. Increment the SI and decrement the counter.
8. Jump to step 6 to get next data if count value is not zero.
9. Repeat the above steps.

SEGMENT DEFINITION:
Segment definition of 7-Segment display is shown below:
a

f b
g

e c

d . dp

The table below shows the correspondence between the data bus and output port bits of
8279. Also the segment relationship with these are given below:

Data Bus D7 D6 D5 D4 D3 D2 D1 D0
8279
A3 A2 A1 A0 B3 B2 B1 B0
Output
Segments d c B a dp g f e

D0 bit of the byte sent to the display RAM corresponds to B0 and D7 bit of the byte sent to the
display RAM corresponds to A3. In order to light up a segment the corresponding bit of the data
written into the display RAM should be “0”
PROGRAM:

Address Object Code Label Mnemonics Comments


Initialize SI register to lookup
1000 BE, 00, 12 START: MOV SI,1200H
table
1003 B9, 0F, 00 MOV CX,000FH Initialize counter
Assign the command word for
1006 B0, 10 MOV AL,10H
Right Entry
1008 E6, C2 OUT C2,AL Send it to the control register
Assign the command word for
100A B0, CC MOV AL,CCH
clear display
100C E6, C2 OUT C2,AL Send it to the control register
Assign the command word for
100E B0, 90 MOV AL,90H
Write display
1010 E6, C2 OUT C2,AL Send it to the control register
1012 8A, 04 NEXT: MOV AL,[SI] Move the data to accumulator
1014 E6, C0 OUT C0,AL Send it to the data register
1016 E8, 05, 00 CALL DELAY Call DELAY routine
1019 46 INC SI Increment the SI
Continue the LOOP for the next
101A E2, F6 LOOP NEXT
data
Repeat the above steps for
101C EB, E2 JMP START
continuous rolling display
MOV
101E BA, FF, A0 DELAY: Set delay count in DX register
DX,A0FFH
1021 4A LP1: DEC DX Decrement the DX register
1022 75, FD JNZ LP1 If non-zero, jump to LP1
1024 C3 RET Return

1200 FF, FF, FF,FF


1204 FF, FF, FF, FF
1208 98, 68, 7C, C8
120C FF, 1C, 29, FF

Result:

Thus the 8086 ALP for keyboard/display interface for rolling display was successfully executed.
Ex. No: 9. Basic arithmetic and logical operations using 8051 microcontroller

9.a. 8-bit addition


Aim: To write an 8051 assembly language program to perform addition of two 8-bit data
Algorithm:
1. Start
2. Clear the carry flag
3. Get 1st operand in A
4. Add 2nd operand with A
5. Store the result in memory
6. Stop
Program:
CLR C
MOV A, #DATA1
ADD A, #DATA2
MOV DPTR, #4300H
MOVX @DPTR, A
L1: SJMP L1

Input: DATA1: 35 DATA2: 29


Output: [4300H]=5E

9.b. 8-bit subtraction


Aim: To write an 8051 assembly language program to perform subtraction of two 8-bit data
Algorithm:
1. Start
2. Clear the carry flag
3. Get 1st operand in A
4. Subtract 2nd operand from A
5. Store the result in memory
6. Stop
Program:
CLR C
MOV A, #DATA1
SUBB A, #DATA2
MOV DPTR, #4500H
MOVX @DPTR, A
L1: SJMP L1

Input: DATA1: 40 DATA2: 16


Output: [4500H]=2A
9.c. 8-bit multiplication
Aim:
To write an 8051 assembly language program to perform multiplication of two 8-bit data
Algorithm:
1. Start
2. Get 1st data (multiplier) in A
3. Get 2nd data( multiplicand) in B
4. Multiply A with B
5. Store the lower byte result (A) into memory
6. Store the higher byte result (B) into memory
7. Stop
Program:
MOV A, #DATA1
MOV B, #DATA2
MUL AB
MOV DPTR, #4500H
MOVX @DPTR, A
INC DPTR
MOV A, B
MOVX @DPTR, A
L1: SJMP L1

Input: DATA1: 14 DATA2: 26


Output: 2F8 [4500H]=F8 [4501H]=02

9. d. 8-bit division

Aim: To write an 8051 assembly language program to perform division of two 8-bit data
Algorithm:
1. Start
2. Get 1st data (dividend) in A
3. Get 2nd data( divisor) in B
4. Divide A by B
5. Store the Quotient (A) in memory
6. Store the Remainder (B) in memory
7. Stop
Program:
MOV A, #DATA1
MOV B, #DATA2
DIV AB
MOV DPTR, #4500H
MOVX @DPTR, A
INC DPTR
MOV A, B
MOVX @DPTR, A
L1: SJMP L1

Input: DATA1: 65 DATA2: 08


Output: [4500H]=0C (Quotient) [4501H]=05 (Remainder)

9. e. Logical AND operation


Aim:
To write an 8051 assembly language program to perform logical AND of two 8-bit data

Algorithm:
1. Start
2. Clear the carry
3. Get 1st operand in A
4. Logical AND the 2nd operand with A
5. Store the result in memory
6. Stop

Program:
MOV A, #DATA1
ANL A, #DATA2
MOV DPTR, #4300H
MOVX @DPTR, A
L1: SJMP L1

Input: DATA1: 35 DATA2: 79

Output: [4300]= 31

Result:
Thus the 8051 ALP for basic arithmetic and logical operations were successfully executed.
10. a. 2’s Complement of an 8-bit number
Aim:
To write an 8051 assembly language program to find the 2’s Complement of an 8-bit
number
Algorithm:
1. Start
2. Load the data into A register from the memory location 4200H
3. Complement the A register
4. Add one to the Accumulator
5. Store the result in the memory 4300H
6. Stop

Program:
MOV DPTR, #4200
MOVX A, @DPTR
CPL A
ADD A, #01H
MOV DPTR, #4300H
MOVX @DPTR, A
L1: SJMP L1

Input: [4200]= 65
Output: [4300]= 9B

Result:
Thus the program to find the 2’s complement of a number using 8051 was successfully
executed.

10. b. Square of an 8-bit number

Aim:
To write an 8051 assembly language program to find the square of an 8-bit number
Algorithm:
1. Start
2. Load the data into A register from the memory location 4200H
3. Move the A register content to B register
4. Multiply A register and B register
5. Store the lower byte result (A) into memory location4201H
6. Store the higher byte result (B) into memory location 4202H
7. Stop
Program:
MOV DPTR, #4200
MOVX A, @DPTR
MOV B, A
MUL AB
INC DPTR
MOVX @DPTR, A
INC DPTR
MOV A, B
MOVX @DPTR, A
L1: SJMP L1

Input: [4200]: E5

Output: [4201]: D9
[4201]: CC

Result:
Thus the 8051 ALP to find the square root of a number was successfully executed.

10. c. Cube of an 8-bit number

Aim:
To write an 8051 assembly language program to find the cube of an 8-bit number

Algorithm:
1. Start
2. Load the data into R0, A and B register
3. Multiply A register and B register
4. Move the content of B register (Higher Byte) into R1 register
5. Move the content of R0 register into B register
6. Multiply A register and B register
7. Store the lower byte result (A) into memory location4500H
8. Move the B register into R2 register
9. Move the content of R1 register into A register and content of R0 into B register
10. Multiply A register and B register
11. Add the content of A register with R2 register
12. Store the lower byte result (A) into memory location4501H
13. Move the B register content into A register
14. Add the carry with A register
15. Store the content of A result into memory location4502H
16. Stop
Program:
MOV R0,#E5H
MOV A,R0
MOV B,R0
MUL AB
MOV R1,B
MOV B,R0
MUL AB
MOV DPTR,#4500
MOVX @DPTR,A
MOV R2,B
MOV A,R1
MOV B,R0
MUL AB
ADD A,R2
INC DPTR
MOVX @DPTR,A
MOV A,B
ADDC A,#00H
INC DPTR
MOVX @DPTR,A
L1: SJMP L1

Input: E5H

Output: [4500]: 1D
[4501]: 3E
[4502]: B7

Result:
Thus the program to find the cube of a number using 8051 was successfully executed.
11. Unpacked BCD to ASCII
Aim:
To write an 8051 assembly language program to convert the unpacked BCD into ASCII.

Algorithm:
1. Start
2. Load the data into A register from the memory location 4200H
3. Move the content of A into B
4. Mask the higher nibble of A
5. Add 30H to the A
6. Move the content of A into R0
7. Move the content of B into A
8. Swap the lower nibble with higher nibbles in A
9. Mask the higher nibble of A
10. Add 30H to the A
11. Move the content of A into R1
12. Move the content of R0 into A
13. Store the result in the memory 4201H
14. Move the content of R1 into A
15. Store the result in the memory 4202H
16. Stop

Program:
MOV DPTR, #4200
MOVX A, @DPTR
MOV B, A
ANL A, #0FH
ADD A, #30H
MOV R0, A
MOV A, B
SWAP A
ANL A, #0FH
ADD A, #30H
MOV R1, A
INC DPTR
MOV A, R0
MOVX @DPTR, A
INC DPTR
MOV A, R1
MOVX @DPTR, A
L1: SJMP L1

Input: [4200]: 59
Output: [4201]: 39 [4202]: 35
Result:
Thus the program to convert the unpacked BCD into ASCII was successfully executed.

You might also like