You are on page 1of 5

Register No.

: 20BCE1563 Name: SHRI VARSHAN P

Date: 28/01/22 Exp.3 Sorting in ascending and descending and finding


. the largest and smallest number in an array

Aim:

To perform the ascending, descending, largest and smallest number from the
given array using 8086 processor by MASM 611 assembler.

Tool Used:

Assembler - MASM 611

Algorithm:

1. Inside the data segment create an array (size N) and end it.

2. Inside the code segment, moving the whole data to AX (accumulator)


register then from AX to the data segment.

3. Store the number of loops (N-1) in CH and CL (count registers).

4. Load the array first index address in SI (source index).

5. Move the first element in array to AL (accumulator) and second element to


BL (base register) using the source index.

6. Then compare the AL and BL

(a) For Ascending:if positive then exchanging the values in it else leave it as
usual and skip to next address of the array by increasing SI and decreasing CL.
And then repeat the steps 5-6. (use JC)

(b) For Descending: if negative then exchanging the values in it else leaveit as
usual and skip to next address of the array by increasing SI and decreasing CL.
And then repeat the steps 5-6. (use JNC)

7. Interrupting the program using INT3.


Register No.: 20BCE1563 Name: SHRI VARSHAN P

8. The largest and smallest number of the array is the first element of the
descending and ascending array respectively.

9. Then run the code after assembling it.

Program:

Ascending and smallest:

Descending and largest:


Register No.: 20BCE1563 Name: SHRI VARSHAN P

Procedure:

1) Mount c c:\MASM611
2) c:
3) cd bin
4) edit filename.asm
5) masm filename.asm
6) link filename.obj
7) debug filename.exe
8) -u
-r
-g
-d DS: 0000 0004 //sorted array
-d DS: 0000 //smallest (or) largest number
-q

These are the commands used during Lab Class while executing the ALP in DOS
prompt

Sample Input:

Ascending and smallest: 59, 50, 65, 98, 48

Descending and largest: 59, 50, 65, 98, 48

Sample Output:

Ascending and smallest: 48, 50, 59, 65, 98

48

Descending and largest: 98, 65, 59, 50, 48


Register No.: 20BCE1563 Name: SHRI VARSHAN P

98

Register/ Memory Contents for I/O:

Ascending and smallest: AX=FFFF, BX=0000 & DS=0754 and AX=0765, BX=0098
& DS=0764 after operation

Descending and largest: AX=FFFF, BX=0000 & DS=0754 and AX=0750, BX=0048
& DS=0764 after operation

Snapshot of the Output:

Ascending and smallest:


Register No.: 20BCE1563 Name: SHRI VARSHAN P

Descending and largest:

Result:

Hence, sorting in ascending and descending and finding the smallest and
largest element in an array are verified using the MASM application using
DOSBOX.

You might also like