Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Algorithm MP

The document outlines various programming steps for operations such as 3.8-bit division, searching and sorting arrays, and converting between different data formats like BCD and ASCII. It includes detailed steps for finding the largest and smallest elements in arrays, reversing arrays, and performing arithmetic operations using a microcontroller. Additionally, it describes interfacing experiments and LED control using the 8051 microcontroller.

Uploaded by

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

Algorithm MP

The document outlines various programming steps for operations such as 3.8-bit division, searching and sorting arrays, and converting between different data formats like BCD and ASCII. It includes detailed steps for finding the largest and smallest elements in arrays, reversing arrays, and performing arithmetic operations using a microcontroller. Additionally, it describes interfacing experiments and LED control using the 8051 microcontroller.

Uploaded by

sudhasanmathi266
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

3.

8-BIT DIVISION

STEP 1: Start the Program.


STEP 2: Set up initial references and counter.
STEP 3: Loop through values starting from memory 4151.
STEP 4: Compare each value against the first value.
STEP 5: Count how many values are greater than or equal.
STEP 6: Store the last processed value and the count in memory.
STEP 7: Stop the Program.

III-SORTING AND SEARCHING

1 SEARCHING FOR AN ELEMENT IN AN GIVEN ARRAY

STEP 1: Start the Program.


STEP 2: Set the initial pointer to the reference value.
STEP 3: Load the reference value for comparison.
STEP 4: Set up the pointer for the values to compare.
STEP 5: Initialize the loop counter.
STEP 6: Loop through the values:
 Load the current value.
 Compare it with the reference.
 If a match is found, jump to store the result.
 If not, continue to the next value and decrement the counter.
STEP 7: If no matches are found after the loop, store 00.
STEP 8: If a match is found, store 01.
STEP 9: Stop the Program.

2.a) SORTING IN ASCENDING ORDER

STEP 1: Start the Program.


STEP 2: Set up counters for outer and inner loops.
STEP 3: Iterate through a block of data at memory address 8100 for a total of 4 iterations.
STEP 4: In each inner loop:
 Compare the current value with the next value.
 If the current value is greater, swap it with the next value.
STEP 5: Repeat the process until all outer loop iterations are complete.
STEP 6: Stop the program.

3.a) LARGEST ELEMENT IN AN ARRAY

STEP 1: Start the Program.


STEP 2: Set up the initial pointer to the data at address 8100.
STEP 3: Load the first value from memory into register A.
STEP 4: Set a loop counter (B) to iterate 4 times.
STEP 5: In each iteration:
 Increment the address in HL to access the next value.
 Compare the current value with the value in A.
 If the current value is less, update A with this new value.
STEP 6: Decrement the loop counter after each comparison.
STEP 7: Store the final value in A into memory at address 8105.
STEP 8: Stop the program.

3.a) SMALLEST ELEMENT IN AN ARRAY

STEP 1: Setup: Initialize memory address and loop counter.


STEP 2: Load First Value: Get the initial value from memory.
STEP 3: Loop:
For each of the 4 values:
o Move to the next memory location.
o Compare the current value with the value in A.
o If the current value is less, update A.
STEP 4: Decrement the counter and repeat until all values are checked.
STEP 5: Store the minimum value found into memory address 8105.
STEP 6: Stop the program.

REVERSING ARRAY ELMENT


STEP 1: Start the Program.
STEP 2: Setup: Initialize registers and memory addresses.
STEP 3: Load Initial Values: Load the first value into C and prepare the destination in D.
STEP 4: Loop through Values:
STEP 5:For each value:
o Decrement HL to access the current value.
o Copy the current value to B.
o Increment HL to access the next value.
o Store the value from B back to the current memory address.
o Store the processed value into the memory location pointed to by D.
o Update the pointers and counters accordingly.
STEP 6: Repeat until all values have been processed.
STEP 7: Terminate the program.

4. BLOCK MOVE

STEP 1: Start the Program.


STEP 2:Setup: Initialize the registers and set the loop counter to 5.
STEP 3: Loop Through Values:
For each of the 5 values:
o Load the value from the source address into register A.
o Store that value into the destination address.
o Increment both the source (HL) and destination (DE) addresses.
o Decrement the loop counter.
STEP 4: Repeat until all values have been moved.
STEP 5: Stop the Program.
IVCODECONVERSION

1.a)BCD TO HEX

STEP 1: Start the Program.


STEP 2: Setup: Initialize the pointer to memory address 5000.
STEP 3: Load Value: Get the value from 5000 into register A.
STEP 4: Calculate:
1.Double the value and store it in B.
2.Update A to be four times the original value.
STEP 5: Add Another Value:
1.Read the next value from 5001, and add it to A.
STEP 6: Store the Final Result: Place the resulting value into 5002.
STEP 7: Stop the program.

1.b)HEX TO BCD

STEP 1: Start the Program.


