0% found this document useful (0 votes)
6 views3 pages

8085 Assembly Code for Sorting Arrays

The document describes an algorithm to arrange numbers in ascending order using an 8085 microprocessor by initializing counters and memory pointers, getting and comparing numbers from memory, interchanging numbers if out of order, and decrementing counters and repeating the process until complete. It also provides a similar algorithm to arrange numbers in descending order by initializing flags and counters, comparing and interchanging numbers if in the wrong order, decrementing counters and repeating the loop.

Uploaded by

explore_harsh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

8085 Assembly Code for Sorting Arrays

The document describes an algorithm to arrange numbers in ascending order using an 8085 microprocessor by initializing counters and memory pointers, getting and comparing numbers from memory, interchanging numbers if out of order, and decrementing counters and repeating the process until complete. It also provides a similar algorithm to arrange numbers in descending order by initializing flags and counters, comparing and interchanging numbers if in the wrong order, decrementing counters and repeating the loop.

Uploaded by

explore_harsh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Arrange in ascending order

MVI B, 09 : Initialize counter       

START : LXI H, 2200H: Initialize memory pointer

MVI C, 09H  : Initialize counter 2

BACK: MOV A, M : Get the number

INX H : Increment memory pointer

CMP M : Compare number with next number

JC SKIP : If less, don't interchange

JZ SKIP  : If equal, don't interchange

MOV D, M

MOV M, A

DCX H

MOV M, D

INX H : Interchange two numbers

SKIP:DCR C  : Decrement counter 2

JNZ BACK  : If not zero, repeat

DCR B : Decrement counter 1

JNZ START

HLT : Terminate program execution


Arrange in DESCENDING Order (8085)

START:MVI B, 00 ; Flag = 0
LXI H, 4150 ; Count = length of array
MOV C, M 
DCR C ; No. of pair = count -1
INX H ; Point to start of array
LOOP:MOV A, M ; Get kth element
INX H 
CMP M ; Compare to (K+1) th element
JNC LOOP 1 ; No interchange if kth >= (k+1) th
MOV D, M ; Interchange if out of order
MOV M, A ;
DCR H 
MOV M, D 
INX H 
MVI B, 01H ; Flag=1
LOOP 1:DCR C ; count down
JNZ LOOP ;
DCR B ; is flag = 1?
JZ START ; do another sort, if yes
HLT ; If flag = 0, step execution

You might also like