0% found this document useful (0 votes)
3 views63 pages

Microprocessor Lab Record

Uploaded by

siravanakumar0
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views63 pages

Microprocessor Lab Record

Uploaded by

siravanakumar0
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

GOVERNMENT ARTS AND SCIENCE COLLEGE

HOSUR-635110.

DEPARTMENT OF COMPUTER SCIENCE


[Link] Computer Science
(III Semester)

MICROPROCESSOR AND
MICONTROLLER LAB

( 23UCSP03)

PRACTICAL RECORD

DEPARTMENT OF COMPUTER SCIENCE


GOVERNMENT ARTS AND SCIENCE COLLEGE
(Affiliated to Periyar University)
HOSUR-635110.
NOVEMBER - 2024
GOVERNMENT ARTS AND SCIENCE COLLEGE
(Affiliated to Periyar University)
HOSUR-635110.

DEPARTMENT OF COMPUTER SCIENCE

This is to certify that the bonafide Practical record work done


by __________________________ and his / her register number
____________________________is a Student of 2nd-Year
[Link].(Computer Science) during the academic year 2024-2025.

Staff-In-charge Head of the Department

The Practical record note book submitted for the Practical


Examination (MICROPROCESSOR AND MICROCONTROLLER LAB–
23UCSP03) held on _____________at Computer Science Lab in
Government Arts And Science College, Hosur .

Internal Examiner External Examiner


INDEX
[Link] DATE NAME OF THE PROGRAM PAGE SIGNATURE
NO

1. 1. 8 – BIT ADDITION
1.2.
16 – BIT ADDITION
1.3. 8 – BIT SUBTRACTION
1.4. BCD SUBTRACTION
2.1. 8 – BIT MULTIPLICATION
2.2. BCD MULTIPLICATION
2.3. 8 – BIT DIVISION
3.1. SEARCH AN ELEMENT IN ARRAY
3.2. ASCENDING AND DESCENDING
3.3 LARGEST AND SMALLEST
3.4 REVERSING ELEMENTS
3.5 BLOCK MOVE
4.1 BCD to HEX and HEX to BCD
4.2 BIN to ASCII and ASCII to BIN
4.3 ASCII to BCD and BCD to ASCII
5.1 8051 ADDITION
5.2 8051 SUBTRACTION
5.3 8051 MULTIPLICATION
5.4 8051 DIVISION
5.5.1 REALISATION OF BOOLEAN
EXPRESSION
5.5.2 TIME DELAY
5.5.3 DISPLAY LEDS
[Link].1
8 – BIT ADDITION

AIM :
Write an assembly language program to perform 8-bit addition
PROGRAM:

MEMORY HEXCODE LABEL MNEMONICS COMMENTS


ADDRESS
0000 21 LXI H,2000 Load immediate value in HL
0001 00 pair
0002 20
0003 7E MOV A,M Move content of
memory to accumulator
0004 23 INX H Increment the
memory pointer
0005 86 ADD M Add memory to accumulator
0006 23 INX H Increment the memory
pointer
0007 77 MOV M,A Move the content of
accumulator to
memory
0008 3E MVI A,00 Move immediate 8 bit data
0009 00 into accumulator
000A 8F ADC A Add register with accumulator
with
carry
000B 76 HLT Stop

INPUT & OUTPUT:

Input data 98 86

Memory address 2000 2001

Output data 1E

Memory address 2002


[Link].2
16 – BIT ADDITION

AIM :
Write an assembly language program to perform 16-bit addition
PROGRAM:

ADDRESS LABEL MNEMONICS HEXCODE COMMENTS


0000 LHLD 2050 2A Load H and L registers direct
0001 50 H <- 2051,
L <- 2050 (first number)
0002 20
0003 XCHG EB Exchange HL &DE value
0004 LHLD 2052 2A Load HL pair with value from
0005 52 address
0006 20 H <- 2053,
L <- 2054 (secondnumber)
0007 DAD D 19 Get HL+DE & store result
in HL register pair
0008 SHLD 3050 22 Store the result at memory
0009 50 location 3050 and 3051

000A 30
000B HLT 76 Stop

INPUT & OUTPUT:

Input data 2A 10 11 20

Memory address 2050 2051 2052 2053

Output data 3B 30

Memory address 3050 3051


[Link].3
8 – BIT SUBTRACTION

AIM :
Write an assembly language program to perform 8-bit subtraction .
PROGRAM :

