Professional Documents
Culture Documents
EC8681-MPMC Research
EC8681-MPMC Research
EC8681-MPMC Research
IT
EC8681 – MICROPROCESSORS AND MICROCONTROLLERS LAB
INDEX
b) Decimal Arithmetic
c) Matrix Addition
d) Matrix Multiplication
4. a) String Manipulation
5. a) Password checking
Aim: To write an 8086 assembly language programs to perform basic arithmetic and logical
operations.
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
Output: 9CA6
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
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
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
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
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
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
Result:
Thus the 8086 ALP to convert hexadecimal number into decimal was successfully executed.
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
OUTPUT OUTPUT
[1202] : 11 [1202] : 18
Result:
Thus the 8086 ALP to perform decimal arithmetic was successfully executed.
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
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
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
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
Input:
N=05H
Elements: 51H, 47H, 69H, 5FH, 12H
Output:
After sorting:
Result:
Thus the 8086 ALP to sort the elements in ascending order was successfully executed.
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
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
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
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
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
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
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
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:
1004 B1, 04 REPEAT: MOV CL,04H Load the count value in CL register
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
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
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:
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.
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:
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. 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
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
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.
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.
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.