Professional Documents
Culture Documents
Experiment #1
Familiarization with the basic 8051 Kit
Submitted By:
Wednesday Group # 13
07EC1041 Aamod Shanker
07EC1043 Jayant
Objective:
To use assembly language to perform the following actions
1. Find the second largest of an array of 100 numbers stored in external
memory from location 9000H onwards. The number should be stored at
location 9500H.
2. Compute the LCM of two numbers. Assume the numbers to be stored at
location 9000H and 9001H. Store the result at 9002H.
3. Check whether a NULL‐terminated string stored from location 9000H is a
palindrome or not. If the string is a palindrome, store 1 at location 9500H,
else clear the location.
Methodology:
Apparatus and Software:
• ESA51E 8051 Trainer Board
• Compiler – Keil uvision 4
• Driver : Win51E
Using 8051 kit:
The program is written in a standard editor and then the program is built to form a .hex file.
The .hex file can then be transferred onto a 8051 microcontroller. The microcontroller is
connected to the computer through a cable and when the connection is established, the
program is loaded on the microcontroller.
Data input:
To work with user given data, and to verify the functionality of the code, we can use the
software package to view and edit the registers of the microcontroller. Next, by running the
program over the inserted values we can validate the code.
Software Design and Algorithm:
Part 1: Second largest number from the 100 element array.
1. For the first number, read it and store it in R1.
2. Now, input the next number in R3.
3. Copy content of R1 at some random location, say 60h.
4. If R3 = value at 60h, R2 = R3.
5. If R3 > value at 60h, R1 = R3; R2 = value at 60h.
6. If R3 < value at 60h, and R3 > R2; R2 = R3.
7. Loop
8. END
CODE:
MOVX A,@DPTR
MOV R1,A // R1 stores the first/largest number
INC DPTR
MOVX A,@DPTR //read second number in buffer
MOV 60h,R1
CJNE A,60h,NEXT //compare largest with buffer
MOV R2,A //if buffer and largest equal, put buffer in second largest
SJMP LOOP //enter loop
NEXT: JNC SHIFT //if largest smaller than buffer, replace largest with buffer
MOV R2,A //if not then put buffer in second largest
SJMP LOOP //enter loop
MOV 60h,R1
CJNE A,60h,NEXT2 //compare largest with buffer
MOV R2,A //update R2
SJMP LOOP
CODE:
MOV 60H,R1
CJNE A,60H, NEXT1 //compare the two values
SJMP LEAVE // if equal, lcm is the number
Part 3: Check if the given string is a palindrome.
1. Obtain the string length by reading till NULL is obtained, and running a counter
alongside.
2. Start reading character by character.
3. Store 1st character in R1 and corresponding mirror image in A. If same, continue to next
character. If not, exit loop. Go to step 5.
4. If the entire string is scanned (R1=0), then exit loop. Move #1 to 9500h.
5. END
CODE:
ORG 8100H
MOV R1,#0
MOV DPTR , #8FFFh
DEC R1
MOV DPTR,#9000H //Initialize
MOV A,R1
MOVC A,@A+DPTR //Move mirror value to A
MOV 60h,R2
CJNE A,60h,FINISH //Compare
RESULT: MOV DPTR,#9500H // If R1 reduces to zero (with all comparisons satisfied), move 1
to 9500h
MOV A,#1
MOVX @DPTR,A