MEMORY HEXCODE LABEL MNEMONICS COMMENTS


ADDRESS
0000 21 LXI H,2000 Load immediate value in HL pair
0001 00
0002 20
0003 7E MOV A,M Move content of
memory to accumulator
0004 23 INX H Increment the
memory pointer
0005 96 SUB M Subtract the memory from
accumulator
0006 23 INX H Increment the memory pointer
0007 77 MOV M,A Move the content of
accumulator to
memory
0008 3E MVI A,00 Move immediate 8 bit data into
0009 00 accumulator
000A 8F ADC A Add Acc with borrow

000B 76 HLT Stop

INPUT & OUTPUT :

Input data 72 35

Memory address 2000 2001

Output data 32 00

Memory address 2002 2003


[Link].4
BCD SUBTRACTION

AIM :
Write an assembly language program to perform BCD subtraction.
PROGRAM :

ADDRESS LABEL MNEMONICS HEXCODE COMMENT


0000 LDA 2051 3A Load data from address 2051 in
0001 51 accumulator
0002 20
0003 MOV C, A 4F Move the data from
accumulator to C
0004 MVI A,99 3E Move the data 99 in A
0005 99
0006 SUB C 91 subtract the content of
register A and C
0007 INR A 3C Increment the content
of A by 1
0008 MOV B, A 47 Move the data from A
to B
0009 LDA 2050 3A
000A 50 Load the data from address 2050
000B 20 in A
000C ADD B 80 Add the content of
register A and B
000D DAA 27 Convert the hexadecimal value in
A
to BCD value
000E STA 3050 32 Store the content of A to 3050
000F 50
0010 30
0011 HLT 76 Stop

INPUT & OUTPUT :

Input data 72 35

Memory address 2050 2051

Output data 37

Memory address 3050


[Link].1
8 – BIT MULTIPLICATION

AIM :
Write an assembly language program to perform 8- bit multiplication.
PROGRAM :

ADDRESS LABEL MNEMONICS HEXCODE COMMENT


0000 LHLD 2050 2A
0001 50 Load content of 2051 in H and content
of 2050 in L
0002 20
0003 XCHG EB Exchange HL & DE VALUE
0004 MOV C, D 4A Move content of D in C
0005 MVI D, 00 16
0006 00 Assigns 00 to D

0007 LXI H,0000 21


0008 00 Assign 00 to H and 00 to L

0009 00
000A NEXT DAD D 19 Get HL+DE & store result in HL
000B DCR C 0D Decrement register C by 1
000C JNZ NEXT C2
000D 0A Jump PC to 200A if Zero!=0

000E 00
000F SHLD 3050 22 Store result in 3050
0010 50
0011 30
0012 HLT 76 Stop

INPUT & OUTPUT:

Input data 43 07
Memory address 2050 2051

Output data 01 D5
Memory address 3051 3050
[Link].2
BCD MULTIPLICATION

AIM :
Write an assembly language program to perform BCD multiplication.
PROGRAM :

Address HEX Codes Labels Mnemonics Comments

F000 21, 00, 80 LXI H,8000H Load first operand address

F003 46 MOV B, M Store first operand to B

F004 23 INX H Increase HLpair

F005 4E MOV C, M Store second operand to register C

F006 1E, 00 MVI E, 00H Clear register E

F008 63 MOV H, E Clear H register

F009 7B MOV A, E Clear A register

F00A B9 CMP C Compare C with A

F00B CA, 23, F0 JZ DONE When Z = 0,jump to DONE

F00E 80 LOOP ADD B Add B with A

F00F 27 DAA Decimal Adjust

F010 57 MOV D, A Store A to D

F011 D2, 19, F0 JNC NINC Jump tp NINC

F014 7C MOV A, H Store H to A

F015 C6, 01 ADI 01H Increase A by1

F017 27 DAA DecimalAdjust

F018 67 MOV H, A Restore H from A

F019 7B NINC MOV A, E Load E to A

F01A C6, 01 ADI 01H Increase A by1

F01C 27 DAA Decimal adjust

F01D 5F MOV E, A Restore E from A

F01E B9 CMP C Compare C with A

F01F 7A MOV A,D Load D to A

F020 C2, 0E, F0 JNZ LOOP Jump to LOOP


Address HEX Codes Labels Mnemonics Comments

F023 6F DONE MOV L, A Load A to L

