0% found this document useful (0 votes)
7 views2 pages

Algorithm

The document outlines an algorithm for sorting a list using a bubble sort method. It describes the initialization of data segments, the structure of outer and inner loops for comparing and swapping elements, and the termination of the program. The process continues until the entire list is sorted, followed by a program exit command.

Uploaded by

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

Algorithm

The document outlines an algorithm for sorting a list using a bubble sort method. It describes the initialization of data segments, the structure of outer and inner loops for comparing and swapping elements, and the termination of the program. The process continues until the entire list is sorted, followed by a program exit command.

Uploaded by

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

Algorithm

Initialize Data Segment:

Load data segment into AX and then move AX to DS.


Set Sorting Loop Counter:

Load Count - 1 into DL (outer loop counter).


Outer Loop (Up2):

Set CL = DL (inner loop counter).


Load the starting address of list into SI.
Inner Loop (Up1):

Load the value at SI into AL.


Compare AL with the next element at SI + 1.
If AL is greater than the next element, swap them using XCHG.
Increment SI (to move to the next pair) and decrement CL.
Repeat until all pairs in this pass are sorted.
Decrease Outer Loop Counter (DL):

Decrement DL and repeat the outer loop until fully sorted.


Exit Program:

Load 4Ch into AH to terminate the program and call interrupt 21h.
+---------------------------+
| Start |
+---------------------------+
|
|
v
+---------------------------+
| Initialize Data Segment |
| AX = Data, DS = AX |
+---------------------------+
|
|
v
+---------------------------+
| Set DL = Count - 1 |
+---------------------------+
|
|
v
+---------------------------+
| Outer Loop Start (Up2) |
| CL = DL |
+---------------------------+
|
|
v
+---------------------------+
| Set SI = list |
+---------------------------+
|
|
v
+---------------------------+
| Inner Loop Start (Up1) |
| Load AL = [SI] |
+---------------------------+
|
|
v
+---------------------------+
| Compare AL and [SI+1] |
+---------------------------+
|
+------+------+
| |
| AL <= [SI+1]| AL > [SI+1]
| |
v v
+------------------+ +------------------+
| Increment SI | | Swap AL and |
| Decrement CL | | (SI+1) and AL |
+------------------+ +------------------+
| |
+------+------+
|
v
+---------------------------+
| Inner Loop End (Up1) |
| If CL != 0, Repeat Up1 |
+---------------------------+
|
|
v
+---------------------------+
| Outer Loop End (Up2) |
| Decrement DL |
| If DL != 0, Repeat Up2 |
+---------------------------+
|
|
v
+---------------------------+
| Program Exit |
+---------------------------+

You might also like