Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Register No.

: 20BRS1176 Name: George Mathew

Date: 27-01-2022 Exp.3 Sorting Array of 15 Numbers

Aim:

To sort an array in ascending and descending order and find the max and min elements of
that array

Tool Used:

Assembler - MASM 611

Algorithm:

• Create the original array as ARRAY1

• Use the digits of your Aadhar Number and split it into groups of two, for the first 6 hex
numbers

• Reverse these digits for the next 6 hex numbers

• Use the digits of your reg no and split it to get the next 3 hex numbers

• Create two arrays one for ascending and the other for descending with the same elements
of ARRAY1

• Sort the Asc Array in Ascending order and print the first index of the array for the
minimum element

• Sort the Desc Array in Descending order and print the first index of the array for the
maximum element

Sample Input:

73H,94H,92H,73H,92H,65H,37H,49H,29H,37H,29H,56H,20H,11H,76H

Sample Output:

a. Ascending:

11,20,29,29,37,37,49,56,65,73,73,76 92,92,94

b. Descending:

94,92,92,76,73,73,65,56,49,37,37,29,29,20,11

c. Max Element:

94

d. Min Element:

11
Register No.: 20BRS1176 Name: George Mathew

Program:

ASSUME CS:CODE, DS:DATA


DATA SEGMENT
ARRAY DB 73H,94H,92H,73H,92H,65H,37H,49H,29H,37H,29H,56H,20H,11H,76H
ASC DB 73H,94H,92H,73H,92H,65H,37H,49H,29H,37H,29H,56H,20H,11H,76H
DESC DB 73H,94H,92H,73H,92H,65H,37H,49H,29H,37H,29H,56H,20H,11H,76H
DATA ENDS
CODE SEGMENT
START:
MOV AX, DATA
MOV DS, AX
XOR AX,AX
MOV CH,0EH
UP2:
MOV CL,0EH
LEA SI,ASC
UP1:
MOV AL,[SI]
MOV BL,[SI+1]
CMP AL,BL
JC DOWN
MOV DL,[SI+1]
XCHG [SI],DL
MOV [SI+1],DL

DOWN:
INC SI
DEC CL
JNZ UP1
DEC CH
JNZ UP2

MOV CH,0EH

UP4:
MOV CL,0EH
LEA SI,DESC
UP3:
MOV AL,[SI]
MOV BL,[SI+1]
CMP AL,BL
JNC DOW
MOV DL,[SI+1]
XCHG [SI],DL
MOV [SI+1],DL

DOW:
INC SI
Register No.: 20BRS1176 Name: George Mathew

DEC CL
JNZ UP3
DEC CH
JNZ UP4

HLT

CODE ENDS
END START

Register/ Memory Contents for I/O:

Snapshot of the Output:

Arrays:

Minimum Element:

Maximum Element:

Result:

Thus the following outputs and the answers are verified for the given inputs of the array.

You might also like