8051 Program
8051 Program
AIM: To write an ALP to fill the data in the specified locations of Internal memory.
ALGORITHM:
1. Initialize R0 with the source address
2. Initialize R1 with the counter
3. The data to be filled is loaded in the accumulator.
4. Move the data from the accumulator to the destination location.
5. Decrement the counter and repeat step4 till R1 is zero
6. Stop
PROGRAM:
ADDRESS MNEMONICS COMMENTS
0000 MOV R0,#50H Load the destination address in R0
0002 MOV R1,#0AH Load the count of data in R1
0004 MOV A,#22H Load the data to be loaded in the destination location
0006 L1: MOV @R0,A Move the accumulator contents to the destination location
0007 INC R0 Increment R0
0008 DJNZ R1,L1 Decrement R1 and jump to L1 if contents of R1 is not zero
000A L2: SJMP L2 Stop
OBSERVATION :
INPUT OUTPUT
50 50
51 51
52 52
53 53
54 54
55 55
56 56
57 57
58 58
59 59
RESULT: Thus an ALP to fill the given data in the specified location of internal memory is
performed.
4.B DATA TRANSFER BETWEEN INTERNAL MEMORIES
AIM : To write an ALP to transfer data from one location of Internal memory to the other.
ALGORITHM:
1. Initialize R0 with the source address.
2. Initialize R1 with the destination address.
3. Initialize R3 with the counter.
4. Move the data from source to the accumulator and then to the destination.
5. Decrement the counter and repeat step4 till R3 is zero.
6. Stop
PROGRAM:
ADDRESS MNEMONICS COMMENTS
0000 MOV R0,#30H Load the source address 30 to R0
0002 MOV R1,#50H Load the destination address 50 to R1
0004 MOV R3,#0AH Load count(0AH) of data in R3
0006 L1: MOV Move the first number from the source location to the accumulator
0007 MOV @R1,A
A,@R0 Move the first number from the accumulator to the destination location.
0008 INC R0 Increment R0. Go to the next source address location
0009 INC R1 Increment R1.Go to the next destination address location
000A DJNZ R3,L1 Decrement R3 and jump to L1 if contents of R3 is not zero
000C L2: SJMP L2 stop
OBSERVATION :
INPUT OUTPUT
30 50
31 51
32 52
33 53
34 54
35 55
36 56
37 57
38 58
39 59
RESULT: Thus an ALP to transfer data from one location of internal memory to the other is
performed.
5. LOGICAL OPERATION USING 8051
AIM: To write an ALP to perform the logical AND operation to separate the Lower Nibble.
ALGORITHM:
1. Initialize the registers R0, R1.
2. Move the number of data in register R2.
3. Move the content from R0 to Accumulator and perform logical AND with 0Fh.
4. Move the result to R1 register.
5. Increment R0 and R1 for the next data.
6. Decrement the counter (R2) , if R2 ≠0,then repeat from step3.
7. Stop the program.
PROGRAM:
ADDRESS MNEMONICS COMMENTS
0000 MOV R0,#50H Move 50h to R0
0002 MOV R1,#60H Move 60h to R1
0004 MOV R2,#04H Move 04h(count) to R1
0006 L1: MOV A,@R0 Move the content of R0 to accumulator
0007 ANL A,#0FH Perform AND operation Between Accumulator and 0Fh
0009 MOV @R1,A Move the accumulator content to location of R1
000A INC R0 Increment R0
000B INC R1 Increment R1
000C DJNZ R2,L1 Decrement the value of R2 and jump to loop L1 if R2≠0
000E L2: SJMP L2 Stop the Program
OBSERVATION:
Input Output
Address Data Address Data
50 60
51 61
52 62
53 63
RESULT: Thus the ALP to perform Logical AND instruction to separate the Lower Nibble was
executed and the output is verified.
5. B SEPERATING THE UPPER NIBBLE
AIM: To write an ALP to perform the logical AND operation to separate the Upper Nibble.
ALGORITHM:
1. Initialize the registers R0, R1.
2. Move the number of data in register R2.
3. Move the content from R0 to Accumulator and perform logical AND with F0h.
4. Swap the Upper and lower nibble of Accumulator.
5. Move the result to R1 register.
6. Increment R0 and R1 for the next data.
7. Decrement the counter (R2) ,if R2 ≠0,then repeat from step3.
8. Stop the program.
PROGRAM:
ADDRESS MNEMONICS COMMENTS
0000 MOV R0,#50H Move 50h to R0
0002 MOV R1,#60H Move 60h to R1
0004 MOV R2,#04H Move 04h(count) to R1
0006 L1: MOV A,@R0 Move the content of R0 to accumulator
0007 ANL A,#0F0H Perform AND operation Between Accumulator and F0h
0009 SWAP A Swap the accumulator content
000A MOV @R1,A Move the accumulator content to location of R1
000B INC R0 Increment R0
000C INC R1 Increment R1
000D DJNZ R2,L1 Decrement the value of R2 and jump to loop L1 if R2≠0
000F L2: SJMP L2 Stop the Program
OBSERVATION:
Input Output
Address Data Address Data
50 60
51 61
52 62
53 63
RESULT: Thus the ALP to perform Logical AND instruction to separate the Upper Nibble was
executed and the output is verified.
5.C BIT MANIPULATION
AIM:To write an ALP to identify if the given hexadecimal number is odd or even.
ALGORITHM:
1. Initialize R0 with the source address
2. Move the contents of R0 to the accumulator
3. Rotate accumulator right through carry.
4. If the carry=1, the given number is odd, load the answer ”OD” in address location 51
5. Else if the carry=0, the given number is even, load the answer ”OE” in address location 51
6. Stop
PROGRAM:
OBSERVATION :
INPUT OUTPUT
50 51
50 51
RESULT: Thus an ALP to identify if the given hexa decimal number is odd or even is performed.
5.D BINARY TO GRAY CODE CONVERSION
AIM:To write an ALP to convert the given binary code to gray code number.
ALGORITHM:
1.Initialize R0 with the source addresss
2. Initialize R1 with the destination addresss
3. Move the data from source to the accumulator.
4. Clear the carry bit to zero and Rotate accumulator right through carry.
5. XOR the contents of accumulator and the contents of R0
6. Store the answer in R1
7. Stop
PROGRAM:
ADDRESS MNEMONICS COMMENTS
0000 MOV R0,#50H Load the source address to R0
0002 MOV R1,#60H Load the destination address to R1
0004 MOV A,@R0 Move the binary number into the accumulator
0005 SETB C Set carry bit=1
0006 CPL C Compliment carry bit
0007 RRC A Rotate accumulator right through carry
0008 XRL A,@R0 XOR the contents of accumulator and R0
0009 MOV @R1,A Move the result from accumulator to destination address
000A L1: SJMP L1 Stop
OBSERVATION :
INPUT OUTPUT
50 60
RESULT: Thus an ALP to convert the given binary code to gray code number is performed.
6. BOOLEAN FUNCTION USING 8051
ALGORITHM:
1. Initialize the Register R0
2. Move the content of R0 to Accumulator ( Represents A)
3. Inctement the position of R0 and Perform AND operation Between the contents of
Accumulator and R0 ( A AND B).
4. Move the content of Accumulator to R1 register.
5. Increment the position of R0 and move the content to Accumulator.
6. Obtain the complement of Acc ( C’).
7. Perform OR operation Between the content of Acc and R1 register.
8. Store the result.
9. Stop the Program.
PROGRAM:
ADDRESS MNEMONICS COMMENTS
0000 MOV Move 50h to R0
0002 MOV A,@R0
R0,#50H Move the content of R0 to accumulator
0003 INC R0 Increment R0
0004 ANL A,@R0 Perform AND operation Between the content of Accumulator and R0
0005 MOV R1,A Move the accumulator content to the register R1
0006 INC R0 Increment R0
0007 MOV A,@R0 Move the content of R0 to accumulator
0008 CPL A Complement Accumulator
0009 ORL A,R1 Accumulator ORed with R1
000A MOV 60H,A Move the accumulator content to the location 60h
000C L1: SJMP L1 Stop the Program
OBSERVATION:
Input Output
Address Data Address Data
50 60
51
52
RESULT: Thus an ALP to perform the given Boolean expression AB+C’ was executed and the
result is verified.