F024 22, 50, 80 SHLD 8050H Store HL pair at location 8050 and 8051

F027 76 HLT Terminate the program

INPUT :

Address Data

8000 12

8001 20

OUTPUT:

Address Data

8050 40

8051 02
[Link].3
8 - BIT DIVISION

AIM :
Write an assembly language program to perform 8-bit division.
PROGRAM :

ADDRESS LABEL MNEMONICS HEXCODE COMMENT

0000 LXI H,2050 21,50,20


Load HL pair with address the 2050
0003 MOV B,M 46 Move the content of memory into register
B
0004 MVI C,00 0E,00 Assigns 00 to c
0006 INX H 23 Increment the memory pointer
0007 MOV A,M 7E Move the content of memory into
A
0008 GO CMP B B8 Compare the content of A and
register B
0009 JC DONE DA,11,00 Jump to address 0011 if carry flag is set
000C SUB B 90 Subtract the content of A with
register B
000D INR C 0C Increment the register C
000E JMP GO C3,08,00 Control will shift to memory address 2008
0011 DONE STA 3050 32,50,30 Store the remainder at memory location
3050
0014 MOV A,C 79 Move content of register C into A
0015 STA 3051 32,51,30 Store the quotient at memory location
3051
0018 HLT 76 Stop

INPUT & OUTPUT:

Input data FF FF
Memory address 2050 2051

Output data 01 FE
Memory address 3051 3050
[Link].1
SEARCH AN ELEMENT IN AN ARRAY

AIM :
Write an assembly language program to search an element in array of elements.
PROGRAM

Address HEX Codes Labels Mnemonics Comments

F000 21, 00, 80 LXI H,8000H Point to get array size

F003 4E MOV C, M Get the size of array

F004 23 INX H Point to next location

F005 46 MOV B, M Get the key value to search

F006 78 MOV A, B Take the key into acc

F007 23 LOOP INX H Point to next location

F008 BE CMP M Compare memory element with Acc

F009 CA, 19, F0 JZ FOUND When Z flag is set, go to FOUND

F00C 0D DCR C Decrease C by1

F00D C2, 07, F0 JNZ LOOP When Count is not 0, jump to LOOP

F010 21, FF, FF LXI H, FFFF Load FFFFH into HL pair

F013 22, 00, 90 SHLD 9000H Store at9000H

F016 C3, 1C, F0 JMP DONE Jump to DONE

F019 22, 00, 90 FOUND SHLD 9000H Store at9000H

F01C 76 DONE HLT Terminate the program


Input

Address Data

... ...

8000 06

8001 55

8002 11

8003 22

8004 33

8005 44

8006 55

8007 66

... ...

Output

Address Data

... ...

9000 06

9001 80

... ...
[Link].2a
SORTING ARRAY IN ASCENDING ORDER

AIM :
Write an assembly language program to sorting array elements in ascending order.
PROGRAM :

HEX
Address Labels Mnemonics Comments
Codes
8000 21,00, 82 LXI H, 8200 Setting pointer for data
8003 5E MOV E,M Move contents of memory(size of array) to
Register E
8004 46 MOV B,M Move number of data to Register B from
Memory
8005 4B Next MOV C,E Move register E content to Register C
8006 23 INX H Increment the memory pointer
8007 0D DCR C Decrement Register C by 1
8008 7E Compare MOV A,M Move contents of memory to Accumulator
8009 23 INX H Increment the memory pointer
800A BE CMP M Compare contents of memory with
Accumulator
800B DA,13,80 JC Ahead Jump on Carry to Ahead
800E 56 MOV D,M Move contents of Memory to Register D
800F 77 MOV M,A Move contents of Accumulator to Memory
8010 2B DCX H Decrement the memory pointer
8011 72 MOV M,D Move contents of Register D to Memory
8012 23 INX H Increment the memory pointer
8013 0D Ahead DCR C Decrement Register C by 1
8014 C2,08,80 JNZ Compare If Register C is not equal to '0', go to Compare
8017 5 DCR B Decrement Register B content by 1
8018 C2,05,80 JNZ Next If Register B is not equal to '0', go to Next
801B 76 HLT End of Program

INPUT OUTPUT

Address Data Address Data