STEP 2: Setup: Initialize the memory pointer and registers.
STEP 3: Load Initial Value: Get the value from memory at 5000H into register C.
STEP 4: First Loop:
1.Continuously add 01H to A and adjust it for valid BCD until a carry occurs.
2.Each carry increments D, which counts how many times A reached the limit.
STEP 5: Second Loop:
1.Decrement C, ensuring the loop continues for the number of initial values loaded.
STEP 6: Store Results: Save the adjusted value back to 5000H and potentially
store another value (from B) into 5003H.
STEP 7: Stop the program.

BINARY TO ASCII

STEP 1: Start the Program.


STEP 2: Setup: Initialize the pointer to memory address 5000H.
STEP 3:Load Value: Get the value from 5000H into register A.
STEP 4: Check and Convert:
1.If the value is less than 10, convert it to its ASCII equivalent ('0' to '9').
2.If the value is 10 or more, convert it to ASCII ('A' and above).
STEP 5: Store the Result: Save the converted ASCII value into the next memory
address (5001H).
STEP 6: Stop the program.

2.a) ASCII TO BINARY

STEP 1: Start the Program.


STEP 2: Setup: Initialize the pointer to memory address 8030H.
STEP 3: Load Value: Get the value from 8030H into register A.
STEP 4: Convert ASCII to Numerical:
1.Subtract 30H to convert an ASCII character (e.g., '0'-'9') into its numerical equivalent.
STEP 5: Check Range:
1.If the value is less than 10, jump to the label.
2.If it is 10 or greater, further adjust the value by subtracting 07H.
STEP 6: Store the Result: Save the adjusted value into 8031H.
STEP 7: Stop the program.

3.a) ASCII TO BCD

STEP 1: Start the Program.


STEP 2: Setup: Initialize the HL register to point to the memory address 8030H.
STEP 3: Load Value: Read the value from 8030H into register A.
STEP 4: Convert ASCII to Numerical: Subtract 30H from A to convert the ASCII
value of a digit into its corresponding numerical value.
STEP 5: Store the Result: Write the numerical value to the memory address 8031H.
STEP 6: Stop the program.

3.a) BCD TO ASCII

STEP 1: Start the Program.


STEP 2: Read data from memory location M into accumulator A.
STEP 3: Add 30H to the value in A.
STEP 4: Store the result from A into memory location 8031H.
STEP 5: Stop the program.
MICROCONTROLLER 8051
PROGRAMS
SIMPLE PROGRAMS IN MICRO CONTROLLER

1. Addition 2.Subtraction 3.Multiplication 4.Division

STEP 1: Start the Program.


STEP 2: Addition
 Load the accumulator (A) with the value 2.
 Add 3 to the value in A.
 Store the result in register R0.
 Clear the accumulator (A) and the carry flag (C).
STEP 3: Subtraction
 Load A with 5.
 Subtract 2 from A.
 Store the result in register R1.
STEP 4: Multiplication
 Load A with 3.
 Load register B with 4.
 Multiply A and B.
 Store the product in register R2 and the multiplier in register R3.
 Clear A.
STEP 5: Division
 Load A with 95.
 Load B with 10.
 Divide A by B.
 Store the quotient in register R4 and the remainder in register R5.
STEP 6: Stop the Program.
INTERFACING EXPERIMENTS USING 8051

1. REALISATION AND BOOLEAN EXPRESION


STEP 1: Start the Program.
STEP 2: Initialize Values
 Load accumulator (A) with 45H.
 Load register (R0) with 67H.
STEP 3: Bitwise AND Operation
 Perform a bitwise AND between A (45H) and R0 (67H).
 Store the result in memory address 20H.
STEP 4:Bitwise OR Operation (First Instance)
 Load A with 45H.
 Perform a bitwise OR between A (45H) and R0 (67H).
 Store the result in memory address 21H.
STEP 5: Bitwise OR Operation (Second Instance)
 Load A with 45H again.
 Perform another bitwise OR between A (45H) and R0 (67H).
 Store the result again in memory address 21H (overwrites the previous value).
STEP 6: Bitwise XOR Operation
 Load A with 45H.
 Perform a bitwise XOR between A (45H) and R0 (67H).
 Store the result in memory address 22H.
STEP 7: Bitwise Complement
 Load A with 45H.
 Complement (invert) the value in A.
 Store the complemented result in memory address 23H.
STEP 8: Stop the Program.
3..LED PORTS

 Initialize Port 1 (P1)

 Set all bits of Port 1 (P1.0 to P1.7) to output mode.


 Initialize P1 to 00H, turning all LEDs off.

 Main Loop

 Enter the MAIN label:


o Toggle LEDs: Complement (invert) the bits of P1, which toggles the state of the
connected LEDs.
o Delay: Call the DELAY_SHORT subroutine to create a visible delay so that the LED
blinking can be seen.
o Repeat: Jump back to MAIN to continue toggling the LEDs.

 Delay Subroutine

 Set R2 to 20 for the outer loop counter.


 Enter the OUTER_LOOP:
o Set R1 to 30 for the inner loop counter.
o Enter the INNER_LOOP:
 Decrement R1. If R1 is not zero, jump back to INNER_LOOP.
o After finishing the inner loop, decrement R2. If R2 is not zero, jump back to
OUTER_LOOP.
 After both loops complete, return from the subroutine.

You might also like