Microprocessor Lab Record
Microprocessor Lab Record
HOSUR-635110.
MICROPROCESSOR AND
MICONTROLLER LAB
( 23UCSP03)
PRACTICAL RECORD
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:
Input data 98 86
Output data 1E
AIM :
Write an assembly language program to perform 16-bit addition
PROGRAM:
000A 30
000B HLT 76 Stop
Input data 2A 10 11 20
Output data 3B 30
AIM :
Write an assembly language program to perform 8-bit subtraction .
PROGRAM :
Input data 72 35
Output data 32 00
AIM :
Write an assembly language program to perform BCD subtraction.
PROGRAM :
Input data 72 35
Output data 37
AIM :
Write an assembly language program to perform 8- bit multiplication.
PROGRAM :
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 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 :
F024 22, 50, 80 SHLD 8050H Store HL pair at location 8050 and 8051
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 :
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
F00D C2, 07, F0 JNZ LOOP When Count is not 0, jump to LOOP
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
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
AIM :
Write an assembly language program to find largest element in an array.
PROGRAM :
8201 DATA 1 04
8202 DATA 2 03
8203 DATA 3 01
8204 DATA 4 22
8205 DATA 5 05
8206 DATA 6 0C
AIM :
Write an assembly language program to find smallest element in an array.
PROGRAM :
8201 DATA 1 04
8202 DATA 2 03
8203 DATA 3 01
8204 DATA 4 22
8205 DATA 5 05
8206 DATA 6 0C
AIM :
Write an assembly language program to reverse the order of elements in an array.
PROGRAM
F000 21, 00, 80 LXI H,8000 Point to 8000 to get block size
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
INPUT/OUTPUT
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
H20, L04
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:
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
H20, L20 (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
H20, L30 (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:
OUTPUT:
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
H50, L00 (Source)
Load immediate 16 bit data into register
pair.
0003 LXI D,5020 11,20,50
H50, L20 (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
INPUT DATA 0B
OUTPUT:
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
H10, L40 (Source)
0002 10
0009 00
000E CPI 0A FE
Check whether number is
between 0 and 9.
000F 0A
0011 SUI 07 D6
If not subtract 7 to find number
between A and F.
0012 07
INPUT DATA 41
OUTPUT:
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
INPUT:
INPUT DATA 37
OUTPUT:
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
INPUT:
INPUT DATA 07
OUTPUT:
OUTPUT DATA 37
[Link].1
8051 - ADDITION
AIM :
Write an assembly language program of 8051 to perform 8-bit addition.
PROGRAM:
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:
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:
MUL AB Multiply the content of A and B, The lower 8bits of results stores in A and
Higher 8bits stores result in B
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:
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:
ANL C,P0.3 Logical and bit operation with P0.2 with C, results in C
CPL P1.2 Complement P1.2 to Swith on the LED based on the OUTPUT
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
END end
INPUT /OUTPUT:
Y = A&B + C&D
LOCATION Expression
INPUT P0.0 A
P0.1 B
P0.2 C
P0.3 D
P1.1 C&D
AIM :
Write an assembly language program of 8051 to time delay generation using
subroutines.
PROGRAM:
END end
INPUT/OUTPUT:
LOCATION Connected
AIM :
Write an assembly language program of 8051 to display LEDs through ports.
PROGRAM:
SJMP LOOP Short Jump to Lable LOOP. Repeat above operations in interval time
BACK: DJNZ R1,BACK Repeatedly decrement Counter R1 by 1, Until counter R1 reached zero
END end
INPUT/OUTPUT:
LOCATION Connected