8200 No. of Elements 6 8201 DATA 1 3
8201 DATA 1 5 8202 DATA 2 5
8202 DATA 2 8 8203 DATA 3 6
8203 DATA 3 3 8204 DATA 4 7
8204 DATA 4 6 8205 DATA 5 8
8205 DATA 5 7 8206 DATA 6 15
8206 DATA 6 15
[Link].2b
SORTING ARRAY IN DESCENDING ORDER

AIM :
Write an assembly language program to sorting array elements in descending order.
PROGRAM :

HEX
Address Labels Mnemonics Comments
Codes
8000 21,00, 82 LXI H, 8200 Setting pointer for data
8003 5E MOV E,M Move contents of memory(size of array) to
Register E
8004 46 MOV B,M Move number of data to Register B from
Memory
8005 4B Next MOV C,E Move register E content to Register C
8006 23 INX H Increment the memory pointer
8007 0D DCR C Decrement Register C by 1
8008 7E Compare MOV A,M Move contents of memory to Accumulator
8009 23 INX H Increment the memory pointer
800A BE CMP M Compare contents of memory with
Accumulator
800B D2,13,80 JNC Ahead Jump on No Carry to Ahead
800E 56 MOV D,M Move contents of Memory to Register D
800F 77 MOV M,A Move contents of Accumulator to Memory
8010 2B DCX H Decrement the memory pointer
8011 72 MOV M,D Move contents of Register D to Memory
8012 23 INX H Increment the memory pointer
8013 0D Ahead DCR C Decrement Register C by 1
8014 C2,08,80 JNZ Compare If Register C is not equal to '0', go to Compare
8017 5 DCR B Decrement Register B content by 1
8018 C2,05,80 JNZ Next If Register B is not equal to '0', go to Next
801B 76 HLT End of Program

INPUT OUTPUT

Address Data Address Data


8200 No. of Elements 6 8201 DATA 1 15
8201 DATA 1 5 8202 DATA 2 8
8202 DATA 2 8 8203 DATA 3 7
8203 DATA 3 3 8204 DATA 4 6
8204 DATA 4 6 8205 DATA 5 5
8205 DATA 5 7 8206 DATA 6 3
8206 DATA 6 15
[Link].3a
FINDING LARGEST ELEMENT IN ARRAY

AIM :
Write an assembly language program to find largest element in an array.
PROGRAM :

Address HEX Codes Labels Mnemonics Comments


8000 21,00,82 LXI H, 8200 Setting pointer for data
8003 46 MOV B,M Move number of data to Register B from
Memory
8004 23 INX H Increment the memory pointer
8005 7E MOV A,M Move contents of memory to
Accumulator
8006 5 DCR B Decrement Register B content by 1

8007 23 Loop INX H Increment the memory pointer


8008 BE CMP M Compare contents of memory with
Accumulator
8009 D2,0D,80 JNC Ahead If carry==0, go Ahead i.e., number is
greater
800C 7E MOV A,M Move contents of memory to
Accumulator
800D 5 Ahead DCR B Decrement Register B content by 1
800E C2,07,80 JNZ Loop If Register B is not equal to '0', go to Loop
8011 32,00,83 STA 8300 Store Accumulator content (Sum) to
Memory
8014 76 HLT End of Program

INPUT & OUTPUT:

8200 No. of Elements 6

8201 DATA 1 04

8202 DATA 2 03

8203 DATA 3 01

8204 DATA 4 22

8205 DATA 5 05

8206 DATA 6 0C

8300 Largest Number 22


[Link].3b
FINDING SMALLEST ELEMENT IN ARRAY

AIM :
Write an assembly language program to find smallest element in an array.
PROGRAM :

Address HEX Codes Labels Mnemonics Comments


8000 21,00,82 LXI H, 8200 Setting pointer for data
8003 46 MOV B,M Move number of data to Register B from
Memory
8004 23 INX H Increment the memory pointer
8005 7E MOV A,M Move contents of memory to
Accumulator
8006 5 DCR B Decrement Register B content by 1

8007 23 Loop INX H Increment the memory pointer


8008 BE CMP M Compare contents of memory with
Accumulator
8009 D6,0D,80 JC Ahead If carry==1, go Ahead i.e., number is
smaller
800C 7E MOV A,M Move contents of memory to
Accumulator
800D 5 Ahead DCR B Decrement Register B content by 1
800E C2,07,80 JNZ Loop If Register B is not equal to '0', go to Loop
8011 32,00,83 STA 8300 Store Accumulator content (Sum) to
Memory
8014 76 HLT End of Program

INPUT & OUTPUT:

