Program for sorting an array for 8086
1.Ascending order
Aim:
To write an assembly language program to arrange the given numbers in ascending order.
Tools:
PC installed with TASM.
Program:
ASSUME CS : CODE, DS : DATA CODE SEGMENT MOV AX, DATA MOV DS, AX MOV DX, COUNT - 1 BACK : MOV CX, DX MOV SI,OFFSET LIST AGAIN : MOV AX, [SI] CMP AX, [SI + 2] JC GO XCHG AX, [SI + 2] XCHG AX, [SI] GO:INC SI INC SI LOOP AGAIN DEC DX JNZ BACK HLT CODE ENDS DATA SEGMENT LIST DW 05H, 04H, 01H, 03H, 02H COUNT EQU 05H DATA ENDS END
Flow Chart
Result:
Input:
LIST (DS : 0000H) = 05H, 04H, 01H, 03H, 02H
Output:
LIST (DS : 0000H) = 01H, 02H, 03H, 04H, 05H
2. Descending order
Aim:
To write an assembly language program to arrange the given numbers in descending order.
Tools:
PC installed with TASM.
Program:
ASSUME CS : CODE, DS : DATA CODE SEGMENT MOV AX, DATA MOV DS, AX MOV DX, COUNT - 1 BACK : MOV CX, DX MOV SI, OFFSET LIST AGAIN : MOV AX, [SI] CMP AX, [SI + 2] JNC GO XCHG AX, [SI + 2] XCHG AX, [SI] GO:INC SI INC SI LOOP AGAIN DEC DX JNZ BACK HLT CODE ENDS DATA SEGMENT LIST DW 03H, 04H, 01H, 05H, 02H COUNT EQU 05H DATA ENDS END
Flow Chart:
Result:
Input:
LIST (DS : 0000H) = 03H, 04H, 01H, 05H, 02H
Output:
LIST (DS : 0000H) = 05H, 04H, 03H, 02H, 01H
-
UpdatedNov 05, 2014
-
Views44,758
You May Like
Programs for 16 bit arithmetic operations for 8086 (using various addressing modes)
Program for String manipulations for 8086
Program for sorting an array for 8086
Program for searching for a number or character in a string for 8086
Program for digital clock design using 8086.
Programming using arithmetic, logical and bit manipulation instructions of 8051