Half ascending and half descending code in 8051

8051 code to arrange the given numbers in half ascending and half descending order.

In this article let’s see how to arrange a given array in half ascending and half descending. I think it’s weird to hear the word half ascending and half descending but it is interesting as well.


1) Store the length of array in r5 and the memory address in r0.
2)Obtaining the half of length and store it in r3,r4,r6 because making r3 as outer counter and r6 as inner counter.
3)Compare the two numbers of an array and if the first number is lesser than second number jump to last label.
4)If the first number is greater than second number then swap the numbers stored in memory location.
5)Decrement inner counter and repeat the above 3rd and 4th step for successive numbers.
6)Decrement outer counter and repeat the above 3rd,4th and 5th steps.
7)For next half of the array repeat the same steps but check the numbers to be in descending order.

Code goes here:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Advertisment ad adsense adlogger