8200 No. of Elements 6

8201 DATA 1 04

8202 DATA 2 03

8203 DATA 3 01

8204 DATA 4 22

8205 DATA 5 05

8206 DATA 6 0C

8300 Smallest Number 01


[Link].4
REVERSING ORDER OF ELEMENTS IN ARRAY

AIM :
Write an assembly language program to reverse the order of elements in an array.
PROGRAM

Address HEX Codes Labels Mnemonics Comments

F000 21, 00, 80 LXI H,8000 Point to 8000 to get block size

F003 4E MOV C,M Take the block size into C

F004 11, 00 90 LXI D,9000 Point to the destination address

F007 7D MOV A,L Load L into A

F008 81 ADD C Add C to point to last address of block

F009 6F MOV L,A Store A to L again

F00A 7E LOOP MOV A,M Load memory to A

F00B 12 STAX D Store A into destination pointed by DE

F00C 13 INX D Point destination to next address

F00D 2B DCX H Point source to previous address

F00E 0D DCR C Decrease C by 1

F00F C2, 0A, F0 JNZ LOOP if Z is not set jump to LOOP

F012 76 HLT Terminate the program


Input

Address Data

… …

8000 0A

8001 11

8002 22

8003 33

8004 44

8005 55

8006 66
Address Data

8007 77

8008 88

8009 99

800A AA

… …

Output

Address Data

… …

9000 AA

9001 99

9002 88

9003 77

9004 66

9005 55

9006 44

9007 33

9008 22

9009 11

… …
[Link].5
BLOCK MOVE OF ELEMENTS

AIM :
Write an assembly language program to move the block of elements from one
location to another.
PROGRAM

MEMORY LABEL MNEMONIC HEX COMMENT


CODE
4200 LXI D,4500 11 Load destination address in DE pair
4201 00
4202 45
4203 LXI H,4100 21 Load the count in HL pair
4204 00
4205 41
4206 MOV C,M 4E Copy the count to register C
4207 LOOP INX H 23 Increment memory
4208 MOV A,M 7E Copy element to Accumulator
4209 STAX D 12 Store the element to the address in the DE
pair
420A INX D 13 Increment destination address
420B DCR C OD Decrement count
420C JNZ LOOP C2 Jump on non-zero to the label LOOP
420D 07
420E 42
420F HLT 76 Program ends

INPUT/OUTPUT

Input at 4100 : 04H


4101 : 06H
4102 : 07H
4103 : 12H
4104 : 03H
Output at 4500 : 06H
4501 : 07H
4502 : 12H
4503 : 03H
[Link].1a
BCD to HEX

AIM :
Write an assembly language program to convert BCD to HEX numbers.
PROGRAM:

MEMORY
LABEL MNEMONICS HEXCODE COMMENTS
ADDRESS
Load register pair immediate.
0000 LXI H,2004 21,04,20
H20, L04
Move immediate 8 bit data to E
0003 MVI E,0A 1E,0A
register.
Move the contents of Memory into
0005 MOV A,M 7E
Accumulator.
Clears the lower four bits of the
0006 ANI F0 E6,F0
accumulator.
0008 RRC 0F
0009 RRC 0F Rotate the contents of the
000A RRC 0F accumulator to the right by one bit.
000B RRC 0F
Move the contents of Accumulator
000C MOV B,A 47
into B register.
Perform bit wise XOR operation and
000D XRA A AF
store the result in accumulator.
000E L1 ADD B 80 Add B register with Accumulator.
000F DCR E 1D Decrement E register by 1.
0010 JNZ L1 C2,0E,00 Jump on non zero.
Move the contents of Accumulator
0013 MOV C,A 4F
into C register.
Move the contents of Memory into
0014 MOV A,M 7E
Accumulator.
Clears the upper four bits of the
0015 ANI 0F E6,0F
accumulator.
0017 ADD C 81 Add B register with Accumulator.
Store Accumulator contents in
0018 STA 2006 32,06,20
Memory.
001B HLT 76 Stop.
INPUT:

MEMORY ADDRESS 2004


INPUT DATA 82
OUTPUT:

MEMORY ADDRESS 2006


OUTPUT DATA 52
[Link].1b
HEX to BCD

AIM :
Write an assembly language program to convert HEX to BCD numbers.
PROGRAM:

