Wednesday, March 18, 2020

8086 Programs: Array operations Search and Sort

 Array operations such as searching and sorting using 16-bit values is performed using Assembly programming.

Searching of 16-bit value in an array

Aim:

To search for a 16-bit value and provide its count using Assembly language for 8086 microprocessor.

Software Used:

MASM

Program Code:

CODE SEGMENT
        MOV SI, 3000H
        MOV CL, 05H
        MOV BL, 00H
BACK: MOV AX, [SI]
        CMP DX, AX
        JNZ SKIP
        INC BL
SKIP: INC SI
        INC SI
        LOOP BACK
        HLT
CODE ENDS
        END

Sample Input and Output:

Consider the array elements: 1234, ABF0, 1234, 1234, CB07

Input

Address

Data

3000

34

3001

12

3002

F0

3003

AB

3004

34

3005

12

3006

34

3007

12

3008

07

3009

CB

DX: 1234 (Element to be searched)

Result: 

BL: 03. This indicates that the element 1234 is present 3-times in the given array.


Sorting of 16-bit values in ascending/descending order in an array

Aim:
To perform the sorting of 16-bit values in an array using Assembly language for 8086 microprocessor. 

Software Used:
MASM

Program Code:
CODE SEGMENT
        MOV SI, 3000H
        MOV DL, 05H
        MOV CL, 04H
BACK: MOV AX, [SI]
        CMP AX, [SI]+02H
        JC SKIP
        XCHG AX, [SI]+02H
        MOV [SI], AX
SKIP: INC SI
        INC SI
        LOOP BACK
        DEC DL
        MOV SI, 3000H
        MOV CL, 04H
        CMP DL, 00H
        JNZ BACK
        HLT
CODE ENDS
        END

Sample Input and Output:

Consider the array elements: 3567, 1234, CDAB, DEF0, 5678

Input

Address

Data

3000

67

3001

35

3002

34

3003

12

3004

AB

3005

CD

3006

F0

3007

DE

3008

78

3009

56


Output

Address

Data

3000

34

3001

12

3002

67

3003

35

3004

78

3005

56

3006

AB

3007

CD

3008

F0

3009

DE

Result: 

The output table shows the array arranged in ascending order: 1234, 3567, 5678, CDAB, DEF0.

No comments:

Post a Comment