MEMORY
LABEL MNEMONICS HEXCODE COMMENTS
ADDRESS
Load register pair immediate.
0000 LXI H,2020 21,20,20
H20, L20 (Source)
Move the contents of Memory into
0003 MOV A,M 7E
Accumulator.
0004 CALL PWRTEN CD,08,00 Call subroutine to load powers of 10.
0007 HLT 76 Stop.
Load register pair immediate.
0008 PWRTEN LXI H,2030 21,30,20
H20, L30 (Destination)
000B MVI B,64 06,64 Load 100 in register B.
000D CALL BINBCD CD,17,00 Call conversion.
0010 MVI B,0A 06
Load 10 in register B.
0011 0A
0012 CALL BINBCD CD,17,00 Call conversion.
Move the contents of Accumulator into
0015 MOV M,A 77
Memory.
0016 RET C9 Return from the subroutine.
0017 BINBCD MVI M,FF 36,FF Load buffer with(0-1).
Clear buffer and increment for each
0019 NEXT INR M 34
subtraction.
Subtract power of 10 from binary
001A SUB B 90
number.
001B JNC NEXT D2,19,00 Is number>power of 10?
001E ADD B 80 If no add power of 10 get back
001F INX H 23 remainder
0020 RET C9 Return from the subroutine.
INPUT:

MEMORY ADDRESS 2020


INPUT DATA FF

OUTPUT:

MEMORY ADDRESS 2030 2031 2032


OUTPUT DATA 02 05 05
[Link].2a
BINARY to ASCII

AIM :
Write an assembly language program to convert BINARY to ASCII numbers.
PROGRAM:

MEMORY
LABEL MNEMONICS HEXCODE COMMENTS
ADDRESS
Load register pair immediate.
0000 LXI H,5000 21,00,50
H50, L00 (Source)
Load immediate 16 bit data into register
pair.
0003 LXI D,5020 11,20,50
H50, L20 (Destination)
Move the contents of Memory into
0006 MOV A,M 7E
Accumulator.
Move the contents of Accumulator into B
0007 MOV B,A 47
register.
Clears the lower four bits of the
0008 ANI F0 E6,F0
accumulator.
000A RRC 0F
000B RRC 0F Rotate the contents of the accumulator to
000C RRC 0F the right by one bit.

000D RRC 0F
000E CALL ASCII CD,19,00 Call conversion routine.
0011 STAX D 12 Store first ASCII Hex in 5020.
0012 INX H 23 Point to next memory.
Move the contents of B register into
0013 MOV A,B 78
Accumulator.
0014 CALL ASCII CD,19,00 Call conversion routine.
0017 STAX D 12 Store register pair immediate.
0018 HLT 76 Stop
Clears the upper four bits of the
0019 ASCII ANI 0F E6,0F
accumulator.
001B CPI 0A FE,0A Is digit less than 1010?
If digit is less than 1010, go to BELOW to
001D JC BELOW DA,20,00
add 30H.
Add 7H to obtain code for digits from A
001F ADI 07 C6,07
to F.
0022 BELOW ADI 30 C6,30 ADD base number 30H

0024 RET C9 Return from the subroutine.


INPUT:

MEMORY ADDRESS 5000

INPUT DATA 0B

OUTPUT:

MEMORY ADDRESS 5020

OUTPUT DATA 42
[Link].2b
ASCII to BINARY

AIM :
Write an assembly language program to convert ASCII to BINARY numbers.
PROGRAM:

MEMORY
LABEL MNEMONICS HEXCODE COMMENTS
ADDRESS
0000 LXI H,1040 21
Load register pair immediate.
0001 40
H10, L40 (Source)
0002 10

0003 LXI D,1050 11


Load immediate 16 bit data into
0004 50 register pair.
H10, L50 (Destination)
0005 10
Move the contents of Memory
0006 MOV A,M 7E
into Accumulator.
0007 CALL ASCBIN CD

0008 0C Call conversion routine.

0009 00

000A STAX D 12 Store register pair immediate.


HLT
000B 76 Stop

000C ASCBIN SUI 30 D6


Subtract 8 bit data from the
accumulator.
000D 30

000E CPI 0A FE
Check whether number is
between 0 and 9.
000F 0A

0010 RC D8 If yes, return to main program.

0011 SUI 07 D6
If not subtract 7 to find number
between A and F.
0012 07

0013 RET C9 Return from the subroutine.


INPUT:

MEMORY ADDRESS 1040

INPUT DATA 41

OUTPUT:

MEMORY ADDRESS 1050

OUTPUT DATA 0A
[Link].3a
ASCII to BCD

AIM :
Write an assembly language program to convert ASCII to BCD numbers.
PROGRAM:

MEMORY
LABEL MNEMONICS HEXCODE COMMENTS
ADDRESS
0000 LXI H,7000 21
Load H-L pair with the memory address
0001 00
7000.
0002 70
Move the contents of the memory
0003 MOV A,M 7E location pointed to by HL into the
Accumulator.
0004 SUI 30 D6
Subtract immediate value 30 from the
accumulator.
0005 30

0006 STA 7001 32


Store the accumulator contents into
0007 01
memory address 7001.
0008 70

0009 HLT 76 Halt the processor.

INPUT:

MEMORY ADDRESS 7000

INPUT DATA 37

OUTPUT:

MEMORY ADDRESS 7001

OUTPUT DATA 07
[Link].3b
BCD to ASCII

AIM :
Write an assembly language program to convert BCD to ASCII numbers.
PROGRAM:

MEMORY
LABEL MNEMONICS HEXCODE COMMENTS
ADDRESS
0000 LXI H,5000 21
Load H-L pair with the memory address
0001 00
5000.
0002 50
Move the contents of the memory
0003 MOV A,M 7E location pointed to by HL into the
Accumulator.
0004 ADI 30 C6
Add immediate value 30 from the
accumulator.
0005 30

0006 STA 5001 32


Store the accumulator contents into
0007 01
memory address 5001.
0008 50

0009 HLT 76 Halt the processor.

INPUT:

MEMORY ADDRESS 5000

INPUT DATA 07

OUTPUT:

MEMORY ADDRESS 5001

OUTPUT DATA 37
[Link].1
8051 - ADDITION

AIM :
Write an assembly language program of 8051 to perform 8-bit addition.
PROGRAM:

ORG 000H Initialize the memory address

MOV R1,#00H Initialize R1 with 0 values

MOV A,40H Move the content memory 40H to A register

MOV B,41H Move the content memory 41H to A register

ADD A,B Add the content of A and B and store result in A

JNC SAVE If carry is not set, jump to label SAVE

INC R1 Increment the Register R1 content by 1

MOV 43H, R1 Move the register R1 value to memory 43H

SAVE : MOV 42H,A Move the A value to Memory 42H

END End

INPUT/OUTPUT:

LOCATION DATA
INPUT 40H 02
41H 03
OUTPUT 42H 05
43H 00
[Link].2
8051 - SUBTRACTION

AIM :
Write an assembly language program of 8051 to perform 8-bit subtraction.
PROGRAM:

ORG 000H Initialize the memory address

MOV R1,#00H Initialize R1 with 0 values

MOV A,40H Move the content memory 40H to A register

MOV B,41H Move the content memory 41H to A register

SUBB A,B Subtract the content of B from A and store result in A

JNC SAVE If borrow is not set, jump to label SAVE

INC R1 Increment the Register R1 content by 1

MOV 43H, R1 Move the register R1 value to memory 43H

SAVE : MOV 42H,A Move the A value to Memory 42H

END End

INPUT/OUTPUT:

LOCATION DATA
INPUT 40H 05
41H 03
OUTPUT 42H 02
43H 00
[Link].3
8051 - MULTIPLICATION

AIM :
Write an assembly language program of 8051 to perform 8-bit multiplication.
PROGRAM:

ORG 000H Initialize the memory address

MOV A,40H Move the content memory 40H to A register

MOV B,41H Move the content memory 41H to A register

MUL AB Multiply the content of A and B, The lower 8bits of results stores in A and
Higher 8bits stores result in B

MOV 42H, A Move the register A value to memory 42H

MOV 43H,B Move the B value to Memory 43H

END End

INPUT/ OUTPUT:

LOCATION DATA

INPUT 40H 05

41H 03

OUTPUT 42H 0F

43H 00
[Link].4
8051 - DIVISION

AIM :
Write an assembly language program of 8051 to perform 8-bit division.
PROGRAM:

ORG 000H Initialize the memory address

MOV A,40H Move the content memory 40H to A register

MOV B,41H Move the content memory 41H to A register

DIV AB Divide the content of A by B, The Quotient of results stores in A and


Remainder stores result in B

MOV 42H, A Move the register A value to memory 42H

MOV 43H,B Move the B value to Memory 43H

END End

INPUT/ OUTPUT:

LOCATION DATA

INPUT 40H 0F

41H 03

OUTPUT 42H 05

43H 00
[Link].5.1
8051 – REALISATION OF BOOLEAN EXPRESSION

AIM :
Write an assembly language program of 8051 to realisation of Boolean expression
using ports.
PROGRAM:

ORG 0000H Initialize memory

MOV C, P0.0 Move the port P0.0 bit to Carry

ANL C, P0.1 Logical AND operation with P0.1 with C, results in C

MOV P1.0,C Move results C to port P1.0

ACALL DELAY Call Delay subroutine for delay operation

MOV C,P0.2 Move the port P0.2 bit to Carry

ANL C,P0.3 Logical and bit operation with P0.2 with C, results in C

MOV P1.1,C Move results C to port P1.0

ACALL DELAY Call Delay subroutine for delay operation

MOV C, P1.0 Move the port P1.0 bit to Carry

ORL C, P1.1 Logical OR operation with P1.1 with C, results in C

MOV P1.2,C Move results C to port P1.2

CPL P1.2 Complement P1.2 to Swith on the LED based on the OUTPUT

ACALL DELAY Call Delay subroutine for delay operation

STOP: SJMP STOP Wait state

DELAY: Delay Subroutine

MOV R0, #1 Initialize the Counter R0 with value 1

HERE1: MOV R1, #5 Initialize the Counter R1 with value 1

HERE: DJNZ R1, HERE Repeatedly decrement Counter R1 by 1, Until counter R1 reached zero

DJNZ R0, HERE1 Repeatedly decrement Counter R0 by 1, Until counter R0 reached zero

RET Return back to main program

END end
INPUT /OUTPUT:

Y = A&B + C&D

LOCATION Expression

INPUT P0.0 A

P0.1 B

P0.2 C

P0.3 D

OUTPUT P1.0 A&B

P1.1 C&D

P2.1 A&B + C&D


[Link].5.2
8051 – TIME DELAY GENERATION USING SUBROUTINES

AIM :
Write an assembly language program of 8051 to time delay generation using
subroutines.
PROGRAM:

ORG 0000H Initialize memory

LOOP: CLR P2.0 To switch ON the LED connected to P2.0

ACALL DELAY Call Delay subroutine for delay operation

SETB P2.0 To switch OFF the LED connected to P2.0

ACALL DELAY Call Delay subroutine for delay operation

Short Jump to Lable LOOP. Repeat above operations in interval


SJMP LOOP time

DELAY: MOV Initialize the Counter R0 with value 10H


R0,#10

AGAIN: MOV Initialize the Counter R1 with value 20H


R1,#20

BACK: DJNZ Repeatedly decrement Counter R1 by 1, Until counter R1 reached


R1,BACK zero

Repeatedly decrement Counter R0 by 1, Until counter R0 reached


DJNZ R0,AGAIN zero

RET Move results C to port P1.2

END end

INPUT/OUTPUT:

LOCATION Connected

INPUT P2.0 Virtual LED

OUTPUT LED is ON and OFF in some


Interval Time
[Link].5.3
8051 – DISPLAY LEDS THROUGH PORTS

AIM :
Write an assembly language program of 8051 to display LEDs through ports.
PROGRAM:

ORG 0000H Initialize memory

LOOP: CLR P2.0 To switch ON the LED connected to P2.0

CLR P2.1 To switch ON the LED connected to P2.1

ACALL DELAY Call Delay subroutine for delay operation

SETB P2.0 To switch OFF the LED connected to P2.0

SETB P2.1 To switch OFF the LED connected to P2.1

ACALL DELAY Call Delay subroutine for delay operation

SJMP LOOP Short Jump to Lable LOOP. Repeat above operations in interval time

DELAY: MOV R0,#10 Initialize the Counter R0 with value 10H

AGAIN: MOV R1,#20 Initialize the Counter R1 with value 20H

BACK: DJNZ R1,BACK Repeatedly decrement Counter R1 by 1, Until counter R1 reached zero

DJNZ R0,AGAIN Repeatedly decrement Counter R0 by 1, Until counter R0 reached zero

RET Move results C to port P1.2

END end

INPUT/OUTPUT:

LOCATION Connected

INPUT P2.0 Virtual LED1

P2.1 Virtual LED2

OUTPUT LED1 and LED2 are ON and


OFF in some Interval Time